PixelLightAPI  .
LogFormatter.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: LogFormatter.h                                 *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_LOGFORMATTER_H__
00024 #define __PLCORE_LOGFORMATTER_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 class File;
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Classes                                               ]
00048 //[-------------------------------------------------------]
00049 /**
00050 *  @brief
00051 *    Abstract log formatter class
00052 *
00053 *  @remarks
00054 *    Defines the interface for a formatter of the log. With this interface you can
00055 *    implement a formatter which will format the output of the log.
00056 *
00057 *  @note
00058 *    - Implementation of the strategy design pattern, this class is the strategy of the context "Log"
00059 */
00060 class LogFormatter {
00061 
00062 
00063     //[-------------------------------------------------------]
00064     //[ Friends                                               ]
00065     //[-------------------------------------------------------]
00066     friend class Log;
00067 
00068 
00069     //[-------------------------------------------------------]
00070     //[ Public functions                                      ]
00071     //[-------------------------------------------------------]
00072     public:
00073         /**
00074         *  @brief
00075         *    To activate/deactivate that the [LogLevel] prefix should be shown
00076         *    in the log before each log message e.g. [Info] info log level message
00077         *
00078         *  @param[in] bShow
00079         *    Should the prefix be shown?
00080         *
00081         *  @remarks
00082         *    This option can be ignored in an log formatter implementation if the log formatter
00083         *    wants that the prefix is always shown.
00084         */
00085         inline void ShowLogLevelPrefix(bool bShow = true);
00086 
00087 
00088     //[-------------------------------------------------------]
00089     //[ Protected functions                                   ]
00090     //[-------------------------------------------------------]
00091     protected:
00092         /**
00093         *  @brief
00094         *    Default constructor
00095         */
00096         PLCORE_API LogFormatter();
00097 
00098         /**
00099         *  @brief
00100         *    Destructor
00101         */
00102         PLCORE_API virtual ~LogFormatter();
00103 
00104         /**
00105         *  @brief
00106         *    Helper function to open the log as a file
00107         *
00108         *  @param[in] sFilename
00109         *    The log's filename
00110         *  @param[in] nStringFormat
00111         *    String encoding format to use when dealing with string functions (not supported by all file implementations)
00112         *
00113         *  @return
00114         *    A pointer to the file object if all went fine, a null pointer on error
00115         */
00116         PLCORE_API File *OpenFile(const String &sFilename, String::EFormat nStringFormat);
00117 
00118 
00119     //[-------------------------------------------------------]
00120     //[ Protected virtual LogFormatter functions              ]
00121     //[-------------------------------------------------------]
00122     protected:
00123         /**
00124         *  @brief
00125         *    Open the log file
00126         *
00127         *  @param[in] sFilename
00128         *    The log's filename
00129         *
00130         *  @return
00131         *    'true' if all went fine, else 'false'
00132         */
00133         virtual bool Open(const String &sFilename) = 0;
00134 
00135         /**
00136         *  @brief
00137         *    Close the log
00138         *
00139         *  @return
00140         *    'true' if all went fine, else 'false'
00141         */
00142         virtual bool Close() = 0;
00143 
00144         /**
00145         *  @brief
00146         *    Writes an Formated string to the log file
00147         *
00148         *  @param[in] nLogLevel
00149         *    The log level to which the log message belongs
00150         *  @param[in] sText
00151         *    Text which should be written into the log
00152         *
00153         *  @return
00154         *    'true' if all went fine, else 'false'
00155         */
00156         virtual bool Output(uint8 nLogLevel, const String &sText) = 0;
00157 
00158         /**
00159         *  @brief
00160         *    Flushes the output buffer to the file on disk
00161         *
00162         *  @return
00163         *    'true' if all went fine, else 'false'
00164         */
00165         virtual bool Flush() = 0;
00166 
00167 
00168     //[-------------------------------------------------------]
00169     //[ Protected data                                        ]
00170     //[-------------------------------------------------------]
00171     protected:
00172         File *m_pFile;                  /**< Pointer to the log file, can be a null pointer */
00173         bool  m_bShowLogLevelPrefix;    /**< Indicates if the [LogLevel] prefix should be shown */
00174 
00175 
00176     //[-------------------------------------------------------]
00177     //[ Private functions                                     ]
00178     //[-------------------------------------------------------]
00179     private:
00180         /**
00181         *  @brief
00182         *    Copy constructor
00183         *
00184         *  @param[in] cSource
00185         *    Source to copy from
00186         */
00187         LogFormatter(const LogFormatter &cSource);
00188 
00189         /**
00190         *  @brief
00191         *    Copy operator
00192         *
00193         *  @param[in] cSource
00194         *    Source to copy from
00195         *
00196         *  @return
00197         *    Reference to this instance
00198         */
00199         LogFormatter &operator =(const LogFormatter &cSource);
00200 
00201 
00202 };
00203 
00204 
00205 //[-------------------------------------------------------]
00206 //[ Namespace                                             ]
00207 //[-------------------------------------------------------]
00208 } // PLCore
00209 
00210 
00211 //[-------------------------------------------------------]
00212 //[ Implementation                                        ]
00213 //[-------------------------------------------------------]
00214 #include "PLCore/Log/LogFormatter.inl"
00215 
00216 
00217 #endif // __PLCORE_LOGFORMATTER_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported