| 18 | } |
| 19 | |
| 20 | void LogFile::print(Level level, std::string_view message) |
| 21 | { |
| 22 | if (!passesLevelFilter(level)) |
| 23 | { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | if (!_file.is_open()) |
| 28 | { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | std::string timestamp; |
| 33 | if (getWriteTimestamps()) |
| 34 | { |
| 35 | auto now = std::chrono::system_clock::now(); |
| 36 | timestamp = fmt::format("[{:%Y-%m-%d %H:%M:%S}] ", std::chrono::floor<std::chrono::seconds>(now)); |
| 37 | } |
| 38 | |
| 39 | const int intendSize = getIntendSize(); |
| 40 | |
| 41 | fmt::print(_file, "{}{}{:<{}}\n", timestamp, getLevelPrefix(level), message, intendSize); |
| 42 | |
| 43 | // Ensure we are not loosing anything because of buffering in case of a crash. |
| 44 | _file.flush(); |
| 45 | } |
| 46 | } |
no test coverage detected