Skip to content

Commit

Permalink
Merge pull request coturn#789 from korayvt/syslog_facility
Browse files Browse the repository at this point in the history
Add syslog facility configuration
  • Loading branch information
ggarber authored Aug 10, 2022
2 parents 6616619 + 2b91f0a commit 38c4055
Show file tree
Hide file tree
Showing 4 changed files with 60 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
45 changes: 44 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,49 @@ 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 str_to_syslog_facility(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 = str_to_syslog_facility(val);
if(tmp == -1){
TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "WARNING: invalid syslog-facility value (%s); ignored.\n", val);
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 +553,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
9 changes: 9 additions & 0 deletions src/apps/relay/mainrelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,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 @@ -802,6 +803,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 Expand Up @@ -997,6 +999,7 @@ static const struct myoption long_options[] = {
{ "no-rfc5780", optional_argument, NULL, NO_RFC5780 },
{ "no-stun-backward-compatibility", optional_argument, NULL, NO_STUN_BACKWARD_COMPATIBILITY_OPT },
{ "response-origin-only-with-rfc5780", optional_argument, NULL, RESPONSE_ORIGIN_ONLY_WITH_RFC5780_OPT },
{ "syslog-facility", required_argument, NULL, SYSLOG_FACILITY_OPT },
{ NULL, no_argument, NULL, 0 }
};

Expand Down Expand Up @@ -1693,6 +1696,7 @@ static void set_option(int c, char *value)
case SIMPLE_LOG_OPT:
case NEW_LOG_TIMESTAMP_OPT:
case NEW_LOG_TIMESTAMP_FORMAT_OPT:
case SYSLOG_FACILITY_OPT:
case 'c':
case 'n':
case 'h':
Expand Down Expand Up @@ -1823,6 +1827,8 @@ static void read_config_file(int argc, char **argv, int pass)
use_new_log_timestamp_format=1;
} else if ((pass==0) && (c==NEW_LOG_TIMESTAMP_FORMAT_OPT)) {
set_turn_log_timestamp_format(value);
} else if((pass==0) && (c==SYSLOG_FACILITY_OPT)) {
set_syslog_facility(value);
} else if((pass == 1) && (c != 'u')) {
set_option(c, value);
} else if((pass == 2) && (c == 'u')) {
Expand Down Expand Up @@ -2309,6 +2315,9 @@ int main(int argc, char **argv)
case NEW_LOG_TIMESTAMP_FORMAT_OPT:
set_turn_log_timestamp_format(optarg);
break;
case SYSLOG_FACILITY_OPT:
set_syslog_facility(optarg);
break;
default:
;
}
Expand Down

0 comments on commit 38c4055

Please sign in to comment.