diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2010-09-02 00:22:28 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2010-09-02 00:22:28 +0400 |
commit | 81515c09f55f152e8330c3b43ad159be64f494e8 (patch) | |
tree | 73d3492455265ac4deaae5cba0f7ccee0f233567 /accel-pptpd/triton/log.c | |
parent | 2b63c6e6e368d6ea39584a70ddb81a88e0924c47 (diff) | |
download | accel-ppp-81515c09f55f152e8330c3b43ad159be64f494e8.tar.gz accel-ppp-81515c09f55f152e8330c3b43ad159be64f494e8.zip |
rewriting triton library ...
Diffstat (limited to 'accel-pptpd/triton/log.c')
-rw-r--r-- | accel-pptpd/triton/log.c | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/accel-pptpd/triton/log.c b/accel-pptpd/triton/log.c index 39a9cb1..7ff90f8 100644 --- a/accel-pptpd/triton/log.c +++ b/accel-pptpd/triton/log.c @@ -1,29 +1,27 @@ #include <stdio.h> +#include <stdarg.h> #include "triton_p.h" static FILE *f_error; static FILE *f_debug; +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; int log_init(void) { - char *log_error=conf_get_opt("core","log_error"); - char *log_debug=conf_get_opt("core","log_debug"); - - if (log_error) - { - f_error=fopen(log_error,"a"); - if (!f_error) - { + char *log_error = conf_get_opt("core","log_error"); + char *log_debug = conf_get_opt("core","log_debug"); + + if (log_error) { + f_error = fopen(log_error, "a"); + if (!f_error) { perror("log:log_error:open"); return -1; } } - if (log_debug) - { - f_debug=fopen(log_debug,"a"); - if (!f_debug) - { + if (log_debug) { + f_debug = fopen(log_debug, "a"); + if (!f_debug) { perror("log:log_debug:open"); return -1; } @@ -32,3 +30,36 @@ int log_init(void) return 0; } +static void do_log(FILE *f, const char *fmt, va_list ap) +{ + struct timeval tv; + struct tm tm; + char date[64]; + + gettimeofday(&tv, NULL); + localtime_r(&tv.tv_sec, &tm); + strftime(date, sizeof(date), "%F %H:%M:%S", &tm); + + pthread_mutex_lock(&lock); + fprintf(f, "[%s.%i]", date, (int)tv.tv_usec / 1000); + vfprintf(f, fmt,ap); + pthread_mutex_unlock(&lock); +} +void triton_log_error(const char *fmt,...) +{ + va_list ap; + if (!f_error) + return; + va_start(ap, fmt); + do_log(f_error, fmt, ap); +} + +void triton_log_debug(const char *fmt,...) +{ + va_list ap; + if (!f_debug) + return; + va_start(ap, fmt); + do_log(f_debug, fmt, ap); +} + |