patching up some more logging stuff
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 29 Nov 2005 15:20:27 +0000 (15:20 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 29 Nov 2005 15:20:27 +0000 (15:20 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@584 9efc2488-bf62-4759-914b-345cdb29e865

src/jserver/osrf_chat_main.c
src/router/osrf_router_main.c
src/utils/log.c
src/utils/log.h

index 9c13f26..99d0195 100644 (file)
@@ -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",
index 5187cc8..5875f73 100644 (file)
@@ -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);
 
index 3c65a63..194a8b3 100644 (file)
@@ -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;
 }
 
 
index 2886dc6..a425f97 100644 (file)
@@ -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