Files
WrenchBoradWeb/wrenchboard/src/core/clog.cc
T
2022-11-13 00:16:43 -05:00

90 lines
2.4 KiB
C++

#include "clog.h"
#include "php_wrenchboard_log.h"
//gelfcpp::output::GelfUDPOutput graylog("10.0.0.112", 12201);
void logfmt( TLogLevel level, const char * format, ... ) {
size_t n = 32678;
char buffer[n];
bzero(buffer, n);
try {
//FILELog::ReportingLevel() = level;
va_list args;
va_start (args, format);
if (level > FILELOG_MAX_LEVEL) ;
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ;
else {
FILE *f = Output2FILE::Stream();
fprintf(f, "- %s %s [%ld]: %c",
NowTime().c_str(),
FILELog::ToString(level).c_str(),
getpid(),
(level > logDEBUG ? level - logDEBUG : 0, '\t'));
vsnprintf (buffer, n, format, args);
fprintf(f, buffer);
fprintf(f, "\n");
}
va_end (args);
// Graylog
/*if (strlen(buffer) > 0) {
GELF_MESSAGE(graylog)
(CurrentTimeStamp())
("level", FILELog::ToString(level).c_str())
("pid", getpid())
(buffer);
} // */
} catch(const std::exception& e) {
FILE_LOG(logERROR) << e.what();
}
}
/*
void logfmt( TLogLevel level, const char * format, ... ) {
try {
//FILELog::ReportingLevel() = level;
char buffer[2048];
va_list args;
va_start (args, format);
vsprintf (buffer, format, args);
//perror (buffer);
va_end (args);
FILE_LOG(level) << buffer;
} catch(const std::exception& e) {
FILE_LOG(logERROR) << e.what();
}
}
*/
/* void GraylogStream(std::string raw) {
std::string marker1 ("]: ");
std::string marker2 (" [");
std::string marker3 (" ");
std::size_t found = raw.find(marker1);
if (found != std::string::npos) {
std::string msg = raw.substr (found + 3);
std::string level ("FLOG_MAX");
found = raw.find(marker2);
if (found != std::string::npos) {
std::string str = raw.substr(0, found - 1);
boost::trim_right(str);
found = str.find(marker3);
while (found != std::string::npos) {
level = str.substr(found);
found = str.find(marker3);
}
}
if (!msg.empty()) {
GELF_MESSAGE(graylog)
(CurrentTimeStamp())
("pid", getpid())
("level", level.c_str())
(msg.c_str());
}
}
}
// */