00001
00002
00003
00004
00005
00006
00007
00008
00009 static const char rcsid[] __attribute__((used)) = "$Id: SimpleLogFormat.cpp 1230 2014-11-16 02:32:01Z sella $";
00010
00011 #include "SimpleLogFormat.h"
00012 #include "Log.h"
00013 #include "../Exception.h"
00014
00015 #include <sys/time.h>
00016 #include <string.h>
00017 #include <stdio.h>
00018
00019 #include <string>
00020
00021 #define BUFFER_SIZE (64 * 1024)
00022
00023 using namespace sella::util;
00024
00025 SimpleLogFormat* SimpleLogFormat::clone(void) const throw () {
00026 return new SimpleLogFormat(*this);
00027 }
00028
00029 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 () {
00030 char buffer[BUFFER_SIZE];
00031
00032 if (message == NULL || message[0] == '\0') {
00033 snprintf(buffer, sizeof(buffer), "%s [%s:%d %s]", e.what(), e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
00034 } else {
00035 snprintf(buffer, sizeof(buffer), "%s - %s [%s:%d %s]", message, e.what(), e.getFile().c_str(), e.getLine(), e.getFunction().c_str());
00036 }
00037
00038 return std::string(buffer);
00039 }
00040
00041 const std::string SimpleLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const char *message) throw () {
00042 char buffer[BUFFER_SIZE];
00043
00044 snprintf(buffer, sizeof(buffer), "%s", message);
00045
00046 return std::string(buffer);
00047 }
00048
00049 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 () {
00050 char buffer[BUFFER_SIZE];
00051
00052 snprintf(buffer, sizeof(buffer), "%s {%s}", message, option);
00053
00054 return std::string(buffer);
00055 }
00056
00057
00058
00059