00001
00002
00003
00004
00005
00006
00007
00008
00009 static const char rcsid[] __attribute__((used)) = "$Id: VerboseLogFormat.cpp 1230 2014-11-16 02:32:01Z sella $";
00010
00011 #include "VerboseLogFormat.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 VerboseLogFormat::VerboseLogFormat(const std::string &stamp, bool micro) throw () : LogFormat(stamp, micro) { }
00026
00027 VerboseLogFormat* VerboseLogFormat::clone(void) const throw () {
00028 return new VerboseLogFormat(*this);
00029 }
00030
00031 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 () {
00032 char buffer[BUFFER_SIZE];
00033
00034 if (message == NULL || message[0] == '\0') {
00035 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());
00036 } else {
00037 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());
00038 }
00039
00040 return std::string(buffer);
00041 }
00042
00043 const std::string VerboseLogFormat::format(int priority, const char *stamp, const char *func, const char *file, int line, const char *message) throw () {
00044 char buffer[BUFFER_SIZE];
00045
00046 snprintf(buffer, sizeof(buffer), "%s <%s> %s [%s:%d %s]", stamp, Log::priority(priority), message, file, line, func);
00047
00048 return std::string(buffer);
00049 }
00050
00051 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 () {
00052 char buffer[BUFFER_SIZE];
00053
00054 snprintf(buffer, sizeof(buffer), "%s <%s> %s [%s:%d %s] {%s}", stamp, Log::priority(priority), message, file, line, func, option);
00055
00056 return std::string(buffer);
00057 }
00058
00059
00060
00061