Is there any way to configure logger at shell startup directly via system.config?


I’m trying to configure my logger in the system.config file. I have {config, <path_to_file>} in shell configuration in rebar.config. However, this configuration is related to kernel, so it is not consulted before kernel starts. Currently, workaround is to call logger:reconfigure() after shell startup. I tried calling reconfiguration in script_file that evaluates before booting shell, but environment from config is not loaded yet.

Is there any way to configure logger at shell startup directly via system.config?

EDIT: If the handler’s id is /= default it succeeds… If I try to replace the default one, I must call reconfiguration.
Erlang version: 25.1
Rebar3 version: 3.19.0


Solution is to prepend {handler, default, undefined} to the configuration. But according to the docs:

**{handler, HandlerId, Module, HandlerConfig}**

If HandlerId is default, then this entry modifies the default handler, equivalent to calling

[ logger:remove_handler(default) ](

followed by

[ logger:add_handler(default, Module, HandlerConfig) ](

For all other values of HandlerId, this entry adds a new handler, equivalent to calling

[ logger:add_handler(HandlerId, Module, HandlerConfig) ](

Multiple entries of this type are allowed.

and examples this tuple shouldn’t be required…


You can use ERL_FLAGS environment variable to specify sys.config file to load at ERTS startup (before rebar3 starts).

Example sys.config content:

[{kernel, [
    {key, value}

Example starting rebar3 shell with it:

max-au:~$ ERL_FLAGS="-config sys.config" rebar3 shell
===> Verifying dependencies...
Erlang/OTP 26 [DEVELOPMENT] [erts-13.1.4] [source-7bc70bd590] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Eshell V13.1.4 (press Ctrl+G to abort, type help(). for help)
1> application:get_env(kernel, key).