From eb249f81729085b03b14a9e008416ec28624dc19 Mon Sep 17 00:00:00 2001 From: Mark Allen Date: Mon, 25 Jan 2016 23:30:49 -0600 Subject: [PATCH] Do not add logroot in expand_path sometimes If expand_path/1 already contains LogRoot in its RelPath, do not add it again. --- src/lager_util.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lager_util.erl b/src/lager_util.erl index 76fdda6..2ce568e 100644 --- a/src/lager_util.erl +++ b/src/lager_util.erl @@ -482,7 +482,14 @@ i3l(I) -> integer_to_list(I). expand_path(RelPath) -> case application:get_env(lager, log_root) of {ok, LogRoot} when is_list(LogRoot) -> % Join relative path - filename:join(LogRoot, RelPath); + %% check if the given RelPath contains LogRoot, if so, do not add + %% it again; see gh #304 + case string:str(filename:dirname(RelPath), LogRoot) of + X when X > 0 -> + RelPath; + _Zero -> + filename:join(LogRoot, RelPath) + end; undefined -> % No log_root given, keep relative path RelPath end. @@ -782,6 +789,7 @@ expand_path_test() -> ok = application:set_env(lager, log_root, "log/dir"), ?assertEqual("/foo/bar", expand_path("/foo/bar")), % Absolute path should not be changed ?assertEqual("log/dir/foo/bar", expand_path("foo/bar")), + ?assertEqual("log/dir/foo/bar", expand_path("log/dir/foo/bar")), %% gh #304 case OldRootVal of undefined -> application:unset_env(lager, log_root);