summaryrefslogtreecommitdiffstatsabout
path: root/utility/util.c
diff options
context:
space:
mode:
authorEdward Rudd <urkle@outoforder.cc>2008-10-25 04:25:56 (GMT)
committer Edward Rudd <urkle@outoforder.cc>2008-10-25 04:25:56 (GMT)
commitcaae8dcfed1462cb19c82f99087e6fe2ba3d407c (patch)
treec575ead091166c6674111b4d214e87487f38e991 /utility/util.c
parent19bbdd68a491721dd4aeff7cacea51148ce3a9b9 (diff)
implemented logging
added better error messages for DB connections fix several segfaults
Diffstat (limited to 'utility/util.c')
-rw-r--r--utility/util.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/utility/util.c b/utility/util.c
index cb6898d..99bb046 100644
--- a/utility/util.c
+++ b/utility/util.c
@@ -33,15 +33,31 @@ void line_chomp(char *str)
33 33
34void logging_init(config_t *cfg) 34void logging_init(config_t *cfg)
35{ 35{
36 apr_status_t rv;
37 apr_pool_create(&cfg->errorlog_p, cfg->pool);
38 apr_file_open_stderr(&cfg->errorlog_fperr, cfg->pool);
36 if (cfg->errorlog) { 39 if (cfg->errorlog) {
37 apr_file_open(&cfg->errorlog_fp, cfg->errorlog, 40 rv = apr_file_open(&cfg->errorlog_fp, cfg->errorlog,
38 APR_FOPEN_CREATE | APR_FOPEN_WRITE | APR_BUFFERED, 41 APR_FOPEN_CREATE | APR_FOPEN_WRITE | APR_FOPEN_APPEND,
39 APR_OS_DEFAULT, 42 APR_OS_DEFAULT,
40 cfg->pool); 43 cfg->pool);
41 apr_pool_create(&cfg->errorlog_p, cfg->pool); 44 if (rv) {
45 printf("Error opening %s\n",cfg->errorlog);
46 cfg->loglevel = LOGLEVEL_NONE;
47 }
48 logging_log(cfg, LOGLEVEL_ERROR, "Log file Opened");
49 } else {
50 cfg->loglevel = LOGLEVEL_NONE;
51 logging_log(cfg, LOGLEVEL_NOISE, "No Log file specified, disabled logging");
42 } 52 }
43} 53}
44 54
55const char *logging_strerror(apr_status_t rv)
56{
57 char buff[256];
58 return apr_strerror(rv, buff, 256);
59}
60
45/** 61/**
46 * @todo implement logging 62 * @todo implement logging
47 */ 63 */
@@ -51,7 +67,7 @@ void logging_log(config_t *cfg, loglevel_e level, const char *fmt, ...)
51 struct iovec vec[2]; 67 struct iovec vec[2];
52 apr_size_t blen; 68 apr_size_t blen;
53 69
54 if (!cfg->errorlog_fp || cfg->loglevel < level) return; 70 if (cfg->loglevel < level) return;
55 71
56 va_start(ap, fmt); 72 va_start(ap, fmt);
57 apr_pool_clear(cfg->errorlog_p); 73 apr_pool_clear(cfg->errorlog_p);
@@ -61,7 +77,12 @@ void logging_log(config_t *cfg, loglevel_e level, const char *fmt, ...)
61 vec[1].iov_base = "\n"; 77 vec[1].iov_base = "\n";
62 vec[1].iov_len = 1; 78 vec[1].iov_len = 1;
63 79
64 apr_file_writev(cfg->errorlog_fp,vec,2,&blen); 80 if (level == LOGLEVEL_NOISE) {
81 apr_file_writev(cfg->errorlog_fperr,vec,2,&blen);
82 }
83 if (cfg->loglevel > LOGLEVEL_NONE) {
84 apr_file_writev(cfg->errorlog_fp,vec,2,&blen);
85 }
65 86
66 va_end(ap); 87 va_end(ap);
67} 88}