diff options
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/logger.cpp b/src/logger.cpp new file mode 100644 index 0000000..ccb721a --- /dev/null +++ b/src/logger.cpp | |||
@@ -0,0 +1,30 @@ | |||
1 | #include "logger.h" | ||
2 | |||
3 | #include <chrono> | ||
4 | #include <fstream> | ||
5 | #include <mutex> | ||
6 | |||
7 | namespace { | ||
8 | |||
9 | class Logger { | ||
10 | public: | ||
11 | Logger() : logfile_("debug.log") {} | ||
12 | |||
13 | void LogLine(const std::string& text) { | ||
14 | std::lock_guard guard(file_mutex_); | ||
15 | logfile_ << "[" << std::chrono::system_clock::now() << "] " << text | ||
16 | << std::endl; | ||
17 | logfile_.flush(); | ||
18 | } | ||
19 | |||
20 | private: | ||
21 | std::ofstream logfile_; | ||
22 | std::mutex file_mutex_; | ||
23 | }; | ||
24 | |||
25 | } // namespace | ||
26 | |||
27 | void TrackerLog(const std::string& text) { | ||
28 | static Logger* instance = new Logger(); | ||
29 | instance->LogLine(text); | ||
30 | } | ||