diff --git a/examples/etc/turnserver.conf b/examples/etc/turnserver.conf index 97999e7b..625fa393 100644 --- a/examples/etc/turnserver.conf +++ b/examples/etc/turnserver.conf @@ -528,6 +528,11 @@ # #syslog +# Set syslog facility for syslog messages +# Default values is ''. +# +#syslog-facility="LOG_LOCAL1" + # This flag means that no log file rollover will be used, and the log file # name will be constructed as-is, without PID and date appendage. # This option can be used, for example, together with the logrotate tool. diff --git a/src/apps/common/ns_turn_utils.c b/src/apps/common/ns_turn_utils.c index 991b2918..675838ab 100644 --- a/src/apps/common/ns_turn_utils.c +++ b/src/apps/common/ns_turn_utils.c @@ -147,6 +147,48 @@ int turn_mutex_destroy(turn_mutex* mutex) { ///////////////////////// LOG /////////////////////////////////// +/* syslog facility */ +/*BVB-594 Syslog facility */ +static char* str_fac[]={"LOG_AUTH","LOG_CRON","LOG_DAEMON", + "LOG_KERN","LOG_LOCAL0","LOG_LOCAL1", + "LOG_LOCAL2","LOG_LOCAL3","LOG_LOCAL4","LOG_LOCAL5", + "LOG_LOCAL6","LOG_LOCAL7","LOG_LPR","LOG_MAIL", + "LOG_NEWS","LOG_USER","LOG_UUCP", + "LOG_AUTHPRIV","LOG_FTP","LOG_SYSLOG", + 0}; + +static int int_fac[]={LOG_AUTH , LOG_CRON , LOG_DAEMON , + LOG_KERN , LOG_LOCAL0 , LOG_LOCAL1 , + LOG_LOCAL2 , LOG_LOCAL3 , LOG_LOCAL4 , LOG_LOCAL5 , + LOG_LOCAL6 , LOG_LOCAL7 , LOG_LPR , LOG_MAIL , + LOG_NEWS , LOG_USER , LOG_UUCP, + LOG_AUTHPRIV,LOG_FTP,LOG_SYSLOG, + 0}; + +static int syslog_facility = 0; + +static int str2facility(char *s) +{ + int i; + for (i=0; str_fac[i]; i++) { + if (!strcasecmp(s,str_fac[i])) + return int_fac[i]; + } + return -1; +} + +void set_syslog_facility(char *val) +{ + if(val == NULL){ + return; + } + int tmp = str2facility(val); + if(tmp == -1){ + return; + } + syslog_facility = tmp; +} + #if defined(TURN_LOG_FUNC_IMPL) extern void TURN_LOG_FUNC_IMPL(TURN_LOG_LEVEL level, const char* format, va_list args); #endif @@ -510,7 +552,7 @@ void turn_log_func_default(TURN_LOG_LEVEL level, const char* format, ...) fwrite(s, so_far, 1, stdout); /* write to syslog or to log file */ if(to_syslog) { - syslog(get_syslog_level(level),"%s",s); + syslog(syslog_facility|get_syslog_level(level),"%s",s); } else { log_lock(); set_rtpfile(); diff --git a/src/apps/common/ns_turn_utils.h b/src/apps/common/ns_turn_utils.h index d9e9488d..e5f65398 100644 --- a/src/apps/common/ns_turn_utils.h +++ b/src/apps/common/ns_turn_utils.h @@ -61,6 +61,8 @@ void set_no_stdout_log(int val); void set_log_to_syslog(int val); void set_simple_log(int val); +void set_syslog_facility(char *val); + void set_turn_log_timestamp_format(char* new_format); void turn_log_func_default(TURN_LOG_LEVEL level, const char* format, ...); diff --git a/src/apps/relay/mainrelay.c b/src/apps/relay/mainrelay.c index 3ed4a1db..a4d88b86 100644 --- a/src/apps/relay/mainrelay.c +++ b/src/apps/relay/mainrelay.c @@ -620,6 +620,7 @@ static char Usage[] = "Usage: turnserver [options]\n" " a log file. With this option everything will be going to the log file only\n" " (unless the log file itself is stdout).\n" " --syslog Output all log information into the system log (syslog), do not use the file output.\n" +" --syslog-facility Set syslog facility for syslog messages. Default is ''.\n" " --simple-log This flag means that no log file rollover will be used, and the log file\n" " name will be constructed as-is, without PID and date appendage.\n" " This option can be used, for example, together with the logrotate tool.\n" @@ -796,6 +797,7 @@ enum EXTRA_OPTS { AUTH_SECRET_TS_EXP, /* deprecated */ NO_STDOUT_LOG_OPT, SYSLOG_OPT, + SYSLOG_FACILITY_OPT, SIMPLE_LOG_OPT, NEW_LOG_TIMESTAMP_OPT, NEW_LOG_TIMESTAMP_FORMAT_OPT,