Skip to content

Commit

Permalink
Fix ossrs#3218: Log: Follow Java/log4j log level specs. v5.0.83
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Oct 26, 2022
1 parent 20c38e0 commit 2aa2a42
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 18 deletions.
5 changes: 5 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ if [ $SRS_LOG_TRACE = YES ]; then
else
srs_undefine_macro "SRS_TRACE" $SRS_AUTO_HEADERS_H
fi
if [ $SRS_LOG_NEW_LEVEL = YES ]; then
srs_define_macro "SRS_LOG_NEW_LEVEL" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_LOG_NEW_LEVEL" $SRS_AUTO_HEADERS_H
fi
if [ $SRS_CROSS_BUILD = YES ]; then
srs_define_macro "SRS_CROSSBUILD" $SRS_AUTO_HEADERS_H
else
Expand Down
5 changes: 5 additions & 0 deletions trunk/auto/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ SRS_GCOV=NO
SRS_LOG_VERBOSE=NO
SRS_LOG_INFO=NO
SRS_LOG_TRACE=YES
# Whether use new level definition, see https://stackoverflow.com/a/2031209/17679565
SRS_LOG_NEW_LEVEL=YES
#
################################################################
# Experts options.
Expand Down Expand Up @@ -143,6 +145,7 @@ Features:
--log-verbose=on|off Whether enable the log verbose level. Default: $(value2switch $SRS_LOG_VERBOSE)
--log-info=on|off Whether enable the log info level. Default: $(value2switch $SRS_LOG_INFO)
--log-trace=on|off Whether enable the log trace level. Default: $(value2switch $SRS_LOG_TRACE)
--log-new-level=on|off Whether use new log level definition, see log4j specs. Default: $(value2switch $SRS_LOG_NEW_LEVEL)
Performance: @see https://blog.csdn.net/win_lin/article/details/53503869
--valgrind=on|off Whether build valgrind for memory check. Default: $(value2switch $SRS_VALGRIND)
Expand Down Expand Up @@ -353,6 +356,7 @@ function parse_user_option() {
--log-verbose) SRS_LOG_VERBOSE=$(switch2value $value) ;;
--log-info) SRS_LOG_INFO=$(switch2value $value) ;;
--log-trace) SRS_LOG_TRACE=$(switch2value $value) ;;
--log-new-level) SRS_LOG_NEW_LEVEL=$(switch2value $value) ;;
--debug) SRS_DEBUG=$(switch2value $value) ;;
--debug-stats) SRS_DEBUG_STATS=$(switch2value $value) ;;

Expand Down Expand Up @@ -553,6 +557,7 @@ function regenerate_options() {
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-verbose=$(value2switch $SRS_LOG_VERBOSE)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-info=$(value2switch $SRS_LOG_INFO)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-trace=$(value2switch $SRS_LOG_TRACE)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-new-level=$(value2switch $SRS_LOG_NEW_LEVEL)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gcov=$(value2switch $SRS_GCOV)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug=$(value2switch $SRS_DEBUG)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug-stats=$(value2switch $SRS_DEBUG_STATS)"
Expand Down
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changelog for SRS.

## SRS 5.0 Changelog

* v5.0, 2022-10-26, Fix [#3218](https://github.com/ossrs/srs/issues/3218): Log: Follow Java/log4j log level specs. v5.0.83
* v5.0, 2022-10-25, Log: Refine the log interface. v5.0.82
* v5.0, 2022-10-23, For [#3216](https://github.com/ossrs/srs/issues/3216): Support Google Address Sanitizer. v5.0.81
* v5.0, 2022-10-21, Kernel: Support grab backtrace stack when assert fail. v5.0.80
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 82
#define VERSION_REVISION 83

#endif
25 changes: 18 additions & 7 deletions trunk/src/kernel/srs_kernel_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@

#include <stdarg.h>

// Go log level: Info, Warning, Error, Fatal, see https://github.com/golang/glog/blob/master/glog.go#L17
// Java log level: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, see https://stackoverflow.com/a/2031209/17679565
// or https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-api/src/main/java/org/apache/logging/log4j/Level.java#L29
const char* srs_log_level_strings[] = {
"Forbidden",
"Verb",
"Debug", NULL,
"Trace", NULL, NULL, NULL,
"Warn", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"Disabled",
#ifdef SRS_LOG_NEW_LEVEL
// The level specs by log4j.
"FORB", "TRACE", "DEBUG", NULL, "INFO", NULL, NULL, NULL,
"WARN", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"ERROR", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"OFF",
#else
// SRS 4.0 level definition, to keep compatible.
"Forb", "Verb", "Debug", NULL, "Trace", NULL, NULL, NULL,
"Warn", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"Off",
#endif
};

ISrsLog::ISrsLog()
Expand Down
7 changes: 4 additions & 3 deletions trunk/src/kernel/srs_kernel_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@

#include <srs_kernel_consts.hpp>

// The log level, for example:
// if specified Debug level, all level messages will be logged.
// if specified Warn level, only Warn/Error/Fatal level messages will be logged.
// The log level, see https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-api/src/main/java/org/apache/logging/log4j/Level.java
// Please note that the enum name might not be the string, to keep compatible with previous definition.
enum SrsLogLevel
{
SrsLogLevelForbidden = 0x00,

// Only used for very verbose debug, generally,
// we compile without this level for high performance.
SrsLogLevelVerbose = 0x01,
SrsLogLevelInfo = 0x02,
SrsLogLevelTrace = 0x04,
SrsLogLevelWarn = 0x08,
SrsLogLevelError = 0x10,

SrsLogLevelDisabled = 0x20,
};

Expand Down
24 changes: 17 additions & 7 deletions trunk/src/utest/srs_utest_kernel2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,22 @@ VOID TEST(KernelPSTest, PsPacketHeaderClockDecode)

VOID TEST(KernelLogTest, LogLevelString)
{
EXPECT_STREQ("Forbidden", srs_log_level_strings[SrsLogLevelForbidden]);
EXPECT_STREQ("Verb", srs_log_level_strings[SrsLogLevelVerbose]);
EXPECT_STREQ("Debug", srs_log_level_strings[SrsLogLevelInfo]);
EXPECT_STREQ("Trace", srs_log_level_strings[SrsLogLevelTrace]);
EXPECT_STREQ("Warn", srs_log_level_strings[SrsLogLevelWarn]);
EXPECT_STREQ("Error", srs_log_level_strings[SrsLogLevelError]);
EXPECT_STREQ("Disabled", srs_log_level_strings[SrsLogLevelDisabled]);
#ifdef SRS_LOG_NEW_LEVEL
EXPECT_STREQ("FORB", srs_log_level_strings[SrsLogLevelForbidden]);
EXPECT_STREQ("TRACE", srs_log_level_strings[SrsLogLevelVerbose]);
EXPECT_STREQ("DEBUG", srs_log_level_strings[SrsLogLevelInfo]);
EXPECT_STREQ("INFO", srs_log_level_strings[SrsLogLevelTrace]);
EXPECT_STREQ("WARN", srs_log_level_strings[SrsLogLevelWarn]);
EXPECT_STREQ("ERROR", srs_log_level_strings[SrsLogLevelError]);
EXPECT_STREQ("OFF", srs_log_level_strings[SrsLogLevelDisabled]);
#else
EXPECT_STREQ("Forb", srs_log_level_strings[SrsLogLevelForbidden]);
EXPECT_STREQ("Verb", srs_log_level_strings[SrsLogLevelVerbose]);
EXPECT_STREQ("Debug", srs_log_level_strings[SrsLogLevelInfo]);
EXPECT_STREQ("Trace", srs_log_level_strings[SrsLogLevelTrace]);
EXPECT_STREQ("Warn", srs_log_level_strings[SrsLogLevelWarn]);
EXPECT_STREQ("Error", srs_log_level_strings[SrsLogLevelError]);
EXPECT_STREQ("Off", srs_log_level_strings[SrsLogLevelDisabled]);
#endif
}

0 comments on commit 2aa2a42

Please sign in to comment.