PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: LogFormatterHtml.h * 00003 * 00004 * Copyright (C) 2002-2011 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_HTML_H__ 00024 #define __PLCORE_LOGFORMATTER_HTML_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Container/HashMap.h" 00032 #include "PLCore/Log/LogFormatter.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * HTML log formatter 00047 * 00048 * @note 00049 * - Header: This text/HTML codes are written after the <body> tags 00050 * - Background: The background is set in the <body> tag 00051 * - Background: You must also give the option name (e.g. bgcolor=<color in HTML notation>) 00052 * - DefaultTextColor: The color must be in HTML notation. Either the color name(e.g. red) or the RGB values in hexadecimal. (e.g. #FF0000) 00053 * - Implementation of the strategy design pattern, this class a concrete strategy of the strategy "LogFormatter" of the context "Log" 00054 */ 00055 class LogFormatterHtml : public LogFormatter { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Public functions ] 00060 //[-------------------------------------------------------] 00061 public: 00062 /** 00063 * @brief 00064 * Default constructor 00065 */ 00066 PLCORE_API LogFormatterHtml(); 00067 00068 /** 00069 * @brief 00070 * Destructor 00071 */ 00072 PLCORE_API virtual ~LogFormatterHtml(); 00073 00074 /** 00075 * @brief 00076 * Sets the text format string for the specified log level 00077 * 00078 * @param[in] nLogLevel 00079 * The log level for which the text format should be set 00080 * @param[in] sFormat 00081 * The text format string 00082 * 00083 * @note 00084 * - You can use every HTML tags for the formating 00085 * - The syntax is as follows: <format-tags>|<end format-tags> 00086 * - The '|' gets replaced with the log message 00087 */ 00088 PLCORE_API void SetTextFormat(uint8 nLogLevel, const String &sFormat); 00089 00090 /** 00091 * @brief 00092 * This text gets printed to the log when the log is opened 00093 * 00094 * @param[in] sHeader 00095 * Header text 00096 * 00097 * @note 00098 * This text/HTML codes are written after the <body> tags 00099 */ 00100 inline void SetHeader(const String &sHeader = ""); 00101 00102 /** 00103 * @brief 00104 * Sets the title of the log 00105 * 00106 * @param[in] sTitle 00107 * The log's title 00108 */ 00109 inline void SetTitle(const String &sTitle = "PL-Log"); 00110 00111 /** 00112 * @brief 00113 * Sets the background for the HTML document either a color or a image 00114 * 00115 * @param[in] sBackground 00116 * The HTML background 00117 * 00118 * @note 00119 * - The background is set in the <body> tag 00120 * - You must also give the option name (e.g. bgcolor=<color in HTML notation>) 00121 */ 00122 inline void SetBackground(const String &sBackground = ""); 00123 00124 /** 00125 * @brief 00126 * Sets the default text color 00127 * 00128 * @param[in] sColor 00129 * The text color 00130 * 00131 * @remarks 00132 * The color must be in HTML notation. Either the color name(e.g. red) or the 00133 * RGB values in hexadecimal. (e.g. #FF0000) 00134 */ 00135 inline void SetDefaultTextColor(const String &sColor = "black"); 00136 00137 /** 00138 * @brief 00139 * Sets the default text format string 00140 * 00141 * @param[in] sFormat 00142 * The text format string 00143 * 00144 * @note 00145 * - See SetTextFormat() 00146 */ 00147 inline void SetDefaultTextFormat(const String &sFormat = "|<br>"); 00148 00149 /** 00150 * @brief 00151 * This text gets printed to the log before the log gets closed 00152 * 00153 * @param[in] sFooter 00154 * Footer text 00155 */ 00156 inline void SetFooter(const String &sFooter = ""); 00157 00158 00159 //[-------------------------------------------------------] 00160 //[ Private functions ] 00161 //[-------------------------------------------------------] 00162 private: 00163 /** 00164 * @brief 00165 * Copy constructor 00166 * 00167 * @param[in] cSource 00168 * Source to copy from 00169 */ 00170 LogFormatterHtml(const LogFormatterHtml &cSource); 00171 00172 /** 00173 * @brief 00174 * Copy operator 00175 * 00176 * @param[in] cSource 00177 * Source to copy from 00178 * 00179 * @return 00180 * Reference to this instance 00181 */ 00182 LogFormatterHtml &operator =(const LogFormatterHtml &cSource); 00183 00184 /** 00185 * @brief 00186 * Returns the HTML formated text the given log level 00187 * 00188 * @param[in] nLogLevel 00189 * Log level for which formated text should be returned 00190 * 00191 * @param[in] sText 00192 * The log text which should be surrounded with the HTML text format-tags 00193 * 00194 * @return 00195 * HTML formated text 00196 */ 00197 String GetHtmlFormatedText(uint8 nLogLevel, const String &sText) const; 00198 00199 00200 //[-------------------------------------------------------] 00201 //[ Private virtual LogFormatter functions ] 00202 //[-------------------------------------------------------] 00203 private: 00204 virtual bool Open(const String &sFilename) override; 00205 virtual bool Close() override; 00206 virtual bool Output(uint8 nLogLevel, const String &sText) override; 00207 virtual bool Flush() override; 00208 00209 00210 //[-------------------------------------------------------] 00211 //[ Private data ] 00212 //[-------------------------------------------------------] 00213 private: 00214 String m_sHeader; /**< Holds the header text */ 00215 String m_sTitle; /**< Holds the title text */ 00216 String m_sBackground; /**< Holds the background */ 00217 String m_sDefaultTextColor; /**< Holds the default text color */ 00218 String m_sDefaultTextFormat; /**< Holds the default text format */ 00219 String m_sFooter; /**< Holds the footer text */ 00220 HashMap<uint8, String> *m_mapTextFormats; /**< Holds the text format for each log level */ 00221 00222 00223 }; 00224 00225 00226 //[-------------------------------------------------------] 00227 //[ Namespace ] 00228 //[-------------------------------------------------------] 00229 } // PLCore 00230 00231 00232 //[-------------------------------------------------------] 00233 //[ Implementation ] 00234 //[-------------------------------------------------------] 00235 #include "PLCore/Log/LogFormatterHtml.inl" 00236 00237 00238 #endif // __PLCORE_LOGFORMATTER_HTML_H__
|