From: Andre Noll Date: Mon, 29 Aug 2011 17:17:38 +0000 (+0200) Subject: Allow switching between different log methods at runtime. X-Git-Tag: v0.4.9~1^2~9 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=65453788515cd5f4c905b518745b4dd7f6f2da10;p=paraslash.git Allow switching between different log methods at runtime. Currently, para_client defines its para_log function via the INIT_STDERR_LOGGING() macro which generates a log function that writes to stderr. However, we will need to switch to a different, curses-aware logging function when operating in interactive mode. To support more than one log method the type of para_log is changed from a function to a (public) pointer variable. This variable is supposed to point to the log function currently in use so that the application can simply set para_log differently in order to switch between log functions. The patch also changes the INIT_STDERR_LOGGING() macro to receive the name of the log function to be defined and to let para_log point to the newly defined function. --- diff --git a/audiod.c b/audiod.c index 8008e2cb..7085ef0f 100644 --- a/audiod.c +++ b/audiod.c @@ -33,6 +33,7 @@ #include "signal.h" #include "version.h" +__printf_2_3 void (*para_log)(int, const char*, ...) = daemon_log; /** define the array of error lists needed by para_audiod */ INIT_AUDIOD_ERRLISTS; /** define the array containing all supported audio formats */ diff --git a/daemon.c b/daemon.c index 0bf2f0ac..f06cf2f5 100644 --- a/daemon.c +++ b/daemon.c @@ -357,7 +357,7 @@ __malloc char *get_server_uptime_str(const struct timeval *current_time) * \param ll The log level. * \param fmt The format string describing the log message. */ -__printf_2_3 void para_log(int ll, const char* fmt,...) +__printf_2_3 void daemon_log(int ll, const char* fmt,...) { va_list argp; FILE *fp; diff --git a/daemon.h b/daemon.h index 3fe72ea9..fd435577 100644 --- a/daemon.h +++ b/daemon.h @@ -16,6 +16,7 @@ void daemon_clear_flag(unsigned flag); void daemon_set_loglevel(char *loglevel); void daemon_set_default_log_colors(void); void daemon_set_log_color_or_die(char const *arg); +__printf_2_3 void daemon_log(int ll, const char* fmt,...); /** Daemon log configuration flags. */ enum daemon_flags { diff --git a/fade.c b/fade.c index 04ca9237..1aced9df 100644 --- a/fade.c +++ b/fade.c @@ -27,7 +27,7 @@ INIT_FADE_ERRLISTS; static struct fade_args_info conf; -__printf_2_3 void para_log(__a_unused int ll, const char *fmt, ...) +__printf_2_3 void date_log(__a_unused int ll, const char *fmt, ...) { va_list argp; time_t t1; @@ -40,6 +40,7 @@ __printf_2_3 void para_log(__a_unused int ll, const char *fmt, ...) vprintf(fmt, argp); va_end(argp); } +__printf_2_3 void (*para_log)(int, const char*, ...) = date_log; /* * Open the mixer device. diff --git a/gui.c b/gui.c index a3c07ec7..3fc81965 100644 --- a/gui.c +++ b/gui.c @@ -489,7 +489,7 @@ static int add_output_line(char *line, __a_unused void *data) static int loglevel; -__printf_2_3 void para_log(int ll, const char *fmt,...) +__printf_2_3 void curses_log(int ll, const char *fmt,...) { int color; char *msg; @@ -510,6 +510,7 @@ __printf_2_3 void para_log(int ll, const char *fmt,...) rb_add_entry(color, msg); wrefresh(bot.win); } +__printf_2_3 void (*para_log)(int, const char*, ...) = curses_log; static void setup_signal_handling(void) { diff --git a/para.h b/para.h index bc6aa929..96492baa 100644 --- a/para.h +++ b/para.h @@ -49,15 +49,19 @@ typeof(x) _x = (x); \ _x > 0? _x : -_x; }) + +extern __printf_2_3 void (*para_log)(int, const char*, ...); /** * Define a standard log function that always writes to stderr. * + * \param funcname The name of the function to be defined. + * * \param loglevel_barrier If the loglevel of the current message * is less than that, the message is going to be ignored. * */ -#define INIT_STDERR_LOGGING(loglevel_barrier) \ - __printf_2_3 void para_log(int ll, const char* fmt,...) \ +#define DEFINE_STDERR_LOGGER(funcname, loglevel_barrier) \ + __printf_2_3 void funcname(int ll, const char* fmt,...) \ { \ va_list argp; \ if (ll < loglevel_barrier) \ @@ -66,6 +70,9 @@ vfprintf(stderr, fmt, argp); \ va_end(argp); \ } +#define INIT_STDERR_LOGGING(loglevel_barrier) \ + DEFINE_STDERR_LOGGER(stderr_log, loglevel_barrier); \ + __printf_2_3 void (*para_log)(int, const char*, ...) = stderr_log; /** Sent by para_client to initiate the authentication procedure. */ #define AUTH_REQUEST_MSG "auth rsa " @@ -105,8 +112,6 @@ extern const char *status_item_list[]; int for_each_stat_item(char *item_buf, size_t num_bytes, int (*item_handler)(int, char *)); -__printf_2_3 void para_log(int, const char*, ...); - /** * Write a log message to a dynamically allocated string. * diff --git a/server.c b/server.c index 7f020c8f..4650f994 100644 --- a/server.c +++ b/server.c @@ -92,6 +92,8 @@ #include "color.h" #include "version.h" +__printf_2_3 void (*para_log)(int, const char*, ...) = daemon_log; + /** Define the array of error lists needed by para_server. */ INIT_SERVER_ERRLISTS;