libutil++  1.9.3
 All Classes Functions Variables
VerboseLogFormat.cpp
1 /*
2 ** libutil++
3 ** $Id: VerboseLogFormat.cpp 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 static const char rcsid[] __attribute__((used)) = "$Id: VerboseLogFormat.cpp 1653 2016-02-28 19:54:59Z sella $";
10 
11 #include "VerboseLogFormat.h"
12 #include "Log.h"
13 #include "../Exception.h"
14 
15 #include <sys/time.h>
16 #include <string.h>
17 #include <stdio.h>
18 
19 #include <string>
20 
21 #define BUFFER_SIZE (64 * 1024)
22 
23 using namespace sella::util;
24 
25 VerboseLogFormat::VerboseLogFormat(const std::string &stamp, bool micro) throw () : LogFormat(stamp, micro) { }
26 
27 VerboseLogFormat* VerboseLogFormat::clone(void) const throw () {
28  return new VerboseLogFormat(*this);
29 }
30 
31 const std::string VerboseLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const sella::Exception &e, const char *message) throw () {
32  char buffer[BUFFER_SIZE];
33 
34  if (message == NULL || message[0] == '\0') {
35  snprintf(buffer, sizeof(buffer), "%s <%s> %s [%s:%d %s] <- [%s:%d %s]", stamp, Log::priority(priority), e.what(), file, line, func, e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
36  } else {
37  snprintf(buffer, sizeof(buffer), "%s <%s> %s - %s [%s:%d %s] <- [%s:%d %s]", stamp, Log::priority(priority), message, e.what(), file, line, func, e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
38  }
39 
40  return std::string(buffer);
41 }
42 
43 const std::string VerboseLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const char *message) throw () {
44  char buffer[BUFFER_SIZE];
45 
46  snprintf(buffer, sizeof(buffer), "%s <%s> %s [%s:%d %s]", stamp, Log::priority(priority), message, file, line, func);
47 
48  return std::string(buffer);
49 }
50 
51 const std::string VerboseLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const char *option, const char *message) throw () {
52  char buffer[BUFFER_SIZE];
53 
54  snprintf(buffer, sizeof(buffer), "%s <%s> %s [%s:%d %s] {%s}", stamp, Log::priority(priority), message, file, line, func, option);
55 
56  return std::string(buffer);
57 }
58 
59 /*
60 ** vim: noet ts=3 sw=3
61 */