Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes

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, BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen)
static void OpenLog (const char *filename)
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 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.

{debug, detail, summary, warning, error, nothing};


Constructor & Destructor Documentation

BCLog::BCLog (  ) 

Constructor.

Definition at line 33 of file BCLog.cxx.

{
   // suppress the ROOT Info printouts
   gErrorIgnoreLevel=2000;
}

BCLog::~BCLog (  ) 

Destructor.

Definition at line 41 of file BCLog.cxx.

{}


Member Function Documentation

void BCLog::CloseLog (  )  [static]

Closes the log file

Definition at line 90 of file BCLog.cxx.

{
   BCLog::fOutputStream.close();
}

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

Definition at line 149 of file BCLog.h.

         { 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.

         { 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.

         { return fMinimumLogLevelScreen; };

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

Definition at line 144 of file BCLog.h.

         { 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.

{
   return BCLog::fOutputStream.is_open();
}

void BCLog::OpenLog (  )  [static]

Definition at line 76 of file BCLog.cxx.

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.

{
   // suppress the ROOT Info printouts
   gErrorIgnoreLevel=2000;

   // open log file
   BCLog::fOutputStream.open(filename);

   if (!BCLog::fOutputStream.is_open())
   {
      std::cerr << " Could not open log file " << filename << ". " << std::endl;
      return;
   }

   // set log level
   BCLog::SetLogLevelFile(loglevelfile);
   BCLog::SetLogLevelScreen(loglevelscreen);

   BCLog::Out(BCLog::summary,BCLog::summary,Form("Opening logfile %s",filename));
}

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

Definition at line 69 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.

{
   // if this is the first call to Out(), call StartupInfo() first
   if(!fFirstOutputDone)
      BCLog::StartupInfo();

   // open log file if not opened
   if (BCLog::IsOpen())
   {
      // write message in to log file
      if (loglevelfile >= BCLog::fMinimumLogLevelFile)
         BCLog::fOutputStream << BCLog::ToString(loglevelfile) << " : " << message << std::endl;
   }

   // write message to screen
   if (loglevelscreen >= BCLog::fMinimumLogLevelScreen)
      std::cout << BCLog::ToString(loglevelscreen) << " : " << message << std::endl;
}

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

Definition at line 120 of file BCLog.h.

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

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

Definition at line 135 of file BCLog.h.

         { Out(debug,message); };

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

Definition at line 132 of file BCLog.h.

         { Out(detail,message); };

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

Definition at line 123 of file BCLog.h.

         { Out(error,message); };

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

Definition at line 129 of file BCLog.h.

         { Out(summary,message); };

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

Definition at line 126 of file BCLog.h.

         { 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.

         { 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.

void BCLog::StartupInfo (  )  [static]

Writes startup information onto screen and into a logfile

Definition at line 125 of file BCLog.cxx.

{
   char * message = Form(
         " +------------------------------\n"
         " |\n"
         " |     Running with BAT\n"
         " |      Version %s\n"
         " |\n"
         " | http://www.mppmu.mpg.de/bat\n"
         " +------------------------------\n",
         BCLog::fVersion);

   if (BCLog::IsOpen() && BCLog::fMinimumLogLevelFile<BCLog::nothing)
      BCLog::fOutputStream << message;

   if (BCLog::fMinimumLogLevelScreen<BCLog::nothing)
      std::cout << message;

   fFirstOutputDone = true;
}

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

Converts a log level to a string

Definition at line 148 of file BCLog.cxx.

{
   switch (loglevel)
   {
      case debug:
         return "Debug  ";
      case detail:
         return "Detail ";
      case summary:
         return "Summary";
      case warning:
         return "Warning";
      case error:
         return "Error  ";
      default:
         return "";
   }
}


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: