From 9458d14961f90558a7746261a4bd2fa80a872968 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 29 Nov 2005 15:20:27 +0000 Subject: [PATCH] patching up some more logging stuff git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@584 9efc2488-bf62-4759-914b-345cdb29e865 --- src/jserver/osrf_chat_main.c | 15 ++++++++++++--- src/router/osrf_router_main.c | 14 ++++++++++++-- src/utils/log.c | 6 +++--- src/utils/log.h | 3 +++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/jserver/osrf_chat_main.c b/src/jserver/osrf_chat_main.c index 9c13f26..99d0195 100644 --- a/src/jserver/osrf_chat_main.c +++ b/src/jserver/osrf_chat_main.c @@ -24,6 +24,7 @@ int main( int argc, char* argv[] ) { char* listenaddr = osrfConfigGetValue(cfg, "/listen_address"); char* llevel = osrfConfigGetValue(cfg, "/loglevel"); char* lfile = osrfConfigGetValue(cfg, "/logfile"); + char* facility = osrfConfigGetValue(cfg, "/syslog"); if(!(domain && secret && sport && listenaddr && llevel && lfile && s2sport)) { fprintf(stderr, "Configuration error for ChopChop - missing key ingredient\n"); @@ -33,9 +34,17 @@ int main( int argc, char* argv[] ) { int port = atoi(sport); int s2port = atoi(s2sport); int level = atoi(llevel); - //log_init(level, lfile); - osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "chopchop", level); - osrfLogSetSyslogFacility(LOG_LOCAL2); + + if(!lfile) { fprintf(stderr, "Log file needed\n"); return -1; } + + if(!strcmp(lfile, "syslog")) { + osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "chochop", level ); + osrfLogSetSyslogFacility(osrfLogFacilityToInt(facility)); + + } else { + osrfLogInit( OSRF_LOG_TYPE_FILE, "chopchop", level ); + osrfLogSetFile( lfile ); + } fprintf(stderr, "Attempting to launch ChopChop with:\n" "domain: %s\nport: %s\nlisten address: %s\nlog level: %s\nlog file: %s\n", diff --git a/src/router/osrf_router_main.c b/src/router/osrf_router_main.c index 5187cc8..5875f73 100644 --- a/src/router/osrf_router_main.c +++ b/src/router/osrf_router_main.c @@ -49,6 +49,7 @@ int __setupRouter( char* config, char* context ) { /* set up the logger */ char* level = osrfConfigGetValue(NULL, "/loglevel"); char* log_file = osrfConfigGetValue(NULL, "/logfile"); + char* facility = osrfConfigGetValue(NULL, "/syslog"); int llevel = 1; if(level) llevel = atoi(level); @@ -58,9 +59,18 @@ int __setupRouter( char* config, char* context ) { fprintf(stderr, "Unable to init logging, going to stderr...\n" ); */ - osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "router", llevel ); /* XXX config option */ - osrfLogSetSyslogFacility( LOG_LOCAL3 ); /* XXX config option */ + if(!log_file) { fprintf(stderr, "Log file needed\n"); return -1; } + if(!strcmp(log_file, "syslog")) { + osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "router", llevel ); + osrfLogSetSyslogFacility(osrfLogFacilityToInt(facility)); + + } else { + osrfLogInit( OSRF_LOG_TYPE_FILE, "router", llevel ); + osrfLogSetFile( log_file ); + } + + free(facility); free(level); free(log_file); diff --git a/src/utils/log.c b/src/utils/log.c index 3c65a63..194a8b3 100644 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -158,8 +158,8 @@ void _osrfLogToFile( char* msg, ... ) { int osrfLogFacilityToInt( char* facility ) { - if(!facility) return -1; - if(strlen(facility) < 6) return -1; + if(!facility) return LOG_LOCAL0; + if(strlen(facility) < 6) return LOG_LOCAL0; switch( facility[5] ) { case 0: return LOG_LOCAL0; case 1: return LOG_LOCAL1; @@ -170,7 +170,7 @@ int osrfLogFacilityToInt( char* facility ) { case 6: return LOG_LOCAL6; case 7: return LOG_LOCAL7; } - return -1; + return LOG_LOCAL0; } diff --git a/src/utils/log.h b/src/utils/log.h index 2886dc6..a425f97 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -62,6 +62,9 @@ void osrfLogDetail( int level, char* filename, int line, char* func, char* msg, void _osrfLogToFile( char* msg, ... ); +/* returns the int representation of the log facility based on the facility name + * if the facility name is invalid, LOG_LOCAL0 is returned + */ int osrfLogFacilityToInt( char* facility ); #endif -- 2.11.0