add option to control verboseness of log

This commit is contained in:
ps 2011-03-17 20:48:44 +00:00
parent f1bd5df29d
commit 2dde08953a
4 changed files with 19 additions and 10 deletions

View file

@ -150,6 +150,12 @@ string,submit_stats_username,"anonymous"
* password * password
string,submit_stats_password,"anonymous" string,submit_stats_password,"anonymous"
* log level:
* 0: log only errors
* 1: log errors and information (default)
* 2: debug (passwords might be written in plaintext with this option, so use with care)
int,log_level,1
#if LOGGER_CLASS==FileLogger #if LOGGER_CLASS==FileLogger
* if you are using the filelogger, which file to log to. * if you are using the filelogger, which file to log to.
string,file_logger_filename,"hermes.log" string,file_logger_filename,"hermes.log"

View file

@ -70,12 +70,12 @@ void FileLogger::syncBufferToDisk()
void FileLogger::addMessage(string file,int line,int loglevel,string logmessage) void FileLogger::addMessage(string file,int line,int loglevel,string logmessage)
{ {
if(loglevel>cfg.getLogLevel()) return;
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
if(cfg.getLogRotationFrequency()>0&&last_rotation+(cfg.getLogRotationFrequency()*60)<time(NULL)) if(cfg.getLogRotationFrequency()>0&&last_rotation+(cfg.getLogRotationFrequency()*60)<time(NULL))
{ {
#ifdef REALLY_VERBOSE_DEBUG
cout << "Rotating log to file " << getProcessedRotateFilename() << " at " << time(NULL) << " with a last rotation of " << last_rotation << endl;
#endif //REALLY_VERBOSE_DEBUG
rotateLog(); rotateLog();
addMessage(__FILE__,__LINE__,LOG_DEBUG,"Rotated log to file " + getProcessedRotateFilename() + " at " + Utils::ulongtostr(time(NULL)) + " with a last rotation of " + Utils::ulongtostr(last_rotation)); addMessage(__FILE__,__LINE__,LOG_DEBUG,"Rotated log to file " + getProcessedRotateFilename() + " at " + Utils::ulongtostr(time(NULL)) + " with a last rotation of " + Utils::ulongtostr(last_rotation));
} }

View file

@ -39,9 +39,9 @@ class Logger
#endif //WIN32 #endif //WIN32
#ifndef LOG_INFO #ifndef LOG_INFO
#define LOG_INFO 0 #define LOG_ERR 0
#define LOG_DEBUG 1 #define LOG_INFO 1
#define LOG_ERR 2 #define LOG_DEBUG 2
#endif //LOG_INFO #endif //LOG_INFO
#include "FileLogger.h" #include "FileLogger.h"
#include "NullLogger.h" #include "NullLogger.h"

View file

@ -36,8 +36,11 @@ void UnixLogger::addMessage(string file,int line,int loglevel,string logmessage)
{ {
string message; string message;
message=file+":"+Utils::inttostr(line)+" [" + Utils::inttostr(connection_id) + "] " + logmessage; if(loglevel<=cfg.getLogLevel())
if(false==cfg.getBackground()) {
cout << message << endl; message=file+":"+Utils::inttostr(line)+" [" + Utils::inttostr(connection_id) + "] " + logmessage;
syslog(loglevel,message.c_str()); if(false==cfg.getBackground())
cout << message << endl;
syslog(loglevel,message.c_str());
}
} }