summaryrefslogtreecommitdiff
path: root/client/Logger.cpp
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-10-23 04:10:55 +0300
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-10-23 04:10:55 +0300
commit21ad7eac963bc329395fa893300fb5c8f721fd77 (patch)
tree10dda6e6170071332aab490faeeb599f10ff6e03 /client/Logger.cpp
parent3eef0376635624c354a5e1b8a2680b74eb23a423 (diff)
Logging facility, Config class, tray icon, custom QApplication subclass
Diffstat (limited to 'client/Logger.cpp')
-rw-r--r--client/Logger.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/client/Logger.cpp b/client/Logger.cpp
new file mode 100644
index 0000000..4cbb8aa
--- /dev/null
+++ b/client/Logger.cpp
@@ -0,0 +1,98 @@
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <time.h>
+#include "Logger.h"
+
+
+LogLevelType Logger::LogLevel = TraceLevel;
+
+#ifdef DEBUG
+
+void Logger::Trace(char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(TraceLevel, msgfmt, args);
+}
+
+void Logger::Debug(char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(DebugLevel, msgfmt, args);
+}
+
+void Logger::Info(char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(InfoLevel, msgfmt, args);
+}
+
+void Logger::Warn(char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(WarnLevel, msgfmt, args);
+}
+
+void Logger::Error(char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(ErrorLevel, msgfmt, args);
+}
+
+void Logger::Fatal(char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(FatalLevel, msgfmt, args);
+}
+
+void Logger::Log(LogLevelType logLevel, char* msgfmt, ...)
+{
+ va_list args;
+ va_start(args, msgfmt);
+ Logger::Log(logLevel, msgfmt, args);
+}
+
+void Logger::Log(LogLevelType logLevel, char* msgfmt, 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);
+
+ char log_level_str[6] = {0};
+ switch (logLevel)
+ {
+ default:
+ case TraceLevel:
+ strcpy(log_level_str, "Trace");
+ break;
+ case DebugLevel:
+ strcpy(log_level_str, "Debug");
+ break;
+ case InfoLevel:
+ strcpy(log_level_str, "Info");
+ break;
+ case WarnLevel:
+ strcpy(log_level_str, "Warn");
+ break;
+ case ErrorLevel:
+ strcpy(log_level_str, "Error");
+ break;
+ case FatalLevel:
+ strcpy(log_level_str, "Fatal");
+ break;
+ }
+
+ char *newfmt = new char[strlen(msgfmt) + 24];
+ sprintf(newfmt, "[%s] %-6s: %s", time_str, log_level_str, msgfmt);
+ vfprintf(stderr, newfmt, args);
+}
+
+#endif \ No newline at end of file