From 3f5580d66ef6c237c8de7f9b8a71fa41d4cf3169 Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Sun, 4 Dec 2011 01:08:40 +0200 Subject: FIX links to Logger in updater app --- updater/Logger.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++- updater/Logger.h | 56 +++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 2 deletions(-) mode change 120000 => 100644 updater/Logger.cpp mode change 120000 => 100644 updater/Logger.h diff --git a/updater/Logger.cpp b/updater/Logger.cpp deleted file mode 120000 index d1ee7ee..0000000 --- a/updater/Logger.cpp +++ /dev/null @@ -1 +0,0 @@ -../client/Logger.cpp \ No newline at end of file diff --git a/updater/Logger.cpp b/updater/Logger.cpp new file mode 100644 index 0000000..67c4907 --- /dev/null +++ b/updater/Logger.cpp @@ -0,0 +1,99 @@ + +#include +#include +#include +#include +#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 diff --git a/updater/Logger.h b/updater/Logger.h deleted file mode 120000 index 03aacbf..0000000 --- a/updater/Logger.h +++ /dev/null @@ -1 +0,0 @@ -../client/Logger.h \ No newline at end of file diff --git a/updater/Logger.h b/updater/Logger.h new file mode 100644 index 0000000..cecd454 --- /dev/null +++ b/updater/Logger.h @@ -0,0 +1,55 @@ + + +#ifndef LOG_H +#define LOG_H + +enum LogLevelType +{ + TraceLevel = 0, + DebugLevel, + InfoLevel, + WarnLevel, + ErrorLevel, + FatalLevel +}; + + +#ifdef DEBUG + +#include + +class Logger +{ +public: + static LogLevelType LogLevel; + + static void Trace(std::string msg, ...); + static void Debug(std::string msg, ...); + static void Info(std::string msg, ...); + static void Warn(std::string msg, ...); + static void Error(std::string msg, ...); + static void Fatal(std::string msg, ...); + static void Log(LogLevelType logLevel, std::string msg, ...); +private: + static void Log(LogLevelType logLevel, std::string msg, va_list arsg); +}; + +#else + +class Logger +{ +public: + static LogLevelType LogLevel; + + static void Trace(std::string msg, ...) {} + static void Debug(std::string msg, ...) {} + static void Info(std::string msg, ...) {} + static void Warn(std::string msg, ...) {} + static void Error(std::string msg, ...) {} + static void Fatal(std::string msg, ...) {} + static void Log(LogLevelType logLevel, std::string msg, ...) {} +}; + +#endif + +#endif \ No newline at end of file -- cgit v1.2.3