libutil++  1.9.3
 All Classes Functions Variables
SimpleLogFormat.cpp
1 /*
2 ** libutil++
3 ** $Id: SimpleLogFormat.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: SimpleLogFormat.cpp 1653 2016-02-28 19:54:59Z sella $";
10 
11 #include "SimpleLogFormat.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 SimpleLogFormat* SimpleLogFormat::clone(void) const throw () {
26  return new SimpleLogFormat(*this);
27 }
28 
29 const std::string SimpleLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const sella::Exception &e, const char *message) throw () {
30  char buffer[BUFFER_SIZE];
31 
32  if (message == NULL || message[0] == '\0') {
33  snprintf(buffer, sizeof(buffer), "%s [%s:%d %s]", e.what(), e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
34  } else {
35  snprintf(buffer, sizeof(buffer), "%s - %s [%s:%d %s]", message, e.what(), e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
36  }
37 
38  return std::string(buffer);
39 }
40 
41 const std::string SimpleLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const char *message) throw () {
42  char buffer[BUFFER_SIZE];
43 
44  snprintf(buffer, sizeof(buffer), "%s", message);
45 
46  return std::string(buffer);
47 }
48 
49 const std::string SimpleLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const char *option, const char *message) throw () {
50  char buffer[BUFFER_SIZE];
51 
52  snprintf(buffer, sizeof(buffer), "%s {%s}", message, option);
53 
54  return std::string(buffer);
55 }
56 
57 /*
58 ** vim: noet ts=3 sw=3
59 */