From 1787c9385e2f9b706d420a2f26db959471d28251 Mon Sep 17 00:00:00 2001 From: Kang Lin Date: Mon, 18 Dec 2023 10:35:47 +0800 Subject: [PATCH] Use log4cplus(#1344) --- CMakeLists.txt | 5 - docs/Log.md | 424 +++++++++++++++++++++++++++ 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/relay/CMakeLists.txt | 6 + src/apps/relay/mainrelay.c | 18 +- vcpkg.json | 1 + 12 files changed, 600 insertions(+), 27 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/CMakeLists.txt b/CMakeLists.txt index 3b99ee1829..0f4c46644c 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/docs/Log.md b/docs/Log.md new file mode 100644 index 0000000000..85d5466d6f --- /dev/null +++ b/docs/Log.md @@ -0,0 +1,424 @@ +# 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 .. -DCMAKE_INSTALL_PREFIX=`pwd`/install + 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) + +A flexible layout configurable with pattern string. + +The goal of this class is to format a InternalLoggingEvent and return the results as a string. The results depend on the conversion pattern. + +The conversion pattern is closely related to the conversion pattern of the printf function in C. A conversion pattern is composed of literal text and format control expressions called conversion specifiers. + +You are free to insert any literal text within the conversion pattern. + +Each conversion specifier starts with a percent sign (%%) and is followed by optional format modifiers and a conversion character. The conversion character specifies the type of data, e.g. Logger, LogLevel, date, thread name. The format modifiers control such things as field width, padding, left and right justification. The following is a simple example. + +Let the conversion pattern be "%-5p [%t]: %m%n" and assume that the log4cplus environment was set to use a PatternLayout. Then the statements + +``` +Logger root = Logger.getRoot(); +LOG4CPLUS_DEBUG(root, "Message 1"); +LOG4CPLUS_WARN(root, "Message 2"); +``` + +would yield the output: + +``` +DEBUG [main]: Message 1 +WARN [main]: Message 2 +``` + +Note that there is no explicit separator between text and conversion specifiers. The pattern parser knows when it has reached the end of a conversion specifier when it reads a conversion character. In the example above the conversion specifier "%-5p" means the LogLevel of the logging event should be left justified to a width of five characters. + +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. +
+ +By default the relevant information is output as is. However, with the aid of format modifiers it is possible to change the minimum field width, the maximum field width and justification. + +The optional format modifier is placed between the percent sign and the conversion character. + +The first optional format modifier is the left justification flag which is just the minus (-) character. Then comes the optional minimum field width modifier. This is a decimal constant that represents the minimum number of characters to output. If the data item requires fewer characters, it is padded on either the left or the right until the minimum width is reached. The default is to pad on the left (right justify) but you can specify right padding with the left justification flag. The padding character is space. If the data item is larger than the minimum field width, the field is expanded to accommodate the data. The value is never truncated. + +This behavior can be changed using the maximum field width modifier which is designated by a period followed by a decimal constant. If the data item is longer than the maximum field, then the extra characters are removed from the beginning of the data item and not from the end. For example, it the maximum field width is eight and the data item is ten characters long, then the first two characters of the data item are dropped. This behavior deviates from the printf function in C where truncation is done from the end. + +Below are various format modifier examples for the logger conversion specifier. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Format modifierleft justifyminimum widthmaximum widthcomment
%20cfalse20noneLeft pad with spaces if the logger name is less than 20 +characters long. +
%-20c true 20 none Right pad with +spaces if the logger name is less than 20 characters long. +
%.30cNAnone30Truncate from the beginning if the logger name is longer than 30 +characters. +
%20.30cfalse2030Left pad with spaces if the logger name is shorter than 20 +characters. However, if logger name is longer than 30 characters, +then truncate from the beginning. +
%-20.30ctrue2030Right pad with spaces if the logger name is shorter than 20 +characters. However, if logger name is longer than 30 characters, +then truncate from the beginning. +
+ +Below are some examples of conversion patterns. + +
+ +
"%r [%t] %-5p %c %x - %m%n" +
This is essentially the TTCC layout. + +
"%-6r [%15.15t] %-5p %30.30c %x - %m%n" + +
Similar to the TTCC layout except that the relative time is +right padded if less than 6 digits, thread name is right padded if +less than 15 characters and truncated if longer and the logger +name is left padded if shorter than 30 characters and truncated if +longer. + +
+ +The above text is largely inspired from Peter A. Darnell and +Philip E. Margolis' highly recommended book "C -- a Software +Engineering Approach", ISBN 0-387-97389-3. + +

Properties

+ +
+
NDCMaxDepth
+
This property limits how many deepest NDC components will +be printed by %%x specifier.
+ +
ConversionPattern
+
This property specifies conversion pattern.
+
+ diff --git a/examples/etc/log.conf b/examples/etc/log.conf new file mode 100644 index 0000000000..8c75c6f055 --- /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 3f7e42877b..b3206de15f 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 1245790137..5c8ba87650 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 0000000000..857708c99f --- /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 8d14c5beab..9bedcea8d9 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*){} +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 de6d43c80a..43fe330415 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*); +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 bf0e0ab8e1..39655a35cc 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/relay/CMakeLists.txt b/src/apps/relay/CMakeLists.txt index a6a6468fed..9c5d273625 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 88ed1e07f0..f23efdca9f 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/vcpkg.json b/vcpkg.json index 7f235cffb9..797ce406c6 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,6 +11,7 @@ "features": [ "openssl", "thread" ] }, "openssl", + "log4cplus", "sqlite3", "libpq", "hiredis",