diff options
Diffstat (limited to 'utility/util.c')
-rw-r--r-- | utility/util.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/utility/util.c b/utility/util.c index ef3ea68..cb6898d 100644 --- a/utility/util.c +++ b/utility/util.c | |||
@@ -1,7 +1,11 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "apr_strings.h" | 2 | #include "apr_strings.h" |
3 | #include "apr_lib.h" | 3 | #include "apr_lib.h" |
4 | #include "apr_file_io.h" | ||
4 | 5 | ||
6 | #include "config.h" | ||
7 | |||
8 | #include <stdarg.h> | ||
5 | 9 | ||
6 | char *lowerstr(apr_pool_t *pool, const char *input) | 10 | char *lowerstr(apr_pool_t *pool, const char *input) |
7 | { | 11 | { |
@@ -26,3 +30,38 @@ void line_chomp(char *str) | |||
26 | } | 30 | } |
27 | } | 31 | } |
28 | } | 32 | } |
33 | |||
34 | void logging_init(config_t *cfg) | ||
35 | { | ||
36 | if (cfg->errorlog) { | ||
37 | apr_file_open(&cfg->errorlog_fp, cfg->errorlog, | ||
38 | APR_FOPEN_CREATE | APR_FOPEN_WRITE | APR_BUFFERED, | ||
39 | APR_OS_DEFAULT, | ||
40 | cfg->pool); | ||
41 | apr_pool_create(&cfg->errorlog_p, cfg->pool); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * @todo implement logging | ||
47 | */ | ||
48 | void logging_log(config_t *cfg, loglevel_e level, const char *fmt, ...) | ||
49 | { | ||
50 | va_list ap; | ||
51 | struct iovec vec[2]; | ||
52 | apr_size_t blen; | ||
53 | |||
54 | if (!cfg->errorlog_fp || cfg->loglevel < level) return; | ||
55 | |||
56 | va_start(ap, fmt); | ||
57 | apr_pool_clear(cfg->errorlog_p); | ||
58 | |||
59 | vec[0].iov_base = apr_pvsprintf(cfg->errorlog_p, fmt, ap); | ||
60 | vec[0].iov_len = strlen(vec[0].iov_base); | ||
61 | vec[1].iov_base = "\n"; | ||
62 | vec[1].iov_len = 1; | ||
63 | |||
64 | apr_file_writev(cfg->errorlog_fp,vec,2,&blen); | ||
65 | |||
66 | va_end(ap); | ||
67 | } | ||