• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

BCLog.h

Go to the documentation of this file.
00001 #ifndef __BCLOG__H
00002 #define __BCLOG__H
00003 
00004 /*!
00005  * \class BCLog
00006  * \brief A class for managing log messages.
00007  * \author Daniel Kollar
00008  * \author Kevin Kröninger
00009  * \version 1.0
00010  * \date 08.2008
00011  * \detail This class manages log messages for printing on the screen
00012  * and into a log file
00013  */
00014 
00015 /*
00016  * Copyright (C) 2008-2010, Daniel Kollar and Kevin Kroeninger.
00017  * All rights reserved.
00018  *
00019  * For the licensing terms see doc/COPYING.
00020  */
00021 
00022 // ---------------------------------------------------------
00023 
00024 #include <iostream>
00025 
00026 // ---------------------------------------------------------
00027 
00028 class BCLog
00029 {
00030    public:
00031 
00032       // definition of log level
00033 
00034       /**
00035        * Enumerator for the amount of details to put into the log file
00036        * Log levels:
00037        * debug   : Lowest level of information
00038        * detail  : Details of functions, etc.
00039        * summary : Results
00040        * warning : Warning messages
00041        * error   : Error message
00042        * nothing : No output
00043        */
00044       enum LogLevel {debug, detail, summary, warning, error, nothing};
00045 
00046       // constructor and destructor
00047 
00048       /**
00049        * Constructor. */
00050       BCLog();
00051 
00052       /**
00053        * Destructor. */
00054       ~BCLog();
00055 
00056       // methods (get)
00057 
00058       /**
00059        * Returns the minimum log level for file output.
00060        * @return log level */
00061       static BCLog::LogLevel GetLogLevelFile()
00062          { return fMinimumLogLevelFile; };
00063 
00064       /**
00065        * Returns the minimum log level for screen output.
00066        * @return log level */
00067       static BCLog::LogLevel GetLogLevelScreen()
00068          { return fMinimumLogLevelScreen; };
00069 
00070       // method (set)
00071 
00072       /**
00073        * Sets the minimum log level for file output.
00074        * @param loglevel log level */
00075       static void SetLogLevelFile(BCLog::LogLevel loglevel)
00076          { BCLog::fMinimumLogLevelFile = loglevel; };
00077 
00078       /**
00079        * Sets the minimum log level for screen output.
00080        * @param loglevel log level */
00081       static void SetLogLevelScreen(BCLog::LogLevel loglevel)
00082          { BCLog::fMinimumLogLevelScreen = loglevel; };
00083 
00084       /**
00085        * Sets the minimum log level for file and screen output.
00086        * @param loglevel log level */
00087       static void SetLogLevel(BCLog::LogLevel loglevel)
00088          { BCLog::fMinimumLogLevelFile = loglevel; BCLog::fMinimumLogLevelScreen = loglevel; };
00089 
00090       // methods
00091 
00092       /**
00093        * Opens log file and sets minimum log levels for file and screen output.
00094        * @param filename log filename
00095        * @param loglevelfile minimum log level for file output
00096        * @param loglevelscreen minimum log level for screen output */
00097       static void OpenLog(const char * filename, BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen);
00098 
00099       static void OpenLog(const char * filename);
00100 
00101       static void OpenLog();
00102 
00103       /**
00104        * @returns true if log file is open or false if not. */
00105       static bool IsOpen();
00106 
00107       /**
00108        * Closes the log file */
00109       static void CloseLog();
00110 
00111       /*
00112        * Writes string to the file and screen log if the log level is equal or greater than the minimum
00113        * @param loglevelfile loglevel for the current message
00114        * @param loglevelscreen loglevel for the current message
00115        * @param message string to write to the file and screen log */
00116       static void Out(BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen, const char * message);
00117 
00118       static void Out(const char * message);
00119 
00120       static void Out(BCLog::LogLevel loglevel, const char * message)
00121          { Out(loglevel,loglevel,message); };
00122 
00123       static void OutError(const char * message)
00124          { Out(error,message); };
00125 
00126       static void OutWarning(const char * message)
00127          { Out(warning,message); };
00128 
00129       static void OutSummary(const char * message)
00130          { Out(summary,message); };
00131 
00132       static void OutDetail(const char * message)
00133          { Out(detail,message); };
00134 
00135       static void OutDebug(const char * message)
00136          { Out(debug,message); };
00137 
00138       /**
00139        * Writes startup information onto screen and into a logfile */
00140       static void StartupInfo();
00141 
00142       /**
00143        * @return string containing the version number  */
00144       static const char * GetVersion()
00145          { return fVersion; };
00146 
00147       /**
00148        * @return unique number for use in histogram name string */
00149       static int GetHIndex()
00150          { return BCLog::fHindex++; };
00151 
00152    private:
00153 
00154       /**
00155        * BAT version number */
00156       static const char * fVersion;
00157 
00158       /**
00159        * The minimum file log level */
00160       static BCLog::LogLevel fMinimumLogLevelFile;
00161 
00162       /**
00163        * The minimum screen log level */
00164       static BCLog::LogLevel fMinimumLogLevelScreen;
00165 
00166       /**
00167        * The output stream for the file log */
00168       static std::ofstream fOutputStream;
00169 
00170       /**
00171        * Specifies wheather there were output printouts already */
00172       static bool fFirstOutputDone;
00173 
00174       /**
00175        * Converts a log level to a string */
00176       static const char * ToString(BCLog::LogLevel);
00177 
00178       /**
00179        * Global histogram counter */
00180       static int fHindex;
00181 };
00182 
00183 // ---------------------------------------------------------
00184 
00185 #endif

Generated on Mon Aug 30 2010 22:14:54 for Bayesian Analysis Toolkit by  doxygen 1.7.1