BayesianAnalysisToolkit  0.9.3
Public Types | Static Private Attributes | List of all members
BCLog Class Reference

A class for managing log messages. More...

#include <BCLog.h>

Public Types

enum  LogLevel {
  debug, detail, summary, warning,
  error, nothing
}
 

Public Member Functions

Constructors and destructors
 BCLog ()
 
 ~BCLog ()
 

Static Public Member Functions

Getters
static BCLog::LogLevel GetLogLevelFile ()
 
static BCLog::LogLevel GetLogLevelScreen ()
 
Setters
static void SetLogLevelFile (BCLog::LogLevel loglevel)
 
static void SetLogLevelScreen (BCLog::LogLevel loglevel)
 
static void SetLogLevel (BCLog::LogLevel loglevelscreen, BCLog::LogLevel loglevelfile)
 
static void SetLogLevel (BCLog::LogLevel loglevel)
 
Miscellaneous
static void OpenLog (const char *filename, BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen)
 
static void OpenLog (const char *filename)
 
static void OpenLog ()
 
static bool IsOpen ()
 
static void CloseLog ()
 
static void Out (BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen, const char *message)
 
static void Out (const char *message)
 
static void Out (BCLog::LogLevel loglevel, const char *message)
 
static void OutError (const char *message)
 
static void OutWarning (const char *message)
 
static void OutSummary (const char *message)
 
static void OutDetail (const char *message)
 
static void OutDebug (const char *message)
 
static void StartupInfo ()
 
static const char * GetVersion ()
 
static int GetHIndex ()
 
static const char * ToString (BCLog::LogLevel)
 

Static Private Attributes

static const char * fVersion = VERSION
 
static BCLog::LogLevel fMinimumLogLevelFile = BCLog::debug
 
static BCLog::LogLevel fMinimumLogLevelScreen = BCLog::summary
 
static std::ofstream fOutputStream
 
static bool fFirstOutputDone = false
 
static int fHindex = 0
 

Detailed Description

A class for managing log messages.

Author
Daniel Kollar
Kevin Kröninger
Version
1.0
Date
08.2008 This class manages log messages for printing on the screen and into a log file

Definition at line 29 of file BCLog.h.

Member Enumeration Documentation

Enumerator for the amount of details to put into the log file Log levels: debug : Lowest level of information detail : Details of functions, etc. summary : Results warning : Warning messages error : Error message nothing : No output

Enumerator
debug 
detail 
summary 
warning 
error 
nothing 

Definition at line 45 of file BCLog.h.

Constructor & Destructor Documentation

BCLog::BCLog ( )

Constructor.

Definition at line 36 of file BCLog.cxx.

37 {
38  // suppress the ROOT Info printouts
39  gErrorIgnoreLevel=2000;
40 }
BCLog::~BCLog ( )

Destructor.

Definition at line 44 of file BCLog.cxx.

45 {}

Member Function Documentation

void BCLog::CloseLog ( )
static

Closes the log file

Definition at line 93 of file BCLog.cxx.

94 {
95  BCLog::fOutputStream.close();
96 }
static int BCLog::GetHIndex ( )
inlinestatic
Returns
unique number for use in histogram name string

Definition at line 164 of file BCLog.h.

165  { return BCLog::fHindex++; };
static BCLog::LogLevel BCLog::GetLogLevelFile ( )
inlinestatic

Returns the minimum log level for file output.

Returns
log level

Definition at line 65 of file BCLog.h.

66  { return fMinimumLogLevelFile; };
static BCLog::LogLevel BCLog::GetLogLevelScreen ( )
inlinestatic

Returns the minimum log level for screen output.

Returns
log level

Definition at line 71 of file BCLog.h.

72  { return fMinimumLogLevelScreen; };
static const char* BCLog::GetVersion ( )
inlinestatic
Returns
string containing the version number

Definition at line 159 of file BCLog.h.

160  { return fVersion; };
bool BCLog::IsOpen ( )
static
Returns
true if log file is open or false if not.

Definition at line 86 of file BCLog.cxx.

87 {
88  return BCLog::fOutputStream.is_open();
89 }
void BCLog::OpenLog ( const char *  filename,
BCLog::LogLevel  loglevelfile,
BCLog::LogLevel  loglevelscreen 
)
static

Opens log file and sets minimum log levels for file and screen output.

Parameters
filenamelog filename
loglevelfileminimum log level for file output
loglevelscreenminimum log level for screen output

Definition at line 49 of file BCLog.cxx.

50 {
51  // suppress the ROOT Info printouts
52  gErrorIgnoreLevel=2000;
53 
54  // open log file
55  BCLog::fOutputStream.open(filename);
56 
57  if (!BCLog::fOutputStream.is_open())
58  {
59  std::cerr << " Could not open log file " << filename << ". " << std::endl;
60  return;
61  }
62 
63  // set log level
64  BCLog::SetLogLevelFile(loglevelfile);
65  BCLog::SetLogLevelScreen(loglevelscreen);
66 
67  BCLog::Out(BCLog::summary,BCLog::summary,Form("Opening logfile %s",filename));
68 }
void BCLog::OpenLog ( const char *  filename)
static

Definition at line 72 of file BCLog.cxx.

73 {
75 }
void BCLog::OpenLog ( )
static

Definition at line 79 of file BCLog.cxx.

80 {
82 }
void BCLog::Out ( BCLog::LogLevel  loglevelfile,
BCLog::LogLevel  loglevelscreen,
const char *  message 
)
static

Writes string to the file and screen log if the log level is equal or greater than the minimum

Parameters
loglevelfileloglevel for the current message
loglevelscreenloglevel for the current message
messagestring to write to the file and screen log

Definition at line 100 of file BCLog.cxx.

101 {
102  // if this is the first call to Out(), call StartupInfo() first
103  if(!fFirstOutputDone)
105 
106  // open log file if not opened
107  if (BCLog::IsOpen())
108  {
109  // write message in to log file
110  if (loglevelfile >= BCLog::fMinimumLogLevelFile)
111  BCLog::fOutputStream << BCLog::ToString(loglevelfile) << " : " << message << std::endl;
112  }
113 
114  // write message to screen
115  if (loglevelscreen >= BCLog::fMinimumLogLevelScreen)
116  std::cout << BCLog::ToString(loglevelscreen) << " : " << message << std::endl;
117 }
void BCLog::Out ( const char *  message)
static

Definition at line 121 of file BCLog.cxx.

static void BCLog::Out ( BCLog::LogLevel  loglevel,
const char *  message 
)
inlinestatic

Definition at line 135 of file BCLog.h.

136  { Out(loglevel,loglevel,message); };
static void BCLog::OutDebug ( const char *  message)
inlinestatic

Definition at line 150 of file BCLog.h.

151  { Out(debug,message); };
static void BCLog::OutDetail ( const char *  message)
inlinestatic

Definition at line 147 of file BCLog.h.

148  { Out(detail,message); };
static void BCLog::OutError ( const char *  message)
inlinestatic

Definition at line 138 of file BCLog.h.

139  { Out(error,message); };
static void BCLog::OutSummary ( const char *  message)
inlinestatic

Definition at line 144 of file BCLog.h.

145  { Out(summary,message); };
static void BCLog::OutWarning ( const char *  message)
inlinestatic

Definition at line 141 of file BCLog.h.

142  { Out(warning,message); };
static void BCLog::SetLogLevel ( BCLog::LogLevel  loglevelscreen,
BCLog::LogLevel  loglevelfile 
)
inlinestatic

Sets the minimum log level for file and screen output.

Parameters
loglevelscreenlog level for screen
loglevelfilelog level for file

Definition at line 94 of file BCLog.h.

95  { BCLog::fMinimumLogLevelFile = loglevelfile; BCLog::fMinimumLogLevelScreen = loglevelscreen; };
static void BCLog::SetLogLevel ( BCLog::LogLevel  loglevel)
inlinestatic

Sets the minimum log level for file and screen output.

Parameters
loglevellog level

Definition at line 100 of file BCLog.h.

101  { SetLogLevel(loglevel, loglevel); };
static void BCLog::SetLogLevelFile ( BCLog::LogLevel  loglevel)
inlinestatic

Sets the minimum log level for file output.

Parameters
loglevellog level

Definition at line 81 of file BCLog.h.

82  { BCLog::fMinimumLogLevelFile = loglevel; };
static void BCLog::SetLogLevelScreen ( BCLog::LogLevel  loglevel)
inlinestatic

Sets the minimum log level for screen output.

Parameters
loglevellog level

Definition at line 87 of file BCLog.h.

88  { BCLog::fMinimumLogLevelScreen = loglevel; };
void BCLog::StartupInfo ( )
static

Writes startup information onto screen and into a logfile

Definition at line 128 of file BCLog.cxx.

129 {
130  char * message = Form(
131  " +------------------------------------------------------+\n"
132  " | |\n"
133  " | BAT version %7s |\n"
134  " | Copyright (C) 2007-2013, the BAT core developer team |\n"
135  " | All rights reserved. |\n"
136  " | |\n"
137  " | For the licensing terms see doc/COPYING |\n"
138  " | For documentation see http://mpp.mpg.de/bat |\n"
139  " | |\n"
140  " +------------------------------------------------------+\n",
142 
143  // write message to screen
145  std::cout << message << std::endl;
146 
148  BCLog::fOutputStream << message;
149 
150  fFirstOutputDone = true;
151 }
const char * BCLog::ToString ( BCLog::LogLevel  loglevel)
static

Converts a log level to a string

Definition at line 155 of file BCLog.cxx.

156 {
157  switch (loglevel)
158  {
159  case debug:
160  return "Debug ";
161  case detail:
162  return "Detail ";
163  case summary:
164  return "Summary";
165  case warning:
166  return "Warning";
167  case error:
168  return "Error ";
169  default:
170  return "";
171  }
172 }

Member Data Documentation

bool BCLog::fFirstOutputDone = false
staticprivate

Specifies wheather there were output printouts already

Definition at line 192 of file BCLog.h.

int BCLog::fHindex = 0
staticprivate

Global histogram counter

Definition at line 196 of file BCLog.h.

BCLog::LogLevel BCLog::fMinimumLogLevelFile = BCLog::debug
staticprivate

The minimum file log level

Definition at line 180 of file BCLog.h.

BCLog::LogLevel BCLog::fMinimumLogLevelScreen = BCLog::summary
staticprivate

The minimum screen log level

Definition at line 184 of file BCLog.h.

std::ofstream BCLog::fOutputStream
staticprivate

The output stream for the file log

Definition at line 188 of file BCLog.h.

const char * BCLog::fVersion = VERSION
staticprivate

BAT version number

Definition at line 176 of file BCLog.h.


The documentation for this class was generated from the following files: