Skip to content

Commit

Permalink
Merge pull request #220 from zmstone/0110-refactor-do-not-log-struct-…
Browse files Browse the repository at this point in the history
…overrides

refactor: do not log overriding structs
  • Loading branch information
zhongwencool authored Jan 11, 2023
2 parents 10fefe7 + 104ecbf commit 437ad44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/hocon_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,8 @@ stringify_line(K, V) when is_list(V) ->
stringify_line(K, V) ->
io_lib:format("~s ~w", [K, V]).

log_for_generator(_Level, #{hocon_env_var_name := Var, path := P, value := V}) when is_binary(V) ->
?STDOUT("~s = ~s = ~s", [P, Var, V]);
log_for_generator(_Level, #{hocon_env_var_name := Var, path := P, value := V}) ->
?STDOUT("~s = ~s = ~0p", [P, Var, V]);
log_env_override(Var, P, V);
log_for_generator(debug, _Args) ->
ok;
log_for_generator(info, _Args) ->
Expand All @@ -425,6 +423,15 @@ log_for_generator(Level, Msg) when is_binary(Msg) ->
log_for_generator(Level, Args) ->
io:format(standard_error, "[~0p] ~0p~n", [Level, Args]).

log_env_override(Var, Path, Value) ->
ValueStr =
case Value of
V when is_binary(V) -> V;
V when is_map(V) -> "{...}";
V -> io_lib:format("~0p", [V])
end,
?STDOUT("~s [~s]: ~s", [Var, Path, ValueStr]).

-ifndef(TEST).
stop_deactivate() ->
init:stop(1),
Expand Down
6 changes: 4 additions & 2 deletions test/hocon_cli_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ generate_with_env_logging_test() ->
]
],
[
{"ZZZ_FOO", "{min: 1, max: 2}"},
{"ZZZ_FOO__MIN", "42"},
{"ZZZ_FOO__MAX", "43"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
Expand All @@ -148,8 +149,9 @@ generate_with_env_logging_test() ->
{ok, Stdout} = cuttlefish_test_group_leader:get_output(),
?assertEqual(
[
<<"foo.max = ZZZ_FOO__MAX = 43">>,
<<"foo.min = ZZZ_FOO__MIN = 42">>
<<"ZZZ_FOO [foo]: {...}">>,
<<"ZZZ_FOO__MAX [foo.max]: 43">>,
<<"ZZZ_FOO__MIN [foo.min]: 42">>
],
lists:sort(
binary:split(
Expand Down

0 comments on commit 437ad44

Please sign in to comment.