OpenWalnut 1.2.5
WLogEntry.h
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 #include "WExportCommon.h"
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 OWCOMMON_EXPORT WLogEntry // NOLINT
00057 {
00058 public:
00059 
00060     /**
00061      * Creates a new log message.
00062      *
00063      * \param logTime  the time
00064      * \param message  the message
00065      * \param level    the log level
00066      * \param source   the source, sending the log
00067      */
00068     WLogEntry( std::string logTime, std::string message, LogLevel level, std::string source = "" );
00069 
00070     /**
00071      * Destroys a log message entry.
00072      */
00073     virtual ~WLogEntry();
00074 
00075     /**
00076      * \param format A string describing the output format in c printf style
00077      * \param colors True if colors should be used. True is the default.
00078      *
00079      * \return String of this log entry.
00080      */
00081     std::string getLogString( std::string format = "[%t] *%l* %m \n", bool colors = true ) const;
00082 
00083     /**
00084      * \return log level of this entry.
00085      */
00086     LogLevel getLogLevel() const;
00087 
00088     /**
00089      * Returns the plain message of the entry.
00090      *
00091      * \return the message
00092      */
00093     std::string getMessage() const;
00094 
00095     /**
00096      * Returns the sender of the log.
00097      *
00098      * \return sender
00099      */
00100     std::string getSource() const;
00101 
00102     /**
00103      * Returns the formatted time string.
00104      *
00105      * \return time string
00106      */
00107     std::string getTime() const;
00108 
00109 protected:
00110 private:
00111     /**
00112      * The time the log message was received
00113      */
00114     std::string m_time;
00115 
00116     /**
00117      * The actual message
00118      */
00119     std::string m_message;
00120 
00121     /**
00122      * Log level
00123      */
00124     LogLevel m_level;
00125 
00126     /**
00127      * Source (e.g. module name) where this log message comes from.
00128      */
00129     std::string m_source;
00130 
00131     /**
00132      * Color used for error logs.
00133      *
00134      * \note it is mutable to allow en-/disabling the colors during getLogString.
00135      */
00136     mutable WTerminalColor m_errorColor;
00137 
00138     /**
00139      * Color used for info logs
00140      *
00141      * \note it is mutable to allow en-/disabling the colors during getLogString.
00142      */
00143     mutable WTerminalColor m_infoColor;
00144 
00145     /**
00146      * Color used for debug logs.
00147      *
00148      * \note it is mutable to allow en-/disabling the colors during getLogString.
00149      */
00150     mutable WTerminalColor m_debugColor;
00151 
00152     /**
00153      * Color used for warning logs.
00154      *
00155      * \note it is mutable to allow en-/disabling the colors during getLogString.
00156      */
00157     mutable WTerminalColor m_warningColor;
00158 
00159     /**
00160      * Color used for source field.
00161      *
00162      * \note it is mutable to allow en-/disabling the colors during getLogString.
00163      */
00164     mutable WTerminalColor m_sourceColor;
00165 
00166     /**
00167      * Color used for time.
00168      *
00169      * \note it is mutable to allow en-/disabling the colors during getLogString.
00170      */
00171     mutable WTerminalColor m_timeColor;
00172 
00173     /**
00174      * Color used for the message.
00175      *
00176      * \note it is mutable to allow en-/disabling the colors during getLogString.
00177      */
00178     mutable WTerminalColor m_messageColor;
00179 };
00180 
00181 #endif  // WLOGENTRY_H
00182 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends