1
0
mirror of https://github.com/coturn/coturn.git synced 2025-11-01 23:41:09 +01:00

Add options for new log timestamp and setting timestamp format

This adds the `--new-log-timestamp` and `--new-timestamp-format <value>` options
to the `turnserver` program.

Setting `--new-log-timestamp` on the command line, or `new-log-timestamp` in the
configuration file, will cause all logs to be written with an ISI-8601 timestamp
(`YYYY-MM-DDTHH:MM:SSZZZZZ` with `T` being literal and `ZZZZZ` being `+` or `-`
and the hour and minute offset from GMT for the local timezone).  This replaces
the 'number of seconds since daemon was started' format.

Setting the `--new-timestamp-format <format>` option with a given format, or
`new-log-timestamp=<format>` in the configuration file, will use this instead
of the standard timestamp format.  Timestamp format strings up to 48 characters
can be accommodated; more will be truncated.  This will only be used when the
`--new-log-timestamp` option (above) is set.

Thanks to Hendrik Huels <hendrik.huels@outlook.de> for the idea and some of the
code for setting the log timestamp string.

Signed-off-by: Paul Wayper <paulway@mabula.net>
This commit is contained in:
Paul Wayper 2020-09-01 21:01:28 +10:00
parent ed88f1605a
commit c315c288bd

View File

@ -603,6 +603,8 @@ static char Usage[] = "Usage: turnserver [options]\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"
" --new-log-timestamp Enable full ISO-8601 timestamp in all logs.\n"
" --new-timestamp_format <format> Set timestamp format (in strftime(1) format)\n"
" --stale-nonce[=<value>] Use extra security with nonce value having limited lifetime (default 600 secs).\n"
" --max-allocate-lifetime <value> Set the maximum value for the allocation lifetime. Default to 3600 secs.\n"
" --channel-lifetime <value> Set the lifetime for channel binding, default to 600 secs.\n"
@ -761,6 +763,8 @@ enum EXTRA_OPTS {
NO_STDOUT_LOG_OPT,
SYSLOG_OPT,
SIMPLE_LOG_OPT,
NEW_LOG_TIMESTAMP_OPT,
NEW_TIMESTAMP_FORMAT_OPT,
AUX_SERVER_OPT,
UDP_SELF_BALANCE_OPT,
ALTERNATE_SERVER_OPT,
@ -899,6 +903,8 @@ static const struct myoption long_options[] = {
{ "no-stdout-log", optional_argument, NULL, NO_STDOUT_LOG_OPT },
{ "syslog", optional_argument, NULL, SYSLOG_OPT },
{ "simple-log", optional_argument, NULL, SIMPLE_LOG_OPT },
{ "new-log-timestamp", optional_argument, NULL, NEW_LOG_TIMESTAMP_OPT },
{ "new-timestamp_format", required_argument, NULL, NEW_TIMESTAMP_FORMAT_OPT },
{ "aux-server", required_argument, NULL, AUX_SERVER_OPT },
{ "udp-self-balance", optional_argument, NULL, UDP_SELF_BALANCE_OPT },
{ "alternate-server", required_argument, NULL, ALTERNATE_SERVER_OPT },
@ -1717,6 +1723,10 @@ static void read_config_file(int argc, char **argv, int pass)
set_log_to_syslog(get_bool_value(value));
} else if((pass==0) && (c==SIMPLE_LOG_OPT)) {
set_simple_log(get_bool_value(value));
} else if ((pass==0) && (c==NEW_LOG_TIMESTAMP_OPT)) {
use_new_log_timestamp_format=1;
} else if ((pass==0) && (c==NEW_TIMESTAMP_FORMAT_OPT)) {
set_turn_log_timestamp_format(value);
} else if((pass == 0) && (c != 'u')) {
set_option(c, value);
} else if((pass > 0) && (c == 'u')) {