diff options
author | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-12-04 01:08:40 +0200 |
---|---|---|
committer | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-12-04 01:08:40 +0200 |
commit | 3f5580d66ef6c237c8de7f9b8a71fa41d4cf3169 (patch) | |
tree | 13451a98dec007be2280316b2f3b017c2e0e3d41 /updater/Logger.cpp | |
parent | 5c789cf06a29cbe9ce628b550b9cd7c93552cf26 (diff) |
FIX links to Logger in updater app
Diffstat (limited to 'updater/Logger.cpp')
-rw-r--r--[l---------] | updater/Logger.cpp | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/updater/Logger.cpp b/updater/Logger.cpp index d1ee7ee..67c4907 120000..100644 --- a/updater/Logger.cpp +++ b/updater/Logger.cpp @@ -1 +1,99 @@ -../client/Logger.cpp
\ No newline at end of file + +#include <stdio.h> +#include <stdarg.h> +#include <string> +#include <time.h> +#include "Logger.h" + +using std::string; + +LogLevelType Logger::LogLevel = TraceLevel; + +#ifdef DEBUG + +void Logger::Trace(string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(TraceLevel, msg, args); +} + +void Logger::Debug(string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(DebugLevel, msg, args); +} + +void Logger::Info(string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(InfoLevel, msg, args); +} + +void Logger::Warn(string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(WarnLevel, msg, args); +} + +void Logger::Error(string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(ErrorLevel, msg, args); +} + +void Logger::Fatal(string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(FatalLevel, msg, args); +} + +void Logger::Log(LogLevelType logLevel, string msg, ...) +{ + va_list args; + va_start(args, msg); + Logger::Log(logLevel, msg, args); +} + +void Logger::Log(LogLevelType logLevel, string msg, va_list args) +{ + time_t rawtime = time(NULL); + struct tm *lctime = localtime(&rawtime); + char time_str[10] = {0}; + strftime(time_str, 10, "%H:%M:%S", lctime); + + string log_level_str; + switch (logLevel) + { + default: + case TraceLevel: + log_level_str = "Trace"; + break; + case DebugLevel: + log_level_str = "Debug"; + break; + case InfoLevel: + log_level_str = "Info"; + break; + case WarnLevel: + log_level_str = "Warn"; + break; + case ErrorLevel: + log_level_str = "Error"; + break; + case FatalLevel: + log_level_str = "Fatal"; + break; + } + + 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); +} + +#endif
\ No newline at end of file |