Skip to content

Commit

Permalink
Add syslog facility configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
trkcll-bvb committed Jul 7, 2021
1 parent 553ce02 commit 22af3ea
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/etc/turnserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 43 additions & 1 deletion src/apps/common/ns_turn_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/apps/common/ns_turn_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand Down
2 changes: 2 additions & 0 deletions src/apps/relay/mainrelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value> 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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 22af3ea

Please sign in to comment.