summaryrefslogtreecommitdiffstats
path: root/client/debug.h
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-06-28 21:27:10 +0200
committerAlexander Larsson <alexl@redhat.com>2010-06-28 21:54:53 +0200
commit7e26ff3c2631a232ea3bc20ed842c47cc5db7526 (patch)
treee1edcffaa20237d7eb12ab77b73f53e9a983d0ff /client/debug.h
parentb08b80d13ff8a6822364e792391473dc53913dca (diff)
downloadspice-7e26ff3c2631a232ea3bc20ed842c47cc5db7526.tar.gz
spice-7e26ff3c2631a232ea3bc20ed842c47cc5db7526.tar.xz
spice-7e26ff3c2631a232ea3bc20ed842c47cc5db7526.zip
Replace log4cpp with custom log function
Also prints a simpler error to stderr for WARN or above so that we print something on the commandline if something go wrong.
Diffstat (limited to 'client/debug.h')
-rw-r--r--client/debug.h56
1 files changed, 20 insertions, 36 deletions
diff --git a/client/debug.h b/client/debug.h
index 63a6138b..c72ccd88 100644
--- a/client/debug.h
+++ b/client/debug.h
@@ -21,9 +21,6 @@
#include <stdlib.h>
#include <sstream>
-#include <log4cpp/Category.hh>
-#include <log4cpp/convenience.h>
-
#include "platform.h"
#ifdef WIN32
@@ -51,49 +48,36 @@
#endif
-#ifdef __GNUC__
-static inline std::string pretty_func_to_func_name(const std::string& f_name)
-{
- std::string name(f_name);
- std::string::size_type end_pos = f_name.find('(');
- if (end_pos == std::string::npos) {
- return f_name;
- }
- std::string::size_type start = f_name.rfind(' ', end_pos);
- if (start == std::string::npos) {
- return f_name;
- }
- end_pos -= ++start;
- return name.substr(start, end_pos);
-}
+enum {
+ LOG_DEBUG,
+ LOG_INFO,
+ LOG_WARN,
+ LOG_ERROR,
+ LOG_FATAL
+};
+
+void spice_log(unsigned int type, const char *function, const char *format, ...);
+void spice_log_cleanup(void);
-#define FUNC_NAME pretty_func_to_func_name(__PRETTY_FUNCTION__).c_str()
+#ifdef __GNUC__
+#define SPICE_FUNC_NAME __PRETTY_FUNCTION__
#else
-#define FUNC_NAME __FUNCTION__
+#define SPICE_FUNC_NAME __FUNCTION__
#endif
-#define LOGGER_SECTION(section) LOG4CPP_LOGGER(section)
-
-LOG4CPP_LOGGER("spice")
-
-#define LOG(type, format, ...) { \
- std::string log_message; \
- string_printf(log_message, "[%llu:%llu] %s: " format, Platform::get_process_id(), \
- Platform::get_thread_id(), FUNC_NAME, ## __VA_ARGS__); \
- LOG4CPP_##type(logger, log_message.c_str()); \
-}
+#define LOG(type, format, ...) spice_log(type, SPICE_FUNC_NAME, format, ## __VA_ARGS__)
-#define LOG_INFO(format, ...) LOG(INFO, format, ## __VA_ARGS__)
-#define LOG_WARN(format, ...) LOG(WARN, format, ## __VA_ARGS__)
-#define LOG_ERROR(format, ...) LOG(ERROR, format, ## __VA_ARGS__)
+#define LOG_INFO(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
+#define LOG_WARN(format, ...) LOG(LOG_WARN, format, ## __VA_ARGS__)
+#define LOG_ERROR(format, ...) LOG(LOG_ERROR, format, ## __VA_ARGS__)
#define PANIC(format, ...) { \
- LOG(FATAL, format, ## __VA_ARGS__); \
+ LOG(LOG_FATAL, format, ## __VA_ARGS__); \
ON_PANIC(); \
}
#define PANIC_ON(x) if ((x)) { \
- LOG(FATAL, "%s panic %s\n", __FUNCTION__, #x); \
+ LOG(LOG_FATAL, "%s panic %s\n", __FUNCTION__, #x); \
ON_PANIC(); \
}
@@ -101,7 +85,7 @@ LOG4CPP_LOGGER("spice")
#define DBG(level, format, ...) { \
if (level <= DBGLEVEL) { \
- LOG(DEBUG, format, ## __VA_ARGS__); \
+ LOG(LOG_DEBUG, format, ## __VA_ARGS__); \
} \
}