diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-10 19:13:22 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-10 19:13:22 -0400 |
commit | 33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea (patch) | |
tree | b1db5d3e83ccd8c5219d5db12b01bc3d152b79d1 /src/logger.cpp | |
parent | 3b3c3ca4ed98c8d1e884f6c9f8f63d7b7c76e37b (diff) | |
download | lingo-ap-tracker-33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea.tar.gz lingo-ap-tracker-33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea.tar.bz2 lingo-ap-tracker-33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea.zip |
Go back to old logging system
Brought in libfmt to handle string formatting and replace a bunch of ostringstream uses.
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/logger.cpp b/src/logger.cpp new file mode 100644 index 0000000..09fc331 --- /dev/null +++ b/src/logger.cpp | |||
@@ -0,0 +1,32 @@ | |||
1 | #include "logger.h" | ||
2 | |||
3 | #include <chrono> | ||
4 | #include <fstream> | ||
5 | #include <mutex> | ||
6 | |||
7 | #include "global.h" | ||
8 | |||
9 | namespace { | ||
10 | |||
11 | class Logger { | ||
12 | public: | ||
13 | Logger() : logfile_(GetAbsolutePath("debug.log")) {} | ||
14 | |||
15 | void LogLine(const std::string& text) { | ||
16 | std::lock_guard guard(file_mutex_); | ||
17 | logfile_ << "[" << std::chrono::system_clock::now() << "] " << text | ||
18 | << std::endl; | ||
19 | logfile_.flush(); | ||
20 | } | ||
21 | |||
22 | private: | ||
23 | std::ofstream logfile_; | ||
24 | std::mutex file_mutex_; | ||
25 | }; | ||
26 | |||
27 | } // namespace | ||
28 | |||
29 | void TrackerLog(std::string text) { | ||
30 | static Logger* instance = new Logger(); | ||
31 | instance->LogLine(text); | ||
32 | } | ||