FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairLogger.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 /*
9  * FairLogger.h
10  *
11  * Created on: Mar 03, 2011
12  * Author: f.uhlig
13  */
14 
15 #ifndef BASE_FAIRLOGGER_H_
16 #define BASE_FAIRLOGGER_H_
17 
18 #include <Rtypes.h> // for bool, FairLogger::Class, etc
19 #include <fairlogger/Logger.h>
20 #include <stdarg.h> // for va_list
21 #include <string> // for operator<<
22 #include <vector> // for vector
23 
24 #define MESSAGE_ORIGIN __FILE__, CONVERTTOSTRING(__LINE__), __FUNCTION__
25 
26 // backwards-compatibility with older FairLogger calls, TODO: delete me as soon as possible
28 {
38 };
39 
40 // backwards-compatibility with older FairLogger calls, TODO: delete me as soon as possible
41 static const char* const LogLevelString[] =
42  {"FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"};
43 
45 {
46  public:
47  static FairLogger* GetLogger();
48 
49  void SetLogToScreen(bool enabled)
50  {
51  if (enabled) {
52  fair::Logger::SetConsoleSeverity(fConsoleSeverity);
53  } else {
54  fair::Logger::SetConsoleSeverity(fair::Severity::fatal);
55  }
56  }
57 
58  void SetLogScreenLevel(const char* severity)
59  {
60  fConsoleSeverity = severity;
61  fair::Logger::SetConsoleSeverity(fConsoleSeverity);
62  }
63 
64  void SetLogToFile(bool enabled)
65  {
66  if (enabled) {
67  fair::Logger::SetFileSeverity(fLogFileSeverity);
68  } else {
69  fair::Logger::SetFileSeverity(fair::Severity::fatal);
70  }
71  }
72 
73  void SetLogFileLevel(const char* severity)
74  {
75  fLogFileSeverity = severity;
76  fair::Logger::SetFileSeverity(fLogFileSeverity);
77  }
78 
79  void SetLogFileName(const std::string& name)
80  {
81  fLogFileName = name;
82  OpenLogFile();
83  }
84 
85  void SetColoredLog(bool enabled) { fair::Logger::SetConsoleColor(enabled); }
86 
87  void SetLogVerbosityLevel(const char* verbosity) { fair::Logger::SetVerbosity(verbosity); }
88 
89  bool IsLogNeeded(fair::Severity severity);
91  deprecated("Use 'IsLogNeeded(fair::Severity severity)' or 'fair::Logger::Logging(const fair::Severity "
92  "severity)' or 'fair::Logger::Logging(const std::string& severityStr)'")));
93 
94  void Fatal(const char* file, const char* line, const char* func, const char* format, ...)
95  __attribute__((deprecated("Use 'LOG(fatal) << content;' macro interface instead.")));
96  void Error(const char* file, const char* line, const char* func, const char* format, ...)
97  __attribute__((deprecated("Use 'LOG(error) << content;' macro interface instead.")));
98  void Warning(const char* file, const char* line, const char* func, const char* format, ...)
99  __attribute__((deprecated("Use 'LOG(warn) << content;' macro interface instead.")));
100  void Info(const char* file, const char* line, const char* func, const char* format, ...)
101  __attribute__((deprecated("Use 'LOG(info) << content;' macro interface instead.")));
102  void Debug(const char* file, const char* line, const char* func, const char* format, ...)
103  __attribute__((deprecated("Use 'LOG(debug) << content;' macro interface instead.")));
104  void Debug1(const char* file, const char* line, const char* func, const char* format, ...)
105  __attribute__((deprecated("Use 'LOG(debug1) << content;' macro interface instead.")));
106  void Debug2(const char* file, const char* line, const char* func, const char* format, ...)
107  __attribute__((deprecated("Use 'LOG(debug2) << content;' macro interface instead.")));
108  void Debug3(const char* file, const char* line, const char* func, const char* format, ...)
109  __attribute__((deprecated("Use 'LOG(debug3) << content;' macro interface instead.")));
110  void Debug4(const char* file, const char* line, const char* func, const char* format, ...)
111  __attribute__((deprecated("Use 'LOG(debug4) << content;' macro interface instead.")));
112 
113  static char const endl __attribute__((
114  deprecated("Line break is now added automatically by the LOG macro, this variable only adds empty space.")));
115  static char const flush __attribute__((
116  deprecated("Data is now flushed automatically by the LOG macro, this variable only adds empty space.")));
117 
118  void SetScreenStreamToCerr(bool /* useCerr */) {}
119 
120  private:
121  static FairLogger* instance;
122 
123  FairLogger();
124  FairLogger(const FairLogger&);
125  FairLogger operator=(const FairLogger&);
126 
127  ~FairLogger() {}
128 
129  void Log(fair::Severity level,
130  const char* file,
131  const char* line,
132  const char*,
133  const char* format,
134  va_list arglist);
135 
136  const char* ConvertLogLevelToString(FairLogLevel level) const { return LogLevelString[level]; }
137 
138  static void LogFatalMessage();
139 
140  void OpenLogFile() { fair::Logger::InitFileSink(fLogFileSeverity, fLogFileName, false); }
141 
142  void CloseLogFile() { fair::Logger::RemoveFileSink(); }
143 
144  std::string fLogFileName;
145  std::string fLogFileSeverity;
146  std::string fConsoleSeverity;
147 
148  int fBufferSize;
149  int fBufferSizeNeeded;
150  std::vector<char> fDynamicBuffer;
151  char* fBufferPointer;
152 
153  ClassDef(FairLogger, 4);
154 };
155 
156 #define gLogger (FairLogger::GetLogger())
157 
158 #endif // BASE_FAIRLOGGER_H_
void SetLogScreenLevel(const char *severity)
Definition: FairLogger.h:58
bool IsLogNeeded(FairLogLevel level) __attribute__((deprecated("Use 'IsLogNeeded(fair macro interface instead
Definition: FairLogger.h:90
void Debug4(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(debug4) << content
Definition: FairLogger.cxx:126
void Warning(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(warn) << content
Definition: FairLogger.cxx:66
void SetLogFileLevel(const char *severity)
Definition: FairLogger.h:73
void Debug1(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(debug1) << content
Definition: FairLogger.cxx:96
void Error(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(error) << content
Definition: FairLogger.cxx:56
void SetLogFileName(const std::string &name)
Definition: FairLogger.h:79
FairLogLevel
Definition: FairLogger.h:27
void Debug(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(debug) << content
Definition: FairLogger.cxx:86
void SetLogToScreen(bool enabled)
Definition: FairLogger.h:49
void SetLogToFile(bool enabled)
Definition: FairLogger.h:64
static FairLogger * GetLogger()
Definition: FairLogger.cxx:39
static char const endl __attribute__((deprecated("Line break is now added automatically by the LOG macro, this variable only adds empty space.")))
bool IsLogNeeded(fair::Severity severity)
Definition: FairLogger.cxx:174
void Info(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(info) << content
Definition: FairLogger.cxx:76
void Debug2(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(debug2) << content
Definition: FairLogger.cxx:106
void Debug3(const char *file, const char *line, const char *func, const char *format,...) __attribute__((deprecated("Use 'LOG(debug3) << content
Definition: FairLogger.cxx:116
void SetScreenStreamToCerr(bool)
Definition: FairLogger.h:118
void SetLogVerbosityLevel(const char *verbosity)
Definition: FairLogger.h:87
void SetColoredLog(bool enabled)
Definition: FairLogger.h:85