erlang-lager / lager

A logging framework for Erlang/OTP
Apache License 2.0
1.13k stars 455 forks source link

Resolve relative log_root to absolute on boot #557

Closed paulo-ferraz-oliveira closed 2 years ago

paulo-ferraz-oliveira commented 3 years ago

As per a recent discussion with @uwiger, on Slack, lager could be doing something like:

expand_lager_log_root() ->
    {ok, Root} = application:get_env(lager, log_root),
    case filename:pathtype(Root) of
        relative ->
            application:set_env(lager, log_root, filename:absname(Root));
        absolute ->
            ok
    end.

as a way to "lock" the log root to an absolute path. This makes for easier debugging, as a call to application:get_env(lager, log_root) would immediately tell us where the log is in the disk.

@mrallen1, @Vagabond, thoughts?

uwiger commented 3 years ago

I just prepared to commit the following comment to the above code in our project. :)

%% See https://github.com/erlang-lager/lager/issues/557
%% There are different ways to ensure that the log root is a stable
%% absolute path (once initialized). This could also be done using
%% sys.config.src (e.g. `{log_root, "${ROOTDIR}/log"}`, but at the time
%% of writing, `rebar3 ct` doesn't support `sys_config_src`, and it gets messy
%% to support both types.
%%
%% This setup hook code will likely run after lager has started, but it still
%% fixes the log root for later. One possible scenario might be that someone
%% pecks around in an aeternity node shell, changes the current working directory
%% and forgets to restore it. This would effectively move the logical log_root
%% in lager, if the setting is a relative path (which is the default).
%%