PatternLayout.hh 3.6 KB

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