diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-28 22:47:42 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-28 22:47:42 +0200 |
commit | f4980c7d59fa1e01ca4a5b5f65c9514ca18d3a88 (patch) | |
tree | abbf368c53ce9e69c5188c731912325ceb86a13f /eurephiadm | |
parent | 9a024f7f1addcb6bfccc49e74250009d7dfa31ae (diff) | |
parent | 5aed7f6775777b2a6166d6eddffaa976eb4fac8b (diff) | |
download | eurephia-f4980c7d59fa1e01ca4a5b5f65c9514ca18d3a88.tar.gz eurephia-f4980c7d59fa1e01ca4a5b5f65c9514ca18d3a88.tar.xz eurephia-f4980c7d59fa1e01ca4a5b5f65c9514ca18d3a88.zip |
Merge branch 'syslog'
Diffstat (limited to 'eurephiadm')
-rw-r--r-- | eurephiadm/client_context.c | 52 | ||||
-rw-r--r-- | eurephiadm/client_context.h | 2 | ||||
-rw-r--r-- | eurephiadm/eurephiadm.c | 10 |
3 files changed, 17 insertions, 47 deletions
diff --git a/eurephiadm/client_context.c b/eurephiadm/client_context.c index aaec995..45405c7 100644 --- a/eurephiadm/client_context.c +++ b/eurephiadm/client_context.c @@ -43,13 +43,16 @@ * Initialises a new eurephiaCTX. This function also initialises the database driver, which must * be configured in the configuration. * - * @param log FILE pointer where to put log data + * @param log String containing log destination + * @param logident String used to identify log entries when logging to syslog * @param loglevel Set the log level (verbosity) * @param cfg eurephiaVALUES pointer to the configuration * * @return Returns a pointer to a eurephiaCTX, otherwise NULL. */ -eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, eurephiaVALUES *cfg) { +eurephiaCTX *eurephiaCTX_init(const char *logident, const char *log, + const int loglevel, eurephiaVALUES *cfg) +{ eurephiaCTX *ctx = NULL; char *dbdriver = NULL, *logfile = NULL; int cfgloglvl = 0; @@ -62,39 +65,21 @@ eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, eurephiaVALUES *cfg ctx = (eurephiaCTX *) malloc_nullsafe(NULL, sizeof(eurephiaCTX)+2); assert(ctx != NULL); - memset(ctx, 0, sizeof(eurephiaCTX)+2); ctx->context_type = ECTX_ADMIN_CONSOLE; // Open log file. Use config file as default if it exists, if not use input param. - logfile = eGet_value(cfg, "log"); + cfgloglvl = ((eGet_value(cfg, "log_level") == NULL) + ? loglevel : atoi_nullsafe(eGet_value(cfg, "log_level"))); + + logfile = eGet_value(cfg, "log"); if( (logfile != NULL) && (log == NULL) ) { - if( strcmp(logfile, "stdout:") == 0 ) { - ctx->log = stdout; - } else if( strcmp(logfile, "stderr:") == 0 ) { - ctx->log = stderr; - } else if( strcmp(logfile, "none:") == 0 ) { - ctx->log = NULL; - } else if( (ctx->log = fopen(logfile, "aw")) == NULL ) { - fprintf(stderr, "ERROR: Could not open log file: %s\n", logfile); - free_nullsafe(NULL, ctx); - return NULL; - } + eurephia_log_init(ctx, logident, logfile, (loglevel > 0 ? loglevel : cfgloglvl)); } else { // If log file is not set in config, use input log parameter. But if // no log file is defined even here, use stderr. If no logging is wanted, it // must be defined as none: in the config file. - ctx->log = (log != NULL ? log : stderr); - } - - // Set log level. Use config file as default if it exists, if not input param defaults. - // But if input param loglevel > 0, then override config file. - // Only set loglevel if logging is enabled. - if( ctx->log != NULL ) { - cfgloglvl = ((eGet_value(cfg, "log_level") == NULL) - ? loglevel : atoi_nullsafe(eGet_value(cfg, "log_level"))); - ctx->loglevel = (loglevel > 0 ? loglevel : cfgloglvl); - } else { - ctx->loglevel = 0; + eurephia_log_init(ctx, logident, (log != NULL ? log : "stderr:"), + (loglevel > 0 ? loglevel : cfgloglvl)); } if( !eDBlink_init(ctx, dbdriver, 2) ) { @@ -125,17 +110,6 @@ void eurephiaCTX_destroy(eurephiaCTX *ctx) { eDBlink_close(ctx); } - if( ctx->log != NULL ) { - fflush(ctx->log); - - // Do not close log file if we're on stdout or stderr - if( (ctx->log != stderr) && (ctx->log != stdout) ) { - eurephia_log(ctx, LOG_INFO, 2, "Closing log file"); - fclose(ctx->log); - } - - ctx->log = NULL; - ctx->loglevel = 0; - } + eurephia_log_close(ctx); free_nullsafe(ctx, ctx); } diff --git a/eurephiadm/client_context.h b/eurephiadm/client_context.h index 56e85ed..96bc431 100644 --- a/eurephiadm/client_context.h +++ b/eurephiadm/client_context.h @@ -31,7 +31,7 @@ #ifndef EUREPHIA_CLIENT_CONTEXT #define EUREPHIA_CLIENT_CONTEXT -eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, eurephiaVALUES *cfg); +eurephiaCTX *eurephiaCTX_init(const char *logident, const char *log, const int loglevel, eurephiaVALUES *cfg); void eurephiaCTX_destroy(eurephiaCTX *ctx); #endif diff --git a/eurephiadm/eurephiadm.c b/eurephiadm/eurephiadm.c index 203b7e2..1429f24 100644 --- a/eurephiadm/eurephiadm.c +++ b/eurephiadm/eurephiadm.c @@ -440,7 +440,7 @@ char *args2string(int argc, char **argv) { * @return returns 0 on success, otherwise a value > 0 */ int main(int argc, char **argv) { - FILE *logfile = NULL; + char *logfile = NULL; int loglevel = 0; eurephiaCTX *ctx = NULL; eurephiaSESSION *session = NULL; @@ -480,11 +480,7 @@ int main(int argc, char **argv) { return 0; case 'l': - if( (logfile = fopen(optargs[0], "wb")) == NULL ) { - fprintf(stderr, "%s: ERROR :: Could not open log file: %s\n", - basename(argv[0]), optargs[0]); - return 0; - } + logfile = optargs[0]; break; case 'L': @@ -543,7 +539,7 @@ int main(int argc, char **argv) { // // Create a eurephia context and load database driver - ctx = eurephiaCTX_init(logfile, loglevel, cfg); + ctx = eurephiaCTX_init("eurephiadm", logfile, loglevel, cfg); if( ctx == NULL ) { fprintf(stderr, "Could not initialise a eurephia context.\n"); return 3; |