diff options
Diffstat (limited to 'src/LoggerListeners.cpp')
-rw-r--r-- | src/LoggerListeners.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp index 5c7097956..91964c57e 100644 --- a/src/LoggerListeners.cpp +++ b/src/LoggerListeners.cpp @@ -3,6 +3,8 @@ #include "LoggerListeners.h" +#include <chrono> + #if defined(_WIN32) #include <io.h> // Needed for _isatty(), not available on Linux #include <time.h> @@ -236,8 +238,26 @@ public: -cLogger::cListener * MakeConsoleListener(void) +// Listener for when stdout is closed, i.e. When running as a daemon. +class cNullConsoleListener + : public cLogger::cListener { + virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override + { + } +}; + + + + + +cLogger::cListener * MakeConsoleListener(bool a_IsService) +{ + if (a_IsService) + { + return new cNullConsoleListener; + } + #ifdef _WIN32 // See whether we are writing to a console the default console attrib: bool ShouldColorOutput = (_isatty(_fileno(stdin)) != 0); @@ -279,9 +299,15 @@ cLogger::cListener * MakeConsoleListener(void) cFileListener::cFileListener(void) { cFile::CreateFolder(FILE_IO_PREFIX + AString("logs")); - AString FileName; - FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", (int)time(nullptr)); - m_File.Open(FileName, cFile::fmAppend); + m_File.Open( + FILE_IO_PREFIX + Printf( + "logs/LOG_%d.txt", + std::chrono::duration_cast<std::chrono::duration<int, std::ratio<1>>>( + std::chrono::system_clock::now().time_since_epoch() + ).count() + ), + cFile::fmAppend + ); } @@ -300,7 +326,7 @@ void cFileListener::Log(AString a_Message, cLogger::eLogLevel a_LogLevel) } case cLogger::llInfo: { - LogLevelPrefix = "info "; + LogLevelPrefix = "Info "; break; } case cLogger::llWarning: |