00001 #ifndef __BCLOG__H 00002 #define __BCLOG__H 00003 00015 /* 00016 * Copyright (C) 2008, 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 00044 enum LogLevel {debug, detail, summary, warning, error, nothing}; 00045 00046 // constructor and destructor 00047 00050 BCLog(); 00051 00054 ~BCLog(); 00055 00056 // methods (get) 00057 00061 static BCLog::LogLevel GetLogLevelFile() 00062 { return fMinimumLogLevelFile; }; 00063 00067 static BCLog::LogLevel GetLogLevelScreen() 00068 { return fMinimumLogLevelScreen; }; 00069 00070 // method (set) 00071 00075 static void SetLogLevelFile(BCLog::LogLevel loglevel) 00076 { BCLog::fMinimumLogLevelFile = loglevel; }; 00077 00081 static void SetLogLevelScreen(BCLog::LogLevel loglevel) 00082 { BCLog::fMinimumLogLevelScreen = loglevel; }; 00083 00087 static void SetLogLevel(BCLog::LogLevel loglevel) 00088 { BCLog::fMinimumLogLevelFile = loglevel; BCLog::fMinimumLogLevelScreen = loglevel; }; 00089 00090 // methods 00091 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 00105 static bool IsOpen(); 00106 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 00122 static void StartupInfo(); 00123 00126 static const char * GetVersion() 00127 { return fVersion; }; 00128 00131 static int GetHIndex() 00132 { return BCLog::fHindex++; }; 00133 00134 private: 00135 00138 static const char * fVersion; 00139 00142 static BCLog::LogLevel fMinimumLogLevelFile; 00143 00146 static BCLog::LogLevel fMinimumLogLevelScreen; 00147 00150 static std::ofstream fOutputStream; 00151 00154 static bool fFirstOutputDone; 00155 00158 static const char * ToString(BCLog::LogLevel); 00159 00162 static int fHindex; 00163 }; 00164 00165 // --------------------------------------------------------- 00166 00167 #endif