8000 Make logdir configuration work as intended by richcarl · Pull Request #4491 · aeternity/aeternity · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make logdir configuration work as intended #4491

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

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/aecore/src/aecore.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
exometer_core,
redbug,
yamerl,
setup,
lager,
aeutils,
base58,
Expand Down
1 change: 1 addition & 0 deletions apps/aecore/test/aec_mining_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ mine_block_test_() ->

setup() ->
InitialApps = {running_apps(), loaded_apps()},
{ok, _} = application:ensure_all_started(setup),
{ok, _} = application:ensure_all_started(aeutils),
aec_test_utils:mock_fast_and_deterministic_cuckoo_pow(),
aec_test_utils:start_chain_db(),
Expand Down
1 change: 1 addition & 0 deletions apps/aecore/test/aec_target_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ target_adj_test_() ->

setup() ->
InitialApps = {running_apps(), loaded_apps()},
{ok, _} = application:ensure_all_started(setup),
{ok, _} = application:ensure_all_started(aeutils),
meck:new(aec_txs_trees, [passthrough]),
meck:new(aec_conductor, [passthrough]),
Expand Down
53 changes: 33 additions & 20 deletions apps/aeutils/src/aeu_logging_env.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,51 @@
-export([adjust_log_levels/0]).

adjust_log_levels() ->
expand_lager_log_root(),
set_lager_log_root(),
aeu_env:check_env(
aeutils,
[{[<<"logging">>, <<"hwm">>] , fun set_hwm/1},
{[<<"logging">>, <<"level">>] , fun set_level/1}]).

%% See https://github.com/erlang-lager/lager/issues/557
%% We want to prevent the log directory from moving during runtime. One
%% possible scenario might be that someone pecks around in an aeternity
%% node shell, changes the current working directory and forgets to restore
%% it. If the log_root setting in lager is a relative path (which it is by
%% default), this would effectively move the log root.
%% 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).
%%
expand_lager_log_root() ->
case application:get_env(lager, log_root) of
{ok, Root} when is_list(Root) ->
case filename:pathtype(Root) of
relative ->
application:set_env(lager, log_root,
filename:absname(Root));
absolute ->
ok
end;
_ ->
application:set_env(lager, log_root, setup:log_dir())
end.
%% The setup app must be started before lager, so that this setup hook runs
%% before lager tries to create the log root directory, and thus only
%% setup's log_dir setting will determine the log directory location.

set_lager_log_root() ->
%% We ignore lager's current `log_root` setting - if it was loaded from
%% the boot script, it will simply be the default value (typically just
%% "log") from the `lager.app.src` file. Instead, `setup` will decide
%% the log directory, and we make sure that the path is an absolute
%% path after this point. (If setup's `log_dir` env was not set before,
%% the call to setup:log_dir() will set it to $HOME/log.<nodename>.)
case is_app_running(lager) of
true -> exit(lager_started_before_setup);
_ -> ok
end,
Root = setup:log_dir(),
case is_tuple(Root) of
true -> exit(invalid_setup_log_dir);
_ -> ok
end,
AbsRoot = case filename:pathtype(Root) of
relative -> filename:absname(Root);
absolute -> Root
end,
%% also ensure that the setting is not reset by load/reload of the apps
ok = application:set_env(lager, log_root, AbsRoot, [{persistent, true}]),
ok = application:set_env(setup, log_dir, AbsRoot, [{persistent, true}]).

set_hwm(HWM) when is_integer(HWM) ->
application:set_env(lager, error_logger_hwm, HWM),
Expand Down
1 change: 1 addition & 0 deletions apps/aeutils/src/aeutils.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{applications,
[kernel,
stdlib,
setup,
lager,
gproc,
jobs,
Expand Down
3 changes: 3 additions & 0 deletions config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@
{mnesia_compatible_aborts, true}]},

{setup, [
{verify_directories, false}, % stop setup from creating dirs
{abort_on_error, true},
%% Note: $HOME here means the aeternity directory, not the user home!
%% (These variables are a feature of the setup application.)
{data_dir, "$HOME/data"},
{log_dir, "$HOME/log"}
]}
Expand Down
9 changes: 6 additions & 3 deletions docs/hacking.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ the temporary directory that was created, do:
variable expansion on the configuration values. E.g., if an application
`x` has a configuration entry `{log_dir, "$HOME/log"}`, then calling
`setup:get_env(x, log_dir)` will return something like
"/home/username/log". (This only works on variables defined via `setup`
itself, not general shell environment variables - `$HOME` is a
predefined special case.)
"/home/username/log". *This only works on variables defined by `setup`
itself, not operating system environment variables. Note in particular
that `$HOME` does not mean the current user's home directory - it
refers to the `setup` configuration key `{home, Dir}` meaning the
root directory of the Aeternity system; if not set, the current
directory is used.*
- Setup has a configuration option `data_dir` which the Aeternity system
uses to know where its database is located. The directory needs to
already exist and be populated at system start, else the startup fails.
Expand Down
8 changes: 5 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% The requirements on the OTP version come mainly from the patches%% for OTP modules - see `otp_patches/` - requiring the version of
%% The requirements on the OTP version come mainly from the patches
%% for OTP modules - see `otp_patches/` - requiring the version of
%% certain OTP applications, e.g. `mnesia`, to be well known in order
%% for such patches to be applied deterministically.
%%
Expand Down Expand Up @@ -114,8 +115,9 @@

{relx, [{release, { aeternity, "version value comes from VERSION" },
% sasl is required for the command `aeternity versions` to work,
% it is disabled in `sys.config` though.
[runtime_tools, sasl, lager, setup, sext, gproc, jobs, lz4, argparse, trace_runner, app_ctrl,
% it is disabled in `sys.config` though. Note that setup must be
% started before lager
[runtime_tools, sasl, setup, lager, sext, gproc, jobs, lz4, argparse, trace_runner, app_ctrl,
{rocksdb, load}, {mnesia_rocksdb, load}, {mnesia, load}, kache,
parse_trans, exometer_core, ranch, aeminer, aecore, aeapi, aehttp, enacl, enoise,
aebytecode, aeserialization, aevm, aechannel, aefate, aemon, aestratum, ecrecover,
Expand Down
0