CLogFileTarget.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * CLogFileTarget.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. #include "ILogTarget.h"
  12. #include "CLogFormatter.h"
  13. /**
  14. * The log file target is a logging target which writes messages to a log file.
  15. */
  16. class DLL_LINKAGE CLogFileTarget : public ILogTarget
  17. {
  18. public:
  19. /**
  20. * Constructor.
  21. *
  22. * @param filePath The file path of the log file.
  23. */
  24. explicit CLogFileTarget(const std::string & filePath);
  25. /**
  26. * Destructor.
  27. */
  28. ~CLogFileTarget();
  29. /**
  30. * Writes a log record.
  31. *
  32. * @param record The log record to write.
  33. */
  34. void write(const LogRecord & record);
  35. /**
  36. * Gets the log formatter.
  37. *
  38. * @return The log formatter.
  39. */
  40. const CLogFormatter & getFormatter() const;
  41. /**
  42. * Sets the log formatter.
  43. *
  44. * @param formatter The log formatter.
  45. */
  46. void setFormatter(const CLogFormatter & formatter);
  47. private:
  48. /** The output file stream. */
  49. std::ofstream file;
  50. /** The log formatter to log messages. */
  51. CLogFormatter formatter;
  52. /** The shared mutex for providing synchronous thread-safe access to the log file target. */
  53. mutable boost::mutex mx;
  54. };