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

ERL-1075: Confusion as to what the default level is for the primary configuration in logger #4030

Open
OTP-Maintainer opened this issue Oct 25, 2019 · 0 comments
Labels

Comments

@OTP-Maintainer
Copy link

Original reporter: adnilsson
Affected version: OTP-22.1
Component: kernel
Migrated from: https://bugs.erlang.org/browse/ERL-1075


h3.  Explanation
The 22.1 version of the Reference Manual for the type {{primary_config()}} in logger in the kernel application [says|http://erlang.org/doc/man/logger.html#type-primary_config]:
{quote}
The following default values apply:
* level => info
{quote}

Much to my surprise, then, I noticed that my {{?LOG_INFO}} messages were never displayed.
Investigating the primary configuration revealed that the logging level was actually set to {{notice}} and not {{info}} as I had inferred from the docs:
{noformat}
Erlang/OTP 22 [erts-10.5.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V10.5.2  (abort with ^G)
1> logger:i(primary).
Primary configuration: 
    Level: notice
    Filter Default: log
    Filters: 
        (none)
ok
{noformat}

On the other hand, the kernel User's Guide says in [section 2.6|http://erlang.org/doc/apps/kernel/logger_chapter.html#configuration] under *Primary Logger Configuration* that {{level}} "Defaults to {{notice}}".

At this point I felt I had two conflicting pieces of  information, but looking closer I saw that the documentation is not incorrect per se. {{logger:internal_init_logger/0}} sets the level of the primary configuration by calling another internal function {{get_logger_level}}:

{code:erlang}
get_logger_level() ->
    case application:get_env(kernel,logger_level,info) of
        Level when ?IS_LEVEL_ALL(Level) ->
            Level;
        Level ->
            throw({logger_level, Level})
    end.
{code}

Clearly,  the call to {{application:get_env/3}} suggests that the default should become {{info}} as I never configured anything else.  But we saw from the output of {{logger:i}} that the primary logging level will be {{notice}}. The only explanation is that the {{logger_level}} parameter is actually set by the kernel application. [Lo and behold|https://github.com/erlang/otp/blob/6611181ae71422a1c66798718b37474641a090a9/lib/kernel/src/kernel.app.src#L148]:  in kernel/src/kernel.app.src you will find {{\{env, \[\{logger_level, notice\} ,  _ \]\}}}. 

I think the issue here is that the documentation is talking about different defaults. On one hand there is the kernel application default setting ({{notice}}), and on the other there is the default for when nothing is said ({{info}}). In the end, only one truly matters for the typical Erlang user.

h3. Improvement suggestion
I see no point in having two separate defaults that causes unexpected behaviour with respect to the Reference Manual. Why not prevent this headache from happening again by removing the {{logger_level}} parameter in kernel.app.src and make {{notice}} the default value in {{logger:get_logger_level/0}}? 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant