CLogFormatter.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * CLogFormatter.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. struct LogRecord;
  12. /**
  13. * The log formatter formats log records.
  14. *
  15. * There are several pattern characters which can be used to format a log record:
  16. * %d = Date/Time
  17. * %l = Log level
  18. * %n = Logger name
  19. * %t = Thread ID
  20. * %m = Message
  21. */
  22. class DLL_LINKAGE CLogFormatter
  23. {
  24. public:
  25. /**
  26. * Default constructor.
  27. */
  28. CLogFormatter();
  29. /**
  30. * Constructor.
  31. *
  32. * @param pattern The pattern to format the log record with.
  33. */
  34. CLogFormatter(const std::string & pattern);
  35. /**
  36. * Formats a log record.
  37. *
  38. * @param record The log record to format.
  39. * @return the formatted log record as a string
  40. */
  41. std::string format(const LogRecord & record) const;
  42. /**
  43. * Sets the pattern.
  44. *
  45. * @param pattern The pattern string which describes how to format the log record.
  46. */
  47. void setPattern(const std::string & pattern);
  48. /**
  49. * Gets the pattern.
  50. *
  51. * @return the pattern string which describes how to format the log record
  52. */
  53. const std::string & getPattern() const;
  54. private:
  55. /** The pattern string which describes how to format the log record. */
  56. std::string pattern;
  57. };