Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log: Should follow Java/Go/FFmpeg/NGINX log level specs. #3218

Closed
winlinvip opened this issue Oct 25, 2022 · 1 comment · Fixed by #3219
Closed

Log: Should follow Java/Go/FFmpeg/NGINX log level specs. #3218

winlinvip opened this issue Oct 25, 2022 · 1 comment · Fixed by #3219
Assignees
Labels
EnglishNative This issue is conveyed exclusively in English. Enhancement Improvement or enhancement.
Milestone

Comments

@winlinvip
Copy link
Member

winlinvip commented Oct 25, 2022

The log level of SRS 1.0 to 4.0:

Verb > Debug > Trace > Warn > Error

The Java log4j specs, see apache/logging-log4j2

TRACE > DEBUG > INFO > WARN > ERROR > FATAL

The Go log specs, see golang/glog or kubernetes/klog:

Info > Warning > Error > Fatal

For Go, another defactor log specs is uber-go/zap

Debug > Info > Warn > Error > DPanic > Panic > Fatal

While FFmpeg has a more detail log level specs:

trace > debug > verbose > info > warning > error > fatal

The last one, NGXIN log level, see nginx:

DEBUG > INFO > NOTICE > WARN > ERR > CRIT > ALERT > EMERG

SRS 5.0+ should follow Java/Go/FFmpeg/Nginx log level specs.

Config

The config for log level:

# The log level for logging to console or file. It can be:
#       verbose, info, trace, warn, error
# If configure --log-level_v2=off, use SRS 4.0 level specs which is v1, the level text is:
#       Verb, Info, Trace, Warn, Error
# If configure --log-level_v2=on, use SRS 5.0 level specs which is v2, the level text is:
#       TRACE, DEBUG, INFO, WARN, ERROR
# Note: Do not support reloading, for SRS5+
# Overwrite by env SRS_SRS_LOG_LEVEL
# default: trace
srs_log_level trace;
# The log level v2, rewrite the config srs_log_level if not empty, it can be:
#       trace, debug, info, warn, error
# If configure --log-level_v2=off, use SRS 4.0 level specs which is v1, the level text is:
#       Verb, Info, Trace, Warn, Error
# If configure --log-level_v2=on, use SRS 5.0 level specs which is v2, the level text is:
#       TRACE, DEBUG, INFO, WARN, ERROR
# Overwrite by env SRS_SRS_LOG_LEVEL_V2
srs_log_level_v2 info;

The default level of SRS 4.0:

srs_log_level trace;

The default level of SRS 5.0:

srs_log_level trace;
srs_log_level_v2 info;

The default config should work well without any changes.

Configure

SRS 5.0 supports configure options to control the log text for level:

./configure --help |grep log-level
#  --log-level_v2=on|off     Whether use v2.0 log level definition, see log4j specs. Default: on

If ./configure --log-level_v2=off, use SRS 4.0 log level text, literally the same to srs_log_level, even though the config use srs_log_level_v2.

If ./configure srs_log_level_v2=on, use SRS 5.0 v2 log level text, apply both for the config srs_log_level and srs_log_level_v2.

The config file and configure is orthogonal:

  • Config srs_log_level or srs_log_level_v2 control the converting from text to log level object.
  • Configure --log-level_v2=on|off controls the log level text in each log line.

So you're able to use different log level for both new style and keep compability with old style.

Compare

If config with srs_log_level, the log text is described by bellow table:

Config
srs_log_level
SRS 4.0 SRS 5.0
--log-level_v2=off
SRS 5.0
--log-level_v2=on
verbose Verb Verb TRACE
info Info Info DEBUG
trace Trace Trace INFO
warn Warn Warn WARN
error Error Error ERROR

If config with srs_log_level_v2, the log text is described by bellow table:

Config
srs_log_level_v2
SRS 5.0
./configure
--log-level_v2=off
SRS 5.0
./configure
--log-level_v2=on
trace Verb TRACE
debug Info DEBUG
info Trace INFO
warn Warn WARN
error Error ERROR

There is a full table about config and configure options:

Config
srs_log_level
Config
srs_log_level_v2
SRS 4.0 SRS 5.0
./configure
--log-level_v2=off
SRS 5.0
./configure
--log-level_v2=on
verbose trace Verb Verb TRACE
info debug Info Info DEBUG
trace info Trace Trace INFO
warn warn Warn Warn WARN
error error Error Error ERROR

The default config should work well, so you don't have to change it.

Example

The startup log of SRS 4.0:

[2022-10-26 11:46:47.991][Trace][6905][83h49oox] XCORE-SRS/4.0.265(Leo)

SRS. 5.0:

[2022-10-26 11:46:47.991][INFO][6905][83h49oox] XCORE-SRS/5.0.83(Bee)

Note: Please note that the level text is different.

@winlinvip winlinvip self-assigned this Oct 25, 2022
@winlinvip winlinvip added the Enhancement Improvement or enhancement. label Oct 25, 2022
@winlinvip winlinvip added this to the 5.0 milestone Oct 25, 2022
@winlinvip winlinvip changed the title Log: Follow log level specs. Log: Should follow Java/Go/FFmpeg log level specs. Oct 25, 2022
winlinvip added a commit to winlinvip/srs that referenced this issue Oct 26, 2022
@winlinvip winlinvip linked a pull request Oct 26, 2022 that will close this issue
@winlinvip winlinvip changed the title Log: Should follow Java/Go/FFmpeg log level specs. Log: Should follow Java/Go/FFmpeg/NGINX log level specs. Oct 26, 2022
winlinvip added a commit to winlinvip/srs that referenced this issue Oct 26, 2022
winlinvip added a commit to winlinvip/srs that referenced this issue Oct 26, 2022
winlinvip added a commit that referenced this issue Oct 26, 2022
1. Support Java/log4j log level text.
2. Support configuring by `--log-new-level=on` which is enabled by default.
3. Support `--log-new-level=off` to use SRS 4.0 log level for compatibility.
@suzp1984
Copy link
Contributor

enum SrsLogLevel

Why not redefine the SrsLogLevel with SRS_LOG_LEVEL_V2 macro so that it can print the reasonable tags?

[2022-10-26 11:46:47.991][INFO][6905][83h49oox] XCORE-SRS/5.0.83(Bee)
The srs_trace() print INFO tag, it seems abnormal.

How about the below definition?

enum SrsLogLevel
{
    SrsLogLevelForbidden = 0x00,

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

    SrsLogLevelDisabled = 0x20,
};

johzzy pushed a commit to johzzy/srs that referenced this issue Jun 26, 2023
…s#3219)

1. Support Java/log4j log level text.
2. Support configuring by `--log-new-level=on` which is enabled by default.
3. Support `--log-new-level=off` to use SRS 4.0 log level for compatibility.
@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EnglishNative This issue is conveyed exclusively in English. Enhancement Improvement or enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants