Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
Logger.cpp
1 #include <log4cpp/Category.hh>
2 #include <log4cpp/PatternLayout.hh>
3 #include <log4cpp/PropertyConfigurator.hh>
4 #include "Logger.h"
5 #include <log4cpp/RollingFileAppender.hh>
6 #include <QString>
7 
8 log4cpp::Category *mainCat;
9 
10 const QString INDENTATION_PAST_TIMESTAMP (" ");
11 const QString INDENTATION_DELTA (" ");
12 
13 void initializeLogging (const QString &name,
14  const QString &filename,
15  bool isDebug)
16 {
17  const size_t MAX_FILE_SIZE_BYTES = 6 * 1024 * 1024; // Size that should satisfy most email servers
18  const unsigned int MAX_BACKUP_INDEX = 2;
19  const bool APPEND_TO_PREVIOUS_FILE = false;
20 
21  log4cpp::RollingFileAppender *appender = new log4cpp::RollingFileAppender (name.toStdString (),
22  filename.toStdString (),
23  MAX_FILE_SIZE_BYTES,
24  MAX_BACKUP_INDEX,
25  APPEND_TO_PREVIOUS_FILE);
26 
27  log4cpp::PatternLayout *layout = new log4cpp::PatternLayout ();
28  layout->setConversionPattern ("%d{%H:%M:%S.%l} %-5p %c - %m%n");
29  appender->setLayout (layout);
30 
31  mainCat = &log4cpp::Category::getRoot ();
32 
33  // Levels are EMERG, FATAL, ALERT, CRIT, ERROR, WARN, NOTICE, INFO, DEBUG.
34  //
35  // Most trace logging is at INFO level, but methods that are called extremely often (like mouse
36  // moves and status bar updates) are at the lower DEBUG level so they are rarely seen
37  if (isDebug) {
38  mainCat->setPriority (log4cpp::Priority::DEBUG);
39  } else {
40  mainCat->setPriority (log4cpp::Priority::INFO);
41  }
42 
43  mainCat->addAppender (appender);
44 }