CLogFileTarget.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. ~CLogFileTarget();
  26. // Accessors
  27. const CLogFormatter & getFormatter() const;
  28. void setFormatter(const CLogFormatter & formatter);
  29. // Methods
  30. /**
  31. * Writes a log record to the log file.
  32. *
  33. * @param record The log record to write.
  34. */
  35. void write(const LogRecord & record);
  36. private:
  37. // Data members
  38. std::ofstream file;
  39. CLogFormatter formatter;
  40. mutable boost::mutex mx;
  41. };