diff --git a/.github/workflows/cmake.yaml b/.github/workflows/cmake.yaml index 0a5b383a8..043091e31 100644 --- a/.github/workflows/cmake.yaml +++ b/.github/workflows/cmake.yaml @@ -24,7 +24,8 @@ jobs: libpq-dev libmariadb-dev libsqlite3-dev \ libhiredis-dev \ libmongoc-dev \ - libmicrohttpd-dev + libmicrohttpd-dev \ + liblog4cplus-dev - uses: actions/checkout@v4 - name: Prometheus support run: | diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml index 389478623..4f991bd4a 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc.yml @@ -39,7 +39,7 @@ jobs: SOURCE_DIR: ${{github.workspace}}\.cache\source TOOLS_DIR: ${{github.workspace}}\.cache\tools INSTALL_DIR: ${{github.workspace}}\.cache\install_msvc_${{matrix.triplet}}_${{matrix.BUILD_TYPE}} - VCPKGGITCOMMITID: acc3bcf76b84ae5041c86ab55fe138ae7b8255c7 + VCPKGGITCOMMITID: 0e47c1985273129e4d0ee52ff73bed9125555de8 VCPKG_PLATFORM_TOOLSET: ${{matrix.VCPKG_PLATFORM_TOOLSET}} CMAKE_GENERATOR_PLATFORM: ${{matrix.CMAKE_GENERATOR_PLATFORM}} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b99ee182..0f4c46644 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,11 +130,6 @@ install(FILES postinstall.txt DESTINATION doc/turnserver COMPONENT Runtime) -install(FILES examples/etc/turnserver.conf - DESTINATION ${CMAKE_INSTALL_SYSCONFDIR} - COMPONENT Runtime - RENAME turnserver.conf.default - ) install(DIRECTORY examples DESTINATION share diff --git a/README.md b/README.md index 17aa3bda1..f6b3b8c4a 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Optional - [Hiredis](https://github.com/redis/hiredis) (user database, monitoring) - SQLite (user database) - PostgreSQL (user database) +- [log4cplus](https://github.com/log4cplus/log4cplus) (log library) ### Building ```shell diff --git a/docs/Log.md b/docs/Log.md new file mode 100644 index 000000000..01a16d486 --- /dev/null +++ b/docs/Log.md @@ -0,0 +1,338 @@ +# Log + +This project includes the following two types of log implementations: + +- Use a mature logging library. current use [log4cplus](https://github.com/log4cplus/log4cplus) +- The project is implemented on its own [Discarded] + +See: [Discussions](https://github.com/coturn/coturn/issues/1344) + +## Setup log4cplus + +- System distribution + - Ubuntu + + sudo apt install liblog4cplus-dev + +- Install from source code + - Download [source code](https://github.com/log4cplus/log4cplus) + + git clone https://github.com/log4cplus/log4cplus.git + + - Compile. See: https://github.com/log4cplus/log4cplus + + cd log4cplus + mkdir build + cd build + cmake .. + cmake --build . --traget install + +## Log4cplus configure file + +[Example](../examples/etc/log.conf) + +- Appender + +|Appender |Description | +|:--------------------------:|:------------------:| +|ConsoleAppender |Ouput to console | +|SysLogAppender |Appends log events to a file. | +|NTEventLogAppender |Appends log events to NT EventLog. Only windows| +|FileAppender |Ouput to file | +|RollingFileAppender |Backup the log files when they reach a certain size| +|DailyRollingFileAppender |The log file is rolled over at a user chosen frequency| +|TimeBasedRollingFileAppender|The log file is rolled over at a user chosen frequency while also keeping in check a total maximum number of produced files. | +|SocketAppender |Output to a remote a log server.| +|Log4jUdpAppender |Sends log events as Log4j XML to a remote a log server. | +|AsyncAppender | | + +- Layout + +| Layout | Description | +|:-----------:|:-----------:| +|SimpleLayout |Simple layout| +|TTCCLayout | | +|PatternLayout|Pattern layout| + + - [PatternLayout](https://log4cplus.github.io/log4cplus/docs/log4cplus-2.1.0/doxygen/classlog4cplus_1_1PatternLayout.html#details) + + +The recognized conversion characters are + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Conversion CharacterEffect
bUsed to output file name component of path name. +E.g. main.cxx from path ../../main.cxx.
cUsed to output the logger of the logging event. The +logger conversion specifier can be optionally followed by +precision specifier, that is a decimal constant in +brackets. +If a precision specifier is given, then only the corresponding +number of right most components of the logger name will be +printed. By default the logger name is printed in full. +For example, for the logger name "a.b.c" the pattern +%c{2} will output "b.c". + +
dUsed to output the date of the logging event in UTC. + +The date conversion specifier may be followed by a date format +specifier enclosed between braces. For example, %%d{%%H:%%M:%%s} +or %%d{%%d %%b %%Y %%H:%%M:%%s}. If no date format +specifier is given then %%d{%%d %%m %%Y %%H:%%M:%%s} +is assumed. + +The Following format options are possible: +
    +
  • %%a -- Abbreviated weekday name
  • +
  • %%A -- Full weekday name
  • +
  • %%b -- Abbreviated month name
  • +
  • %%B -- Full month name
  • +
  • %%c -- Standard date and time string
  • +
  • %%d -- Day of month as a decimal(1-31)
  • +
  • %%H -- Hour(0-23)
  • +
  • %%I -- Hour(1-12)
  • +
  • %%j -- Day of year as a decimal(1-366)
  • +
  • %%m -- Month as decimal(1-12)
  • +
  • %%M -- Minute as decimal(0-59)
  • +
  • %%p -- Locale's equivalent of AM or PM
  • +
  • %%q -- milliseconds as decimal(0-999) -- Log4CPLUS specific +
  • %%Q -- fractional milliseconds as decimal(0-999.999) -- Log4CPLUS specific +
  • %%S -- Second as decimal(0-59)
  • +
  • %%U -- Week of year, Sunday being first day(0-53)
  • +
  • %%w -- Weekday as a decimal(0-6, Sunday being 0)
  • +
  • %%W -- Week of year, Monday being first day(0-53)
  • +
  • %%x -- Standard date string
  • +
  • %%X -- Standard time string
  • +
  • %%y -- Year in decimal without century(0-99)
  • +
  • %%Y -- Year including century as decimal
  • +
  • %%Z -- Time zone name
  • +
  • %% -- The percent sign
  • +
+ +Lookup the documentation for the strftime() function +found in the <ctime> header for more information. +
DUsed to output the date of the logging event in local time. + +All of the above information applies. +
EUsed to output the value of a given environment variable. The +name of is supplied as an argument in brackets. If the variable does +exist then empty string will be used. + +For example, the pattern %E{HOME} will output the contents +of the HOME environment variable. +
FUsed to output the file name where the logging request was +issued. + +NOTE Unlike log4j, there is no performance penalty for +calling this method.
hUsed to output the hostname of this system (as returned +by gethostname(2)). + +NOTE The hostname is only retrieved once at +initialization. + +
HUsed to output the fully-qualified domain name of this +system (as returned by gethostbyname(2) for the hostname +returned by gethostname(2)). + +NOTE The hostname is only retrieved once at +initialization. + +
lEquivalent to using "%F:%L" + +NOTE: Unlike log4j, there is no performance penalty for +calling this method. + +
LUsed to output the line number from where the logging request +was issued. + +NOTE: Unlike log4j, there is no performance penalty for +calling this method. + +
mUsed to output the application supplied message associated with +the logging event.
MUsed to output function name using +__FUNCTION__ or similar macro. + +NOTE The __FUNCTION__ macro is not +standard but it is common extension provided by all compilers +(as of 2010). In case it is missing or in case this feature +is disabled using the +LOG4CPLUS_DISABLE_FUNCTION_MACRO macro, %M +expands to an empty string.
nOutputs the platform dependent line separator character or +characters. +
pUsed to output the LogLevel of the logging event.
rUsed to output miliseconds since program start +of the logging event.
tUsed to output the thread ID of the thread that generated +the logging event. (This is either `pthread_t` value returned +by `pthread_self()` on POSIX platforms or thread ID returned +by `GetCurrentThreadId()` on Windows.)
TUsed to output alternative name of the thread that generated the +logging event.
iUsed to output the process ID of the process that generated the +logging event.
xUsed to output the NDC (nested diagnostic context) associated +with the thread that generated the logging event. +
XUsed to output the MDC (mapped diagnostic context) +associated with the thread that generated the logging +event. It takes optional key parameter. Without the key +paramter (%%X), it outputs the whole MDC map. With the key +(%%X{key}), it outputs just the key's value. +
"%%"The sequence "%%" outputs a single percent sign. +
+ + + + - Example + - Default. don't use configure file + +``` +INFO - System cpu num is 4 + +INFO - System enable num is 4 + +WARN - Cannot find config file: turnserver.conf. Default and command-line settings will be used. + +INFO - Coturn Version Coturn-4.6.2 'Gorst' + +INFO - Max number of open files/sockets allowed for this process: 1048576 + +INFO - Due to the open files/sockets limitation, max supported number of TURN Sessions possible is: 524000 (approximately) +``` + + - log4cplus.appender.CONSOLE.layout.ConversionPattern=[%t] %-5p - %m + +``` +[140497062541824] INFO - System cpu num is 4 +[140497062541824] INFO - System enable num is 4 +[140497062541824] WARN - Cannot find config file: turnserver.conf. Default and command-line settings will be used. +[140497062541824] INFO - Coturn Version Coturn-4.6.2 'Gorst' +[140497062541824] INFO - Max number of open files/sockets allowed for this process: 1048576 +[140497062541824] INFO - Due to the open files/sockets limitation, max supported number of TURN Sessions possible is: 524000 (approximately) +``` + + - log4cplus.appender.CONSOLE.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S,%Q} %l [%t] %-5p %c - %m + +``` +2023-12-19 16:47:27,453.057 src/apps/relay/mainrelay.c:2950 [139876171266560] INFO root - System cpu num is 4 +2023-12-19 16:47:27,453.088 src/apps/relay/mainrelay.c:2951 [139876171266560] INFO root - System enable num is 4 +2023-12-19 16:47:27,453.141 src/apps/relay/mainrelay.c:2446 [139876171266560] WARN root - Cannot find config file: turnserver.conf. Default and command-line settings will be used. +2023-12-19 16:47:27,453.223 src/apps/relay/mainrelay.c:2695 [139876171266560] INFO root - Coturn Version Coturn-4.6.2 'Gorst' +2023-12-19 16:47:27,453.228 src/apps/relay/mainrelay.c:2696 [139876171266560] INFO root - Max number of open files/sockets allowed for this process: 1048576 +2023-12-19 16:47:27,453.232 src/apps/relay/mainrelay.c:2704 [139876171266560] INFO root - Due to the open files/sockets limitation, max supported number of TURN Sessions possible is: 524000 (approximately) +``` + diff --git a/examples/etc/log.conf b/examples/etc/log.conf new file mode 100644 index 000000000..99f7a129b --- /dev/null +++ b/examples/etc/log.conf @@ -0,0 +1,18 @@ +logpath=log + +log4cplus.appender.CONSOLE=log4cplus::ConsoleAppender +log4cplus.appender.CONSOLE.Append=true +# Layout. See: https://github.com/log4cplus/log4cplus/blob/master/include/log4cplus/layout.h +log4cplus.appender.CONSOLE.layout=log4cplus::PatternLayout +log4cplus.appender.CONSOLE.layout.ConversionPattern=[%t] %-5p - %m +#log4cplus.appender.CONSOLE.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S,%Q} %l [%t] %-5p %c - %m + +log4cplus.appender.FILE=log4cplus::DailyRollingFileAppender +log4cplus.appender.FILE.File=../log/error.log +log4cplus.appender.FILE.Schedule=HOURLY +log4cplus.appender.FILE.Append=true +# Layout. See: https://github.com/log4cplus/log4cplus/blob/master/include/log4cplus/layout.h +log4cplus.appender.FILE.layout=log4cplus::PatternLayout +log4cplus.appender.FILE.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S,%Q} [%t] %-5p %c - %m + +log4cplus.rootLogger=ALL, CONSOLE, FILE diff --git a/examples/etc/turnserver.conf b/examples/etc/turnserver.conf index 3f7e42877..b3206de15 100644 --- a/examples/etc/turnserver.conf +++ b/examples/etc/turnserver.conf @@ -506,6 +506,9 @@ # #dh-file= +# log configure file +#log-conf-file=/etc/turnserver/log.conf + # Flag to prevent stdout log messages. # By default, all log messages go to both stdout and to # the configured log file. With this option everything will diff --git a/man/man1/turnserver.1 b/man/man1/turnserver.1 index 993206896..ea3b4e99a 100644 --- a/man/man1/turnserver.1 +++ b/man/man1/turnserver.1 @@ -337,6 +337,10 @@ Do not allow TCP relay endpoints defined in RFC 6062, use only UDP relay endpoints as defined in RFC 5766. .TP .B +\fB\-\-log-conf-file\fP +Set the full path name of the log configure file. +.TP +.B \fB\-\-no\-stdout\-log\fP Flag to prevent stdout log messages. By default, all log messages are going to both stdout and to diff --git a/src/apps/common/CMakeLists.txt b/src/apps/common/CMakeLists.txt index 124579013..68b1d8a83 100644 --- a/src/apps/common/CMakeLists.txt +++ b/src/apps/common/CMakeLists.txt @@ -50,6 +50,18 @@ else() endif() endif() +find_package(log4cplus) +if(log4cplus_FOUND) + list(APPEND COMMON_LIBS log4cplus::log4cplus) + list(APPEND COMMON_DEFINED HAS_LOG4CPLUS) + list(APPEND SOURCE_FILES log4cplus.cpp) + install(FILES ${CMAKE_SOURCE_DIR}/examples/etc/log.conf + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR} + COMPONENT Runtime + RENAME turnserver_log.conf + ) +endif() + find_package(hiredis) if(hiredis_FOUND) list(APPEND SOURCE_FILES hiredis_libevent2.c) diff --git a/src/apps/common/log4cplus.cpp b/src/apps/common/log4cplus.cpp new file mode 100644 index 000000000..3ad886e2e --- /dev/null +++ b/src/apps/common/log4cplus.cpp @@ -0,0 +1,69 @@ +#include "ns_turn_utils.h" +#include +#include +#include + +using namespace log4cplus; +using namespace log4cplus::helpers; + +void *turn_log_init() { + int ret = -1; + void *log = log4cplus_initialize(); + const char *file = "../etc/turnserver_log.conf"; + FILE *pf = fopen(file, "a"); + if (pf) { + fclose(pf); + ret = log4cplus_file_configure(file); + } + if (ret) + log4cplus_basic_reconfigure(1); + return log; +} + +void turn_log_clean(void *log) { log4cplus_deinitialize(log); } + +int turn_log_set_conf_file(const char *file) { return log4cplus_file_reconfigure(file); } + +LogLevel turn_level_to_loglevel(TURN_LOG_LEVEL level) { + switch ((int)level) { + case TURN_LOG_LEVEL_DEBUG: + return DEBUG_LOG_LEVEL; + case TURN_LOG_LEVEL_INFO: + return INFO_LOG_LEVEL; + case TURN_LOG_LEVEL_WARNING: + return WARN_LOG_LEVEL; + case TURN_LOG_LEVEL_ERROR: + return ERROR_LOG_LEVEL; + } + return DEBUG_LOG_LEVEL; +} + +void turn_log_func_default(const char *file, int line, const char *f, char *category, TURN_LOG_LEVEL level, + const char *msgfmt, ...) { + int retval = -1; + + try { + Logger logger = category ? Logger::getInstance(category) : Logger::getRoot(); + LogLevel ll = turn_level_to_loglevel(level); + + if (logger.isEnabledFor(ll)) { + const tchar *msg = nullptr; + snprintf_buf buf; + std::va_list ap; + + do { + va_start(ap, msgfmt); + retval = buf.print_va_list(msg, msgfmt, ap); + va_end(ap); + } while (retval == -1); + + logger.forcedLog(ll, msg, file, line, f); + } + + } catch (std::exception const &e) { + // Fall through. + printf("logger.forcedLog exception: %s", e.what()); + } + + return; +} diff --git a/src/apps/common/ns_turn_utils.c b/src/apps/common/ns_turn_utils.c index 8d14c5bea..5f0e9cb24 100644 --- a/src/apps/common/ns_turn_utils.c +++ b/src/apps/common/ns_turn_utils.c @@ -504,8 +504,6 @@ void rollover_logfile(void) { static int get_syslog_level(TURN_LOG_LEVEL level) { #if defined(__unix__) || defined(unix) || defined(__APPLE__) switch (level) { - case TURN_LOG_LEVEL_CONTROL: - return LOG_NOTICE; case TURN_LOG_LEVEL_WARNING: return LOG_WARNING; case TURN_LOG_LEVEL_ERROR: @@ -526,7 +524,15 @@ void err(int eval, const char *format, ...) { } #endif -void turn_log_func_default(char *file, int line, TURN_LOG_LEVEL level, const char *format, ...) { +#if !defined(HAS_LOG4CPLUS) +void *turn_log_init() { return NULL; } + +void turn_log_clean(void *log) {} + +int turn_log_set_conf_file(const char *file) { return 0; } + +void turn_log_func_default(const char *file, int line, const char *f, char *category, TURN_LOG_LEVEL level, + const char *format, ...) { va_list args; va_start(args, format); #if defined(TURN_LOG_FUNC_IMPL) @@ -543,30 +549,39 @@ void turn_log_func_default(char *file, int line, TURN_LOG_LEVEL level, const cha so_far += snprintf(s, sizeof(s), "%lu: ", (unsigned long)log_time()); } +#if defined(WINDOWS) || defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(__CYGWIN64__) + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "[%lu:%lu] ", GetCurrentProcessId(), + GetCurrentThreadId()); +#else + #ifdef SYS_gettid - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "(%lu): ", (unsigned long)gettid()); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "[%lu] ", (unsigned long)gettid()); +#endif + #endif if (_log_file_line_set) - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "%s(%d):", file, line); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "%s(%d)", file, line); switch (level) { case TURN_LOG_LEVEL_DEBUG: - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "DEBUG: "); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "DEBUG"); break; case TURN_LOG_LEVEL_INFO: - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "INFO: "); - break; - case TURN_LOG_LEVEL_CONTROL: - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "CONTROL: "); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "INFO"); break; case TURN_LOG_LEVEL_WARNING: - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "WARNING: "); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "WARNING"); break; case TURN_LOG_LEVEL_ERROR: - so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "ERROR: "); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), "ERROR"); break; } + + if (category && strcmp(category, "")) + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), " %s", category); + so_far += snprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), ": "); + so_far += vsnprintf(s + so_far, MAX_RTPPRINTF_BUFFER_SIZE - (so_far + 1), format, args); if (so_far > MAX_RTPPRINTF_BUFFER_SIZE + 1) { @@ -598,6 +613,7 @@ void turn_log_func_default(char *file, int line, TURN_LOG_LEVEL level, const cha #endif va_end(args); } +#endif // !defined(HAS_LOG4CPLUS) ///////////// ORIGIN /////////////////// diff --git a/src/apps/common/ns_turn_utils.h b/src/apps/common/ns_turn_utils.h index de6d43c80..1819aed00 100644 --- a/src/apps/common/ns_turn_utils.h +++ b/src/apps/common/ns_turn_utils.h @@ -31,8 +31,10 @@ #ifndef __TURN_ULIB__ #define __TURN_ULIB__ +#define TURN_LOG_CATEGORY(category, level, ...) \ + turn_log_func_default(__FILE__, __LINE__, __FUNCTION__, category, level, __VA_ARGS__) #if !defined(TURN_LOG_FUNC) -#define TURN_LOG_FUNC(level, ...) turn_log_func_default(__FILE__, __LINE__, level, __VA_ARGS__) +#define TURN_LOG_FUNC(level, ...) TURN_LOG_CATEGORY(NULL, level, __VA_ARGS__) #endif #if defined(WINDOWS) @@ -52,7 +54,6 @@ extern "C" { typedef enum { TURN_LOG_LEVEL_DEBUG = 0, TURN_LOG_LEVEL_INFO, - TURN_LOG_LEVEL_CONTROL, TURN_LOG_LEVEL_WARNING, TURN_LOG_LEVEL_ERROR } TURN_LOG_LEVEL; @@ -71,9 +72,13 @@ void set_syslog_facility(char *val); void set_turn_log_timestamp_format(char *new_format); -void turn_log_func_default(char *file, int line, TURN_LOG_LEVEL level, const char *format, ...) +/*! + * \note User don't use it. please use TURN_LOG_CATEGORY + */ +void turn_log_func_default(const char *file, int line, const char *f, char *category, TURN_LOG_LEVEL level, + const char *format, ...) #ifdef __GNUC__ - __attribute__((format(printf, 4, 5))) + __attribute__((format(printf, 6, 7))) #endif ; @@ -84,6 +89,10 @@ extern volatile int _log_time_value_set; extern volatile turn_time_t _log_time_value; extern int use_new_log_timestamp_format; +void *turn_log_init(); +void turn_log_clean(void *log); +int turn_log_set_conf_file(const char *file); + void rtpprintf(const char *format, ...); void reset_rtpprintf(void); void set_logfile(const char *fn); @@ -96,9 +105,11 @@ int is_secure_string(const uint8_t *string, int sanitizesql); /////////////////////////////////////////////////////// +#ifndef __cplusplus #if !defined(min) #define min(a, b) ((a) <= (b) ? (a) : (b)) #endif +#endif #ifdef __cplusplus } diff --git a/src/apps/natdiscovery/natdiscovery.c b/src/apps/natdiscovery/natdiscovery.c index bf0e0ab8e..868828ec1 100644 --- a/src/apps/natdiscovery/natdiscovery.c +++ b/src/apps/natdiscovery/natdiscovery.c @@ -632,6 +632,7 @@ int main(int argc, char **argv) { int first = 1; ioa_addr other_addr, reflexive_addr, tmp_addr, remote_addr, local_addr, local2_addr; + void *log = turn_log_init(); if (socket_init()) return -1; @@ -814,5 +815,7 @@ int main(int argc, char **argv) { socket_closesocket(udp_fd); socket_closesocket(udp_fd2); + turn_log_clean(log); + return 0; } diff --git a/src/apps/oauth/oauth.c b/src/apps/oauth/oauth.c index 40e315ddc..24a0c7d9d 100644 --- a/src/apps/oauth/oauth.c +++ b/src/apps/oauth/oauth.c @@ -195,6 +195,7 @@ const char Usage[] = ////////////////////////////////////////////////// int main(int argc, char **argv) { + void *log = turn_log_init(); oauth_key key; @@ -469,5 +470,6 @@ int main(int argc, char **argv) { } } + turn_log_clean(log); return 0; } diff --git a/src/apps/peer/mainudpserver.c b/src/apps/peer/mainudpserver.c index c8ef9f3aa..af1a752f8 100644 --- a/src/apps/peer/mainudpserver.c +++ b/src/apps/peer/mainudpserver.c @@ -61,6 +61,8 @@ int main(int argc, char **argv) { int c; char ifname[1025] = "\0"; + void *log = turn_log_init(); + if (socket_init()) return -1; @@ -101,5 +103,6 @@ int main(int argc, char **argv) { run_udp_server(server); clean_udp_server(server); + turn_log_clean(log); return 0; } diff --git a/src/apps/relay/CMakeLists.txt b/src/apps/relay/CMakeLists.txt index a6a6468fe..9c5d27362 100644 --- a/src/apps/relay/CMakeLists.txt +++ b/src/apps/relay/CMakeLists.txt @@ -165,3 +165,9 @@ else() COMPONENT Runtime ) endif() + +install(FILES ${CMAKE_SOURCE_DIR}/examples/etc/turnserver.conf + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR} + COMPONENT Runtime + RENAME turnserver.conf.default + ) diff --git a/src/apps/relay/mainrelay.c b/src/apps/relay/mainrelay.c index 88ed1e07f..29d4ff38f 100644 --- a/src/apps/relay/mainrelay.c +++ b/src/apps/relay/mainrelay.c @@ -32,6 +32,7 @@ #include "dbdrivers/dbdriver.h" #include "prom_server.h" +#include #if defined(WINDOWS) #include @@ -1141,6 +1142,9 @@ static char Usage[] = " -l, --log-file Option to set the full path name of the log file.\n" " By default, the turnserver tries to open a log file in\n" " /var/log/turnserver/, /var/log, /var/tmp, /tmp and . (current) " + " --log-conf-file Option to set the full path name of the log configure file.\n" + " By default, the turnserver tries to open a log configure file in\n" + " /etc/turnserver/log.conf and ./log.conf (current) " "directories\n" " (which open operation succeeds first that file will be used).\n" " With this option you can set the definite log file name.\n" @@ -1374,6 +1378,7 @@ enum EXTRA_OPTS { DEL_ALL_AUTH_SECRETS_OPT, STATIC_AUTH_SECRET_VAL_OPT, AUTH_SECRET_TS_EXP, /* deprecated */ + LOG_CONF_FILE, NO_STDOUT_LOG_OPT, SYSLOG_OPT, SYSLOG_FACILITY_OPT, @@ -1524,6 +1529,7 @@ static const struct myoption long_options[] = { {"pkey", required_argument, NULL, PKEY_FILE_OPT}, {"pkey-pwd", required_argument, NULL, PKEY_PWD_OPT}, {"log-file", required_argument, NULL, 'l'}, + {"log-conf-file", optional_argument, NULL, LOG_CONF_FILE}, {"no-stdout-log", optional_argument, NULL, NO_STDOUT_LOG_OPT}, {"syslog", optional_argument, NULL, SYSLOG_OPT}, {"simple-log", optional_argument, NULL, SIMPLE_LOG_OPT}, @@ -2276,6 +2282,7 @@ static void set_option(int c, char *value) { /* these options have been already taken care of before: */ case 'l': + case LOG_CONF_FILE: case NO_STDOUT_LOG_OPT: case SYSLOG_OPT: case SIMPLE_LOG_OPT: @@ -2408,6 +2415,8 @@ static void read_config_file(int argc, char **argv, int pass) { TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "Bad configuration format: %s\n", sarg); } else if ((pass == 0) && (c == 'l')) { set_logfile(value); + } else if ((pass == 0) && (c == LOG_CONF_FILE)) { + turn_log_set_conf_file(value); } else if ((pass == 0) && (c == NO_STDOUT_LOG_OPT)) { set_no_stdout_log(get_bool_value(value)); } else if ((pass == 0) && (c == SYSLOG_OPT)) { @@ -2859,6 +2868,7 @@ static void init_domain(void) { int main(int argc, char **argv) { int c = 0; + void *log = turn_log_init(); IS_TURN_SERVER = 1; TURN_MUTEX_INIT(&turn_params.tls_mutex); @@ -2890,6 +2900,9 @@ int main(int argc, char **argv) { case 'l': set_logfile(optarg); break; + case LOG_CONF_FILE: + turn_log_set_conf_file(optarg); + break; case NO_STDOUT_LOG_OPT: set_no_stdout_log(get_bool_value(optarg)); break; @@ -3239,6 +3252,7 @@ int main(int argc, char **argv) { disconnect_database(); + turn_log_clean(log); return 0; } diff --git a/src/apps/rfc5769/rfc5769check.c b/src/apps/rfc5769/rfc5769check.c index d8ec7ed01..e550f887c 100644 --- a/src/apps/rfc5769/rfc5769check.c +++ b/src/apps/rfc5769/rfc5769check.c @@ -197,6 +197,8 @@ static SHATYPE shatype = SHATYPE_SHA1; int main(int argc, const char **argv) { int res = -1; + void *log = turn_log_init(); + UNUSED_ARG(argc); UNUSED_ARG(argv); @@ -561,5 +563,7 @@ int main(int argc, const char **argv) { exit(-1); } + turn_log_clean(log); + return 0; } diff --git a/src/apps/stunclient/stunclient.c b/src/apps/stunclient/stunclient.c index 3c3b32fb3..e7760e6b4 100644 --- a/src/apps/stunclient/stunclient.c +++ b/src/apps/stunclient/stunclient.c @@ -417,6 +417,8 @@ int main(int argc, char **argv) { int c = 0; int forceRfc5780 = 0; + void *log = turn_log_init(); + if (socket_init()) return -1; @@ -468,5 +470,6 @@ int main(int argc, char **argv) { socket_closesocket(udp_fd); + turn_log_clean(log); return 0; } diff --git a/src/apps/uclient/mainuclient.c b/src/apps/uclient/mainuclient.c index d8bd1cc9e..df2f7ad4f 100644 --- a/src/apps/uclient/mainuclient.c +++ b/src/apps/uclient/mainuclient.c @@ -170,6 +170,8 @@ int main(int argc, char **argv) { char rest_api_separator = ':'; int use_null_cipher = 0; + void *log = turn_log_init(); + #if defined(WINDOWS) WORD wVersionRequested; @@ -579,5 +581,6 @@ int main(int argc, char **argv) { start_mclient(argv[optind], port, client_ifname, local_addr, messagenumber, mclient); + turn_log_clean(log); return 0; } diff --git a/vcpkg.json b/vcpkg.json index 7f235cffb..563cf8b77 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,10 +11,10 @@ "features": [ "openssl", "thread" ] }, "openssl", + "log4cplus", "sqlite3", "libpq", "hiredis", "mongo-c-driver" ] - }