BCLog Class Reference

A class for managing log messages. More...

#include <BCLog.h>

List of all members.

Public Types

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

Public Member Functions

 BCLog ()
 ~BCLog ()

Static Public Member Functions

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

Static Private Member Functions

static const char * ToString (BCLog::LogLevel)

Static Private Attributes

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

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 28 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 44 of file BCLog.h.


Constructor & Destructor Documentation

BCLog::BCLog (  ) 

Constructor.

Definition at line 33 of file BCLog.cxx.

00034 {
00035    // suppress the ROOT Info printouts
00036    gErrorIgnoreLevel=2000;
00037 }

BCLog::~BCLog (  ) 

Destructor.

Definition at line 41 of file BCLog.cxx.

00042 {}


Member Function Documentation

void BCLog::CloseLog (  )  [static]

Closes the log file

Definition at line 90 of file BCLog.cxx.

00091 {
00092    BCLog::fOutputStream.close();
00093 }

static int BCLog::GetHIndex (  )  [inline, static]
Returns:
unique number for use in histogram name string

Definition at line 149 of file BCLog.h.

00150          { return BCLog::fHindex++; };

static BCLog::LogLevel BCLog::GetLogLevelFile (  )  [inline, static]

Returns the minimum log level for file output.

Returns:
log level

Definition at line 61 of file BCLog.h.

00062          { return fMinimumLogLevelFile; };

static BCLog::LogLevel BCLog::GetLogLevelScreen (  )  [inline, static]

Returns the minimum log level for screen output.

Returns:
log level

Definition at line 67 of file BCLog.h.

00068          { return fMinimumLogLevelScreen; };

static const char* BCLog::GetVersion (  )  [inline, static]
Returns:
string containing the version number

Definition at line 144 of file BCLog.h.

00145          { return fVersion; };

bool BCLog::IsOpen (  )  [static]
Returns:
true if log file is open or false if not.

Definition at line 83 of file BCLog.cxx.

00084 {
00085    return BCLog::fOutputStream.is_open();
00086 }

void BCLog::OpenLog (  )  [static]

Definition at line 76 of file BCLog.cxx.

00077 {
00078    BCLog::OpenLog("log.txt", BCLog::debug, BCLog::summary);
00079 }

void BCLog::OpenLog ( const char *  filename  )  [static]

Definition at line 69 of file BCLog.cxx.

00070 {
00071    BCLog::OpenLog(filename, BCLog::debug, BCLog::summary);
00072 }

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:
filename log filename
loglevelfile minimum log level for file output
loglevelscreen minimum log level for screen output

Definition at line 46 of file BCLog.cxx.

00047 {
00048    // suppress the ROOT Info printouts
00049    gErrorIgnoreLevel=2000;
00050 
00051    // open log file
00052    BCLog::fOutputStream.open(filename);
00053 
00054    if (!BCLog::fOutputStream.is_open())
00055    {
00056       std::cerr << " Could not open log file " << filename << ". " << std::endl;
00057       return;
00058    }
00059 
00060    // set log level
00061    BCLog::SetLogLevelFile(loglevelfile);
00062    BCLog::SetLogLevelScreen(loglevelscreen);
00063 
00064    BCLog::Out(BCLog::summary,BCLog::summary,Form("Opening logfile %s",filename));
00065 }

static void BCLog::Out ( BCLog::LogLevel  loglevel,
const char *  message 
) [inline, static]

Definition at line 120 of file BCLog.h.

00121          { Out(loglevel,loglevel,message); };

void BCLog::Out ( const char *  message  )  [static]

Definition at line 118 of file BCLog.cxx.

void BCLog::Out ( BCLog::LogLevel  loglevelfile,
BCLog::LogLevel  loglevelscreen,
const char *  message 
) [static]

Definition at line 97 of file BCLog.cxx.

00098 {
00099    // if this is the first call to Out(), call StartupInfo() first
00100    if(!fFirstOutputDone)
00101       BCLog::StartupInfo();
00102 
00103    // open log file if not opened
00104    if (BCLog::IsOpen())
00105    {
00106       // write message in to log file
00107       if (loglevelfile >= BCLog::fMinimumLogLevelFile)
00108          BCLog::fOutputStream << BCLog::ToString(loglevelfile) << " : " << message << std::endl;
00109    }
00110 
00111    // write message to screen
00112    if (loglevelscreen >= BCLog::fMinimumLogLevelScreen)
00113       std::cout << BCLog::ToString(loglevelscreen) << " : " << message << std::endl;
00114 }

static void BCLog::OutDebug ( const char *  message  )  [inline, static]

Definition at line 135 of file BCLog.h.

00136          { Out(debug,message); };

static void BCLog::OutDetail ( const char *  message  )  [inline, static]

Definition at line 132 of file BCLog.h.

00133          { Out(detail,message); };

static void BCLog::OutError ( const char *  message  )  [inline, static]

Definition at line 123 of file BCLog.h.

00124          { Out(error,message); };

static void BCLog::OutSummary ( const char *  message  )  [inline, static]

Definition at line 129 of file BCLog.h.

00130          { Out(summary,message); };

static void BCLog::OutWarning ( const char *  message  )  [inline, static]

Definition at line 126 of file BCLog.h.

00127          { Out(warning,message); };

static void BCLog::SetLogLevel ( BCLog::LogLevel  loglevel  )  [inline, static]

Sets the minimum log level for file and screen output.

Parameters:
loglevel log level

Definition at line 87 of file BCLog.h.

static void BCLog::SetLogLevelFile ( BCLog::LogLevel  loglevel  )  [inline, static]

Sets the minimum log level for file output.

Parameters:
loglevel log level

Definition at line 75 of file BCLog.h.

00076          { BCLog::fMinimumLogLevelFile = loglevel; };

static void BCLog::SetLogLevelScreen ( BCLog::LogLevel  loglevel  )  [inline, static]

Sets the minimum log level for screen output.

Parameters:
loglevel log level

Definition at line 81 of file BCLog.h.

00082          { BCLog::fMinimumLogLevelScreen = loglevel; };

void BCLog::StartupInfo (  )  [static]

Writes startup information onto screen and into a logfile

Definition at line 125 of file BCLog.cxx.

00126 {
00127    char * message = Form(
00128          " +------------------------------\n"
00129          " |\n"
00130          " |     Running with BAT\n"
00131          " |      Version %s\n"
00132          " |\n"
00133          " | http://www.mppmu.mpg.de/bat\n"
00134          " +------------------------------\n",
00135          BCLog::fVersion);
00136 
00137    if (BCLog::IsOpen() && BCLog::fMinimumLogLevelFile<BCLog::nothing)
00138       BCLog::fOutputStream << message;
00139 
00140    if (BCLog::fMinimumLogLevelScreen<BCLog::nothing)
00141       std::cout << message;
00142 
00143    fFirstOutputDone = true;
00144 }

const char * BCLog::ToString ( BCLog::LogLevel  loglevel  )  [static, private]

Converts a log level to a string

Definition at line 148 of file BCLog.cxx.

00149 {
00150 
00151    switch (loglevel)
00152    {
00153       case debug:
00154          return "Debug  ";
00155       case detail:
00156          return "Detail ";
00157       case summary:
00158          return "Summary";
00159       case warning:
00160          return "Warning";
00161       case error:
00162          return "Error  ";
00163       default:
00164          return "";
00165    }
00166 
00167 }


Member Data Documentation

bool BCLog::fFirstOutputDone = false [static, private]

Specifies wheather there were output printouts already

Definition at line 172 of file BCLog.h.

int BCLog::fHindex = 0 [static, private]

Global histogram counter

Definition at line 180 of file BCLog.h.

BCLog::LogLevel BCLog::fMinimumLogLevelFile = BCLog::debug [static, private]

The minimum file log level

Definition at line 160 of file BCLog.h.

BCLog::LogLevel BCLog::fMinimumLogLevelScreen = BCLog::summary [static, private]

The minimum screen log level

Definition at line 164 of file BCLog.h.

std::ofstream BCLog::fOutputStream [static, private]

The output stream for the file log

Definition at line 168 of file BCLog.h.

const char * BCLog::fVersion = VERSION [static, private]

BAT version number

Definition at line 150 of file BCLog.h.


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

Generated on Tue Oct 6 09:48:22 2009 for Bayesian Analysis Toolkit by  doxygen 1.6.1