diff options
author | Alexander Larsson <alexl@redhat.com> | 2010-06-28 21:27:10 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2010-06-28 21:54:53 +0200 |
commit | 7e26ff3c2631a232ea3bc20ed842c47cc5db7526 (patch) | |
tree | e1edcffaa20237d7eb12ab77b73f53e9a983d0ff /client | |
parent | b08b80d13ff8a6822364e792391473dc53913dca (diff) | |
download | spice-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')
-rw-r--r-- | client/application.cpp | 91 | ||||
-rw-r--r-- | client/debug.h | 56 | ||||
-rw-r--r-- | client/gui/gui.h | 4 | ||||
-rw-r--r-- | client/windows/main.cpp | 2 | ||||
-rw-r--r-- | client/windows/platform.cpp | 1 | ||||
-rw-r--r-- | client/windows/redc.vcproj | 8 | ||||
-rw-r--r-- | client/x11/Makefile.am | 2 | ||||
-rw-r--r-- | client/x11/main.cpp | 2 | ||||
-rw-r--r-- | client/x11/platform.cpp | 1 |
9 files changed, 102 insertions, 65 deletions
diff --git a/client/application.cpp b/client/application.cpp index f32943e8..8d2c34fe 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -43,10 +43,9 @@ #include "tunnel_channel.h" #include "rect.h" #include "gui/gui.h" - -#include <log4cpp/BasicConfigurator.hh> -#include <log4cpp/FileAppender.hh> -#include <log4cpp/RollingFileAppender.hh> +#include <stdarg.h> +#include <stdio.h> +#include <time.h> #define STICKY_KEY_PIXMAP ALT_IMAGE_RES_ID #define STICKY_KEY_TIMEOUT 750 @@ -2096,30 +2095,84 @@ bool Application::process_cmd_line(int argc, char** argv) return true; } +#ifdef RED_DEBUG +static unsigned int log_level = LOG_DEBUG; +#else +static unsigned int log_level = LOG_INFO; +#endif + +static FILE *log_file = NULL; + +void spice_log_cleanup(void) +{ + if (log_file) { + fclose(log_file); + log_file = NULL; + } +} + +static inline std::string function_to_func_name(const std::string& f_name) +{ +#ifdef __GNUC__ + 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 name.substr(0, end_pos); + } + end_pos -= ++start; + return name.substr(start, end_pos); +#else + return f_name; +#endif +} + +void spice_log(unsigned int type, const char *function, const char *format, ...) +{ + std::string formated_message; + va_list ap; + const char *type_as_char[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; + const char *type_as_nice_char[] = { "Debug", "Info", "Warning", "Error", "Fatal error" }; + + if (type < log_level) { + return; + } + + assert(type <= LOG_FATAL); + + va_start(ap, format); + string_vprintf(formated_message, format, ap); + va_end(ap); + + if (type >= log_level && log_file != NULL) { + fprintf(log_file, "%ld %s [%llu:%llu] %s: %s\n", (long)time(NULL), type_as_char[type], + (long long int)Platform::get_process_id(), (long long int)Platform::get_thread_id(), + function_to_func_name(function).c_str(), + formated_message.c_str()); + fflush(log_file); + } + + if (type >= LOG_WARN) { + fprintf(stderr, "%s: %s\n", type_as_nice_char[type], formated_message.c_str()); + } +} + void Application::init_logger() { std::string log_file_name; + Platform::get_app_data_dir(log_file_name, app_name); Platform::path_append(log_file_name, "spicec.log"); - int fd = ::open(log_file_name.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0644); + log_file = ::fopen(log_file_name.c_str(), "a"); - if (fd == -1) { - log4cpp::BasicConfigurator::configure(); + if (log_file == NULL) { + fprintf(stderr, "Failed to open log file %s\n", log_file_name.c_str()); return; } - - log4cpp::Category& root = log4cpp::Category::getRoot(); -#ifdef RED_DEBUG - root.setPriority(log4cpp::Priority::DEBUG); - root.removeAllAppenders(); - root.addAppender(new log4cpp::FileAppender("_", fd)); -#else - root.setPriority(log4cpp::Priority::INFO); - root.removeAllAppenders(); - ::close(fd); - root.addAppender(new log4cpp::RollingFileAppender("_", log_file_name)); -#endif } void Application::init_globals() 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__); \ } \ } diff --git a/client/gui/gui.h b/client/gui/gui.h index df41efe6..d51a8c85 100644 --- a/client/gui/gui.h +++ b/client/gui/gui.h @@ -59,8 +59,8 @@ public: enum MessageType { QUESTION, INFO, - WARNINNG, - ERROR, + WARNING, + ERROR_MSG }; struct ButtonInfo { diff --git a/client/windows/main.cpp b/client/windows/main.cpp index 8c7166fa..a85acec9 100644 --- a/client/windows/main.cpp +++ b/client/windows/main.cpp @@ -92,7 +92,7 @@ int WINAPI WinMain(HINSTANCE hInstance, exit_val = SPICEC_ERROR_CODE_ERROR; } - log4cpp::Category::shutdown(); + spice_log_cleanup(); pthread_win32_process_detach_np(); return exit_val; diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp index aad4f351..1e05fe10 100644 --- a/client/windows/platform.cpp +++ b/client/windows/platform.cpp @@ -20,6 +20,7 @@ #include <shlobj.h> #include <io.h> #include <conio.h> +#include <fcntl.h> #include "platform.h" #include "win_platform.h" diff --git a/client/windows/redc.vcproj b/client/windows/redc.vcproj index 80e875b5..af7ead44 100644 --- a/client/windows/redc.vcproj +++ b/client/windows/redc.vcproj @@ -47,7 +47,7 @@ Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;..;..\..\common;..\..\..\spice-protocol;..\..\common\win;"..\..\common\win\my_getopt-1.5";"$(SPICE_LIBS)\include";"$(SPICE_LIBS)\include\pixman-1";"$(SPICE_LIBS)\include\CEGUI-0.6.2""
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;SW_CANVAS_CACHE;RED_DEBUG;SW_CANVAS_NO_CHUNKS;_WIN32_WINNT=0x0500;LOG4CPLUS_STATIC;USE_GLZ;PTW32_STATIC_LIB;CEGUI_STATIC"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;SW_CANVAS_CACHE;RED_DEBUG;SW_CANVAS_NO_CHUNKS;_WIN32_WINNT=0x0500;USE_GLZ;PTW32_STATIC_LIB;CEGUI_STATIC"
MinimalRebuild="false"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@@ -69,7 +69,7 @@ />
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="log4cppD.lib pixman-1D.lib libeay32MTd.lib ssleay32MTd.lib ws2_32.lib msimg32.lib winmm.lib libcelt_0_5_1D.lib pthreadVC2d.lib version.lib CEGUIBase_Static_d.lib CEGUITGAImageCodec_Static_d.lib CEGUIExpatParser_Static_d.lib freetype2312MT_D.lib libexpatMT_D.lib pcre_D.lib CEGUIFalagardWRBase_Static_d.lib libjpeg-static-mt-debug.lib zlibwapi.lib"
+ AdditionalDependencies="pixman-1D.lib libeay32MTd.lib ssleay32MTd.lib ws2_32.lib msimg32.lib winmm.lib libcelt_0_5_1D.lib pthreadVC2d.lib version.lib CEGUIBase_Static_d.lib CEGUITGAImageCodec_Static_d.lib CEGUIExpatParser_Static_d.lib freetype2312MT_D.lib libexpatMT_D.lib pcre_D.lib CEGUIFalagardWRBase_Static_d.lib libjpeg-static-mt-debug.lib zlibwapi.lib"
OutputFile="$(OutDir)\spicec.exe"
LinkIncremental="2"
AdditionalLibraryDirectories=""$(SPICE_LIBS)\lib""
@@ -129,7 +129,7 @@ <Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=".;..;..\..\..\spice-protocol;..\..\common;..\..\common\win;"..\..\common\win\my_getopt-1.5";"$(SPICE_LIBS)\include";"$(SPICE_LIBS)\include\pixman-1";"$(SPICE_LIBS)\include\CEGUI-0.6.2""
- PreprocessorDefinitions="WIN32;_WINDOWS;SW_CANVAS_CACHE;SW_CANVAS_NO_CHUNKS;_WIN32_WINNT=0x0500;LOG4CPLUS_STATIC;USE_GLZ;PTW32_STATIC_LIB;CEGUI_STATIC"
+ PreprocessorDefinitions="WIN32;_WINDOWS;SW_CANVAS_CACHE;SW_CANVAS_NO_CHUNKS;_WIN32_WINNT=0x0500;USE_GLZ;PTW32_STATIC_LIB;CEGUI_STATIC"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
@@ -148,7 +148,7 @@ />
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="log4cpp.lib pixman-1.lib libeay32MT.lib ssleay32MT.lib ws2_32.lib msimg32.lib winmm.lib libcelt_0_5_1.lib pthreadVC2.lib version.lib CEGUIBase_Static.lib CEGUITGAImageCodec_Static.lib CEGUIExpatParser_Static.lib freetype2312MT.lib libexpatMT.lib pcre.lib CEGUIFalagardWRBase_Static.lib libjpeg-static-mt.lib zlibwapi.lib"
+ AdditionalDependencies="pixman-1.lib libeay32MT.lib ssleay32MT.lib ws2_32.lib msimg32.lib winmm.lib libcelt_0_5_1.lib pthreadVC2.lib version.lib CEGUIBase_Static.lib CEGUITGAImageCodec_Static.lib CEGUIExpatParser_Static.lib freetype2312MT.lib libexpatMT.lib pcre.lib CEGUIFalagardWRBase_Static.lib libjpeg-static-mt.lib zlibwapi.lib"
OutputFile="$(OutDir)\spicec.exe"
LinkIncremental="1"
AdditionalLibraryDirectories=""$(SPICE_LIBS)\lib""
diff --git a/client/x11/Makefile.am b/client/x11/Makefile.am index d92a96df..eaa03149 100644 --- a/client/x11/Makefile.am +++ b/client/x11/Makefile.am @@ -19,7 +19,6 @@ INCLUDES = \ $(GL_CFLAGS) \ $(ALSA_CFLAGS) \ $(PIXMAN_CFLAGS) \ - $(LOG4CPP_CFLAGS) \ $(CELT051_CFLAGS) \ $(SSL_CFLAGS) \ $(XRANDR_CFLAGS) \ @@ -173,7 +172,6 @@ spicec_SOURCES = \ spicec_LDFLAGS = \ $(SPICEC_STATIC_LINKAGE_BSTATIC) \ - $(LOG4CPP_LIBS) \ $(CELT051_LIBS) \ $(SSL_LIBS) \ $(CEGUI_LIBS) \ diff --git a/client/x11/main.cpp b/client/x11/main.cpp index 1b9bb893..4f49c705 100644 --- a/client/x11/main.cpp +++ b/client/x11/main.cpp @@ -21,7 +21,7 @@ static void cleanup() { - log4cpp::Category::shutdown(); + spice_log_cleanup(); } const char * version_str = VERSION; diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp index 92264546..8fe1f726 100644 --- a/client/x11/platform.cpp +++ b/client/x11/platform.cpp @@ -33,6 +33,7 @@ #include <sys/resource.h> #include <sys/types.h> #include <sys/syscall.h> +#include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <set> |