OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WLOGENTRY_H 00026 #define WLOGENTRY_H 00027 00028 #include <string> 00029 00030 #include "WTerminalColor.h" 00031 00032 00033 /** 00034 * Various log levels, to distinguish output on its level. 00035 */ 00036 typedef enum 00037 { 00038 LL_DEBUG = 0, 00039 LL_INFO, 00040 LL_WARNING, 00041 LL_ERROR 00042 } 00043 LogLevel; 00044 00045 /** 00046 * Simple function to convert a given string to an log level. If the string is invalid, LL_DEBUG is returned. 00047 * 00048 * \param str the string containing the log level string-representation 00049 * \return the loglevel 00050 */ 00051 LogLevel logLevelFromString( const std::string& str ); 00052 00053 /** 00054 * Represents a simple log message with some attributes. 00055 */ 00056 class WLogEntry // NOLINT 00057 { 00058 public: 00059 /** 00060 * Creates a new log message. 00061 * 00062 * \param logTime the time 00063 * \param message the message 00064 * \param level the log level 00065 * \param source the source, sending the log 00066 */ 00067 WLogEntry( std::string logTime, std::string message, LogLevel level, std::string source = "" ); 00068 00069 /** 00070 * Destroys a log message entry. 00071 */ 00072 virtual ~WLogEntry(); 00073 00074 /** 00075 * \param format A string describing the output format in c printf style 00076 * \param colors True if colors should be used. True is the default. 00077 * 00078 * \return String of this log entry. 00079 */ 00080 std::string getLogString( std::string format = "[%t] *%l* %m \n", bool colors = true ) const; 00081 00082 /** 00083 * \return log level of this entry. 00084 */ 00085 LogLevel getLogLevel() const; 00086 00087 /** 00088 * Returns the plain message of the entry. 00089 * 00090 * \return the message 00091 */ 00092 std::string getMessage() const; 00093 00094 /** 00095 * Returns the sender of the log. 00096 * 00097 * \return sender 00098 */ 00099 std::string getSource() const; 00100 00101 /** 00102 * Returns the formatted time string. 00103 * 00104 * \return time string 00105 */ 00106 std::string getTime() const; 00107 00108 protected: 00109 private: 00110 /** 00111 * The time the log message was received 00112 */ 00113 std::string m_time; 00114 00115 /** 00116 * The actual message 00117 */ 00118 std::string m_message; 00119 00120 /** 00121 * Log level 00122 */ 00123 LogLevel m_level; 00124 00125 /** 00126 * Source (e.g. module name) where this log message comes from. 00127 */ 00128 std::string m_source; 00129 00130 /** 00131 * Color used for error logs. 00132 * 00133 * \note it is mutable to allow en-/disabling the colors during getLogString. 00134 */ 00135 mutable WTerminalColor m_errorColor; 00136 00137 /** 00138 * Color used for info logs 00139 * 00140 * \note it is mutable to allow en-/disabling the colors during getLogString. 00141 */ 00142 mutable WTerminalColor m_infoColor; 00143 00144 /** 00145 * Color used for debug logs. 00146 * 00147 * \note it is mutable to allow en-/disabling the colors during getLogString. 00148 */ 00149 mutable WTerminalColor m_debugColor; 00150 00151 /** 00152 * Color used for warning logs. 00153 * 00154 * \note it is mutable to allow en-/disabling the colors during getLogString. 00155 */ 00156 mutable WTerminalColor m_warningColor; 00157 00158 /** 00159 * Color used for source field. 00160 * 00161 * \note it is mutable to allow en-/disabling the colors during getLogString. 00162 */ 00163 mutable WTerminalColor m_sourceColor; 00164 00165 /** 00166 * Color used for time. 00167 * 00168 * \note it is mutable to allow en-/disabling the colors during getLogString. 00169 */ 00170 mutable WTerminalColor m_timeColor; 00171 00172 /** 00173 * Color used for the message. 00174 * 00175 * \note it is mutable to allow en-/disabling the colors during getLogString. 00176 */ 00177 mutable WTerminalColor m_messageColor; 00178 }; 00179 00180 #endif // WLOGENTRY_H 00181