diff options
Diffstat (limited to 'client/Logger.cpp')
-rw-r--r-- | client/Logger.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/client/Logger.cpp b/client/Logger.cpp index 67c4907..74449ae 100644 --- a/client/Logger.cpp +++ b/client/Logger.cpp @@ -8,9 +8,19 @@ using std::string; LogLevelType Logger::LogLevel = TraceLevel; +FILE* Logger::logFile = NULL; + #ifdef DEBUG +void Logger::InitLogFile() +{ + if (logFile == NULL) + { + logFile = fopen("client.log", "a"); + } +} + void Logger::Trace(string msg, ...) { va_list args; @@ -58,6 +68,7 @@ void Logger::Log(LogLevelType logLevel, string msg, ...) va_list args; va_start(args, msg); Logger::Log(logLevel, msg, args); + va_end(args); } void Logger::Log(LogLevelType logLevel, string msg, va_list args) @@ -68,6 +79,7 @@ void Logger::Log(LogLevelType logLevel, string msg, va_list args) strftime(time_str, 10, "%H:%M:%S", lctime); string log_level_str; + switch (logLevel) { default: @@ -91,9 +103,16 @@ void Logger::Log(LogLevelType logLevel, string msg, va_list args) break; } + char logstr[1024] = {0}; char *newfmt = new char[msg.size() + 24]; sprintf(newfmt, "[%s] %-6s: %s", time_str, log_level_str.c_str(), msg.c_str()); - vfprintf(stderr, newfmt, args); + vsprintf(logstr, newfmt, args); + fprintf(stderr, logstr); + if (logFile != NULL) + { + fprintf(logFile, logstr); + } + delete [] newfmt; } #endif
\ No newline at end of file |