Skip to content

Commit

Permalink
Merge pull request #543 from paulo-ferraz-oliveira/fix/log_location
Browse files Browse the repository at this point in the history
Log to log_root+..._log except if ..._log is absolute
  • Loading branch information
Vagabond authored Mar 2, 2021
2 parents 8c32954 + 7134737 commit f4788b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
ci:
name: >
Run checks and tests over ${{matrix.otp_vsn}} and ${{matrix.os}}
Run Linux-based checks and tests over ${{matrix.otp_vsn}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
container:
image: erlang:${{matrix.otp_vsn}}
Expand All @@ -23,3 +23,23 @@ jobs:
- uses: actions/checkout@v2
- run: rebar3 dialyzer
- run: rebar3 eunit
ci-windows:
name: >
Run Windows-based checks and tests over ${{matrix.otp_vsn}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
strategy:
matrix:
otp_vsn: [23.2]
os: [windows-latest]
steps:
- uses: actions/checkout@v2
- uses: gleam-lang/[email protected]
with:
otp-version: ${{matrix.otp_vsn}}
id: install_erlang
- run: wget https://s3.amazonaws.com/rebar3/rebar3 -OutFile rebar3
shell: powershell
- run: |
& "${{steps.install_erlang.outputs.erlpath}}\bin\escript.exe" rebar3 dialyzer
- run: |
& "${{steps.install_erlang.outputs.erlpath}}\bin\escript.exe" rebar3 eunit
8 changes: 0 additions & 8 deletions appveyor.yml

This file was deleted.

23 changes: 8 additions & 15 deletions src/lager_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,16 @@ i3l(I) when I < 100 -> [$0 | i2l(I)];
i3l(I) -> integer_to_list(I).

%% When log_root option is provided, get the real path to a file
expand_path(RelPath) ->
RelPath2 = case application:get_env(lager, log_root) of
{ok, LogRoot} when is_list(LogRoot) -> % Join relative path
%% check if the given RelPath contains LogRoot, if so, do not add
%% it again; see gh #304
case filename:dirname(RelPath) of
"." ->
filename:join(LogRoot, RelPath);
false ->
RelPath
end;
undefined -> % No log_root given, keep relative path
RelPath
expand_path(LogPath) ->
LogRoot = application:get_env(lager, log_root, undefined),
RealPath = case filename:absname(LogPath) =:= LogPath of
false when LogRoot =/= undefined ->
filename:join(LogRoot, LogPath);
_ ->
LogPath
end,
%% see #534 make sure c:cd can't change file path, trans filename to abs name
filename:absname(RelPath2).
filename:absname(RealPath).

%% Find a file among the already installed handlers.
%%
Expand Down Expand Up @@ -839,7 +833,6 @@ expand_path_test() ->
ok = application:set_env(lager, log_root, "log/dir"),
?assertEqual(filename:absname("/foo/bar"), expand_path("/foo/bar")), % Absolute path should not be changed
?assertEqual(filename:absname("log/dir/foo/bar"), expand_path("foo/bar")),
?assertEqual(filename:absname("log/dir/foo/bar"), expand_path("log/dir/foo/bar")), %% gh #304

case OldRootVal of
undefined -> application:unset_env(lager, log_root);
Expand Down
6 changes: 3 additions & 3 deletions test/pr_stacktrace_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pr_stacktrace_throw_test() ->
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "pr_stacktrace_test:pr_stacktrace_throw_test/0 line 26\n pr_stacktrace_test:make_throw/0 line 16\nthrow:{test,exception}",
Want = "pr_stacktrace_test:pr_stacktrace_throw_test/0 line 18\n pr_stacktrace_test:make_throw/0 line 8\nthrow:{test,exception}",
?assertNotEqual(nomatch, string:find(Got, Want)).

pr_stacktrace_bad_arg_test() ->
Expand All @@ -30,7 +30,7 @@ pr_stacktrace_bad_arg_test() ->
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "pr_stacktrace_test:pr_stacktrace_bad_arg_test/0 line 36\n pr_stacktrace_test:bad_arg/0 line 22\nerror:badarg",
Want = "pr_stacktrace_test:pr_stacktrace_bad_arg_test/0 line 28\n pr_stacktrace_test:bad_arg/0 line 14\nerror:badarg",
?assertNotEqual(nomatch, string:find(Got, Want)).

pr_stacktrace_bad_arity_test() ->
Expand All @@ -40,7 +40,7 @@ pr_stacktrace_bad_arity_test() ->
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "pr_stacktrace_test:pr_stacktrace_bad_arity_test/0 line 46\n lists:concat([], [])\nerror:undef",
Want = "pr_stacktrace_test:pr_stacktrace_bad_arity_test/0 line 38\n lists:concat([], [])\nerror:undef",
?assertNotEqual(nomatch, string:find(Got, Want)).

pr_stacktrace_no_reverse_test() ->
Expand Down

0 comments on commit f4788b7

Please sign in to comment.