Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created March 26, 2014 19:54
Show Gist options
  • Save waffle2k/9791779 to your computer and use it in GitHub Desktop.
Save waffle2k/9791779 to your computer and use it in GitHub Desktop.
Example of using the c++ logging
std::clog.rdbuf(new log::FileLog("/dev/stderr"));
if (char *l = getenv("DEBUGLOG")){
if (0==strcmp("syslog",l)){
std::clog.rdbuf(new log::SysLog(argv[0], LOG_LOCAL0));
}
else {
// Assign it to the supplied file
std::clog.rdbuf(new log::FileLog(l));
}
}
for (int i = start; i < end; i++){
std::cout << "Setting filter to " << logfilterstr(log::kLogInfo) << "[" << log::kLogInfo << "]" << std::endl << std::endl;
static_cast<log::FileLog *>(std::clog.rdbuf())->filter( log::kLogInfo );
std::clog << log::kLogEmerg << "Testing the logging facilities [kLogEmerg]" << std::endl;
std::clog << log::kLogAlert << "Testing the logging facilities [kLogAlert]" << std::endl;
std::clog << log::kLogCrit << "Testing the logging facilities [kLogCrit]" << std::endl;
std::clog << log::kLogErr << "Testing the logging facilities [kLogErr]" << std::endl;
std::clog << log::kLogWarning << "Testing the logging facilities [kLogWarning]" << std::endl;
std::clog << log::kLogNotice << "Testing the logging facilities [kLogNotice]" << std::endl;
std::clog << log::kLogInfo << "Testing the logging facilities [kLogInfo]" << std::endl;
std::clog << log::kLogDebug << "Testing the logging facilities [kLogDebug]" << std::endl;
std::clog << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment