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");
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",
/* 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);
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);
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;
case 6: return LOG_LOCAL6;
case 7: return LOG_LOCAL7;
}
- return -1;
+ return LOG_LOCAL0;
}
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