From 62f2bd4b2ea2ce7c41be0ba60439861c735595d2 Mon Sep 17 00:00:00 2001 From: Kang Lin Date: Mon, 18 Dec 2023 10:35:47 +0800 Subject: [PATCH] Use log4cplus (#1344) --- .github/workflows/cmake.yaml | 3 +- .github/workflows/msvc.yml | 2 +- CMakeLists.txt | 5 - README.md | 1 + docs/Log.md | 296 +++++++++++++++++++++++++++ examples/etc/log.conf | 18 ++ examples/etc/turnserver.conf | 3 + src/apps/common/CMakeLists.txt | 11 + src/apps/common/log4cplus.cpp | 79 +++++++ src/apps/common/ns_turn_utils.c | 42 ++-- src/apps/common/ns_turn_utils.h | 15 +- src/apps/natdiscovery/natdiscovery.c | 5 +- src/apps/oauth/oauth.c | 6 +- src/apps/peer/mainudpserver.c | 7 +- src/apps/relay/CMakeLists.txt | 6 + src/apps/relay/mainrelay.c | 18 +- src/apps/rfc5769/rfc5769check.c | 6 +- src/apps/stunclient/stunclient.c | 7 +- src/apps/uclient/mainuclient.c | 5 +- vcpkg.json | 2 +- 20 files changed, 499 insertions(+), 38 deletions(-) create mode 100644 docs/Log.md create mode 100644 examples/etc/log.conf create mode 100644 src/apps/common/log4cplus.cpp 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..7ccb73a55 --- /dev/null +++ b/docs/Log.md @@ -0,0 +1,296 @@ +# 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. +
diff --git a/examples/etc/log.conf b/examples/etc/log.conf new file mode 100644 index 000000000..8c75c6f05 --- /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=${logpath}/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/src/apps/common/CMakeLists.txt b/src/apps/common/CMakeLists.txt index 124579013..5c8ba8765 100644 --- a/src/apps/common/CMakeLists.txt +++ b/src/apps/common/CMakeLists.txt @@ -50,6 +50,17 @@ 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 + ) +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..857708c99 --- /dev/null +++ b/src/apps/common/log4cplus.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include "ns_turn_utils.h" + +using namespace log4cplus; +using namespace log4cplus::helpers; + +void* turn_log_init(){ + int ret = -1; + void* log = log4cplus_initialize(); + const char* file = "../etc/log4cplus.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(char *file, int line, char* function, 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, function); + } + + } + 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..53ca9b272 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,11 @@ 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){} +void turn_log_func_default(char *file, int line, char *category, TURN_LOG_LEVEL level, const char *format, ...) { va_list args; va_start(args, format); #if defined(TURN_LOG_FUNC_IMPL) @@ -543,32 +545,41 @@ 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) { so_far = MAX_RTPPRINTF_BUFFER_SIZE + 1; } @@ -584,7 +595,7 @@ void turn_log_func_default(char *file, int line, TURN_LOG_LEVEL level, const cha #else syslog(syslog_facility | get_syslog_level(level), "%s", s); #endif - + } else { log_lock(); set_rtpfile(); @@ -598,6 +609,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..1310855ca 100644 --- a/src/apps/common/ns_turn_utils.h +++ b/src/apps/common/ns_turn_utils.h @@ -31,8 +31,9 @@ #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 +53,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 +71,12 @@ 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(char *file, int line, char* function, char *category, TURN_LOG_LEVEL level, const char *format, ...) #ifdef __GNUC__ - __attribute__((format(printf, 4, 5))) + __attribute__((format(printf, 6, 7))) #endif ; @@ -84,6 +87,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); diff --git a/src/apps/natdiscovery/natdiscovery.c b/src/apps/natdiscovery/natdiscovery.c index bf0e0ab8e..39655a35c 100644 --- a/src/apps/natdiscovery/natdiscovery.c +++ b/src/apps/natdiscovery/natdiscovery.c @@ -631,7 +631,8 @@ int main(int argc, char **argv) { int rfc5780; 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..41b6dab13 100644 --- a/src/apps/oauth/oauth.c +++ b/src/apps/oauth/oauth.c @@ -195,7 +195,8 @@ const char Usage[] = ////////////////////////////////////////////////// int main(int argc, char **argv) { - + void* log = turn_log_init(); + oauth_key key; // init vars with default values @@ -468,6 +469,7 @@ int main(int argc, char **argv) { exit(-1); } } - + + turn_log_clean(log); return 0; } diff --git a/src/apps/peer/mainudpserver.c b/src/apps/peer/mainudpserver.c index c8ef9f3aa..344fd3e0f 100644 --- a/src/apps/peer/mainudpserver.c +++ b/src/apps/peer/mainudpserver.c @@ -60,7 +60,9 @@ int main(int argc, char **argv) { int verbose = TURN_VERBOSE_NONE; int c; char ifname[1025] = "\0"; - + + void* log = turn_log_init(); + if (socket_init()) return -1; @@ -100,6 +102,7 @@ int main(int argc, char **argv) { server_type *server = start_udp_server(verbose, ifname, local_addr_list, las, port); 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..f23efdca9 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 configure log file.\n" + " By default, the turnserver tries to open a configure log 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)) { @@ -2858,7 +2867,8 @@ 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; @@ -3238,7 +3251,8 @@ int main(int argc, char **argv) { run_listener_server(&(turn_params.listener)); disconnect_database(); - + + turn_log_clean(log); return 0; } diff --git a/src/apps/rfc5769/rfc5769check.c b/src/apps/rfc5769/rfc5769check.c index d8ec7ed01..b5430fbae 100644 --- a/src/apps/rfc5769/rfc5769check.c +++ b/src/apps/rfc5769/rfc5769check.c @@ -196,7 +196,9 @@ 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); @@ -560,6 +562,8 @@ int main(int argc, const char **argv) { if (check_oauth() < 0) exit(-1); } + + turn_log_clean(log); return 0; } diff --git a/src/apps/stunclient/stunclient.c b/src/apps/stunclient/stunclient.c index 3c3b32fb3..b1ee12813 100644 --- a/src/apps/stunclient/stunclient.c +++ b/src/apps/stunclient/stunclient.c @@ -416,7 +416,9 @@ int main(int argc, char **argv) { char local_addr[256] = "\0"; int c = 0; int forceRfc5780 = 0; - + + void* log = turn_log_init(); + if (socket_init()) return -1; @@ -467,6 +469,7 @@ 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..178122431 100644 --- a/src/apps/uclient/mainuclient.c +++ b/src/apps/uclient/mainuclient.c @@ -169,6 +169,8 @@ int main(int argc, char **argv) { char rest_api_separator = ':'; int use_null_cipher = 0; + + void* log = turn_log_init(); #if defined(WINDOWS) @@ -578,6 +580,7 @@ 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" ] - }