Skip to content

Commit

Permalink
Log: Use log4cplus (coturn#1344)
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Dec 19, 2023
1 parent 1c7171b commit 996aece
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
296 changes: 296 additions & 0 deletions docs/Log.md
Original file line number Diff line number Diff line change
@@ -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

<table>
<tr>
<td>Conversion Character</td>
<td>Effect</td>
</tr>
<tr>
<td align=center><b>b</b></td>
<td>Used to output file name component of path name.
E.g. <tt>main.cxx</tt> from path <tt>../../main.cxx</tt>.</td>
</tr>
<tr>
<td align=center><b>c</b></td>

<td>Used to output the logger of the logging event. The
logger conversion specifier can be optionally followed by
<em>precision specifier</em>, 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
<b>%c{2}</b> will output "b.c".

</td>
</tr>

<tr>
<td align=center><b>d</b></td>

<td>Used to output the date of the logging event in <b>UTC</b>.

The date conversion specifier may be followed by a <em>date format
specifier</em> enclosed between braces. For example, <b>%%d{%%H:%%M:%%s}</b>
or <b>%%d{%%d&nbsp;%%b&nbsp;%%Y&nbsp;%%H:%%M:%%s}</b>. If no date format
specifier is given then <b>%%d{%%d&nbsp;%%m&nbsp;%%Y&nbsp;%%H:%%M:%%s}</b>
is assumed.

The Following format options are possible:
<ul>
<li>%%a -- Abbreviated weekday name</li>
<li>%%A -- Full weekday name</li>
<li>%%b -- Abbreviated month name</li>
<li>%%B -- Full month name</li>
<li>%%c -- Standard date and time string</li>
<li>%%d -- Day of month as a decimal(1-31)</li>
<li>%%H -- Hour(0-23)</li>
<li>%%I -- Hour(1-12)</li>
<li>%%j -- Day of year as a decimal(1-366)</li>
<li>%%m -- Month as decimal(1-12)</li>
<li>%%M -- Minute as decimal(0-59)</li>
<li>%%p -- Locale's equivalent of AM or PM</li>
<li>%%q -- milliseconds as decimal(0-999) -- <b>Log4CPLUS specific</b>
<li>%%Q -- fractional milliseconds as decimal(0-999.999) -- <b>Log4CPLUS specific</b>
<li>%%S -- Second as decimal(0-59)</li>
<li>%%U -- Week of year, Sunday being first day(0-53)</li>
<li>%%w -- Weekday as a decimal(0-6, Sunday being 0)</li>
<li>%%W -- Week of year, Monday being first day(0-53)</li>
<li>%%x -- Standard date string</li>
<li>%%X -- Standard time string</li>
<li>%%y -- Year in decimal without century(0-99)</li>
<li>%%Y -- Year including century as decimal</li>
<li>%%Z -- Time zone name</li>
<li>%% -- The percent sign</li>
</ul>

Lookup the documentation for the <code>strftime()</code> function
found in the <code>&lt;ctime&gt;</code> header for more information.
</td>
</tr>

<tr>
<td align=center><b>D</b></td>

<td>Used to output the date of the logging event in <b>local</b> time.

All of the above information applies.
</td>
</tr>

<tr>
<td align=center><b>E</b></td>

<td>Used 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 <b>%E{HOME}</b> will output the contents
of the HOME environment variable.
</td>
</tr>

<tr>
<td align=center><b>F</b></td>

<td>Used to output the file name where the logging request was
issued.

<b>NOTE</b> Unlike log4j, there is no performance penalty for
calling this method.</td>
</tr>

<tr>
<td align=center><b>h</b></td>

<td>Used to output the hostname of this system (as returned
by gethostname(2)).

<b>NOTE</b> The hostname is only retrieved once at
initialization.

</td>
</tr>

<tr>
<td align=center><b>H</b></td>

<td>Used to output the fully-qualified domain name of this
system (as returned by gethostbyname(2) for the hostname
returned by gethostname(2)).

<b>NOTE</b> The hostname is only retrieved once at
initialization.

</td>
</tr>

<tr>
<td align=center><b>l</b></td>

<td>Equivalent to using "%F:%L"

<b>NOTE:</b> Unlike log4j, there is no performance penalty for
calling this method.

</td>
</tr>

<tr>
<td align=center><b>L</b></td>

<td>Used to output the line number from where the logging request
was issued.

<b>NOTE:</b> Unlike log4j, there is no performance penalty for
calling this method.

</tr>

<tr>
<td align=center><b>m</b></td>
<td>Used to output the application supplied message associated with
the logging event.</td>
</tr>

<tr>
<td align=center><b>M</b></td>

<td>Used to output function name using
<code>__FUNCTION__</code> or similar macro.

<b>NOTE</b> The <code>__FUNCTION__</code> 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
<code>LOG4CPLUS_DISABLE_FUNCTION_MACRO</code> macro, %M
expands to an empty string.</td>
</tr>

<tr>
<td align=center><b>n</b></td>

<td>Outputs the platform dependent line separator character or
characters.
</tr>

<tr>
<td align=center><b>p</b></td>
<td>Used to output the LogLevel of the logging event.</td>
</tr>

<tr>
<td align=center><b>r</b></td>
<td>Used to output miliseconds since program start
of the logging event.</td>
</tr>

<tr>
<td align=center><b>t</b></td>

<td>Used 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.)</td>
</tr>

<tr>
<td align=center><b>T</b></td>

<td>Used to output alternative name of the thread that generated the
logging event.</td>
</tr>

<tr>
<td align=center><b>i</b></td>

<td>Used to output the process ID of the process that generated the
logging event.</td>
</tr>

<tr>
<td align=center><b>x</b></td>

<td>Used to output the NDC (nested diagnostic context) associated
with the thread that generated the logging event.
</td>
</tr>

<tr>
<td align=center><b>X</b></td>

<td>Used 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.
</td>
</tr>

<tr>
<td align=center><b>"%%"</b></td>
<td>The sequence "%%" outputs a single percent sign.
</td>
</tr>

</table>
18 changes: 18 additions & 0 deletions examples/etc/log.conf
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/etc/turnserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@
#
#dh-file=<DH-PEM-file-name>

# 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
Expand Down
4 changes: 4 additions & 0 deletions man/man1/turnserver.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/apps/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 996aece

Please sign in to comment.