9 static const char rcsid[] __attribute__((used)) =
"$Id: MixedLogFormat.cpp 1653 2016-02-28 19:54:59Z sella $";
11 #include "MixedLogFormat.h"
13 #include "../Exception.h"
21 #define BUFFER_SIZE (64 * 1024)
23 using namespace sella::util;
25 MixedLogFormat::MixedLogFormat(
int threshold)
throw () : threshold(threshold) { }
31 const std::string MixedLogFormat::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];
34 if (priority >= threshold) {
35 if (message == NULL || message[0] ==
'\0') {
36 snprintf(buffer,
sizeof(buffer),
"%s [%s:%d %s]", e.what(), e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
38 snprintf(buffer,
sizeof(buffer),
"%s - %s [%s:%d %s]", message, e.what(), e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
41 if (message == NULL || message[0] ==
'\0') {
42 snprintf(buffer,
sizeof(buffer),
"%s [%s:%d %s] <- [%s:%d %s]", e.what(), file, line, func, e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
44 snprintf(buffer,
sizeof(buffer),
"%s - %s [%s:%d %s] <- [%s:%d %s]", message, e.what(), file, line, func, e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
48 return std::string(buffer);
51 const std::string MixedLogFormat::format(
int priority,
const char *stamp,
const char *func,
const char *file,
int line,
const char *message)
throw () {
52 char buffer[BUFFER_SIZE];
54 if (priority >= threshold) {
55 snprintf(buffer,
sizeof(buffer),
"%s", message);
57 snprintf(buffer,
sizeof(buffer),
"%s [%s:%d %s]", message, file, line, func);
60 return std::string(buffer);
63 const std::string MixedLogFormat::format(
int priority,
const char *stamp,
const char *func,
const char *file,
int line,
const char *option,
const char *message)
throw () {
64 char buffer[BUFFER_SIZE];
66 if (priority >= threshold) {
67 snprintf(buffer,
sizeof(buffer),
"%s {%s}", message, option);
69 snprintf(buffer,
sizeof(buffer),
"%s [%s:%d %s] {%s}", message, file, line, func, option);
73 return std::string(buffer);