PatternLayout.hh 3.6 KB

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