1 /* 2 * PatternLayout.hh 3 * 4 * Copyright 2002, Bastiaan Bakker. All rights reserved. 5 * 6 * See the COPYING file for the terms of usage and distribution. 7 */ 8 9 #ifndef _LOG4CPP_PATTERNLAYOUT_HH 10 #define _LOG4CPP_PATTERNLAYOUT_HH 11 12 #include <log4cpp/Portability.hh> 13 #include <log4cpp/Layout.hh> 14 #include <log4cpp/Configurator.hh> 15 #include <vector> 16 #ifdef LOG4CPP_HAVE_SSTREAM 17 #include <sstream> 18 #endif 19 20 namespace log4cpp { 21 22 /** 23 * PatternLayout is a simple fixed format Layout implementation. 24 **/ 25 class LOG4CPP_EXPORT PatternLayout : public Layout { 26 public: 27 /** 28 The default conversion pattern 29 **/ 30 static const char* DEFAULT_CONVERSION_PATTERN; 31 32 /** 33 A conversion pattern equivalent to the SimpleLayout. 34 **/ 35 static const char* SIMPLE_CONVERSION_PATTERN; 36 37 /** 38 A conversion pattern equivalent to the BasicLayout. 39 **/ 40 static const char* BASIC_CONVERSION_PATTERN; 41 42 /** 43 A conversion pattern equivalent to the TTCCLayout. 44 Note: TTCCLayout is in log4j but not log4cpp. 45 **/ 46 static const char* TTCC_CONVERSION_PATTERN; 47 48 PatternLayout(); 49 virtual ~PatternLayout(); 50 51 // NOTE: All double percentage signs ('%%') followed by a character 52 // in the following comments should actually be a single char. 53 // The doubles are included so that doxygen will print them correctly. 54 /** 55 * Formats the LoggingEvent in the style set by 56 * the setConversionPattern call. By default, set 57 * to "%%m%%n" 58 **/ 59 virtual std::string format(const LoggingEvent& event); 60 61 /** 62 * Sets the format of log lines handled by this 63 * PatternLayout. By default, set to "%%m%%n".<br> 64 * Format characters are as follows:<br> 65 * <li><b>%%</b> - a single percent sign</li> 66 * <li><b>%%c</b> - the category</li> 67 * <li><b>%%d</b> - the date\n 68 * Date format: The date format character may be followed by a date format 69 * specifier enclosed between braces. For example, %%d{%%H:%%M:%%S,%%l} or %%d{%%d %%m %%Y %%H:%%M:%%S,%%l}. 70 * If no date format specifier is given then the following format is used: 71 * "Wed Jan 02 02:03:55 1980". The date format specifier admits the same syntax 72 * as the ANSI C function strftime, with 1 addition. The addition is the specifier 73 * %%l for milliseconds, padded with zeros to make 3 digits.</li> 74 * <li><b>%%m</b> - the message</li> 75 * <li><b>%%n</b> - the platform specific line separator</li> 76 * <li><b>%%p</b> - the priority</li> 77 * <li><b>%%r</b> - milliseconds since this layout was created.</li> 78 * <li><b>%%R</b> - seconds since Jan 1, 1970</li> 79 * <li><b>%%u</b> - clock ticks since process start</li> 80 * <li><b>%%x</b> - the NDC</li> 81 * @param conversionPattern the conversion pattern 82 * @exception ConfigureFailure if the pattern is invalid 83 **/ 84 virtual void setConversionPattern(const std::string& conversionPattern); 85 86 virtual std::string getConversionPattern() const; 87 88 virtual void clearConversionPattern(); 89 90 class LOG4CPP_EXPORT PatternComponent { 91 public: ~PatternComponent()92 inline virtual ~PatternComponent() {}; 93 virtual void append(std::ostringstream& out, const LoggingEvent& event) = 0; 94 }; 95 96 private: 97 typedef std::vector<PatternComponent*> ComponentVector; 98 ComponentVector _components; 99 100 std::string _conversionPattern; 101 }; 102 } 103 104 #endif // _LOG4CPP_PATTERNLAYOUT_HH 105