|
|
@ -21,7 +21,7 @@ |
|
|
|
, is_loggable/3 |
|
|
|
, trace_filter/1 |
|
|
|
, trace_filter/2 |
|
|
|
, expand_path/1 |
|
|
|
, parsePath/1 |
|
|
|
, find_file/2 |
|
|
|
, check_hwm/1 |
|
|
|
, check_hwm/2 |
|
|
@ -479,28 +479,25 @@ is_loggable(Msg, SeverityThreshold, MyName) when is_integer(SeverityThreshold) - |
|
|
|
rumMsg:severity_as_int(Msg) =< SeverityThreshold orelse |
|
|
|
lists:member(MyName, rumMsg:destinations(Msg)). |
|
|
|
|
|
|
|
%% 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 |
|
|
|
end, |
|
|
|
%% see #534 make sure c:cd can't change file path, trans filename to abs name |
|
|
|
filename:absname(RelPath2). |
|
|
|
parsePath(RelPath) -> |
|
|
|
NewRelPath = |
|
|
|
case rumUtil:get_env(logRoot, undefined) of |
|
|
|
undefined -> |
|
|
|
RelPath; |
|
|
|
LogRoot -> |
|
|
|
case filename:dirname(RelPath) of |
|
|
|
"." -> |
|
|
|
filename:join(LogRoot, RelPath); |
|
|
|
false -> |
|
|
|
RelPath |
|
|
|
end |
|
|
|
end, |
|
|
|
filename:absname(NewRelPath). |
|
|
|
|
|
|
|
%% Find a file among the already installed handlers. |
|
|
|
%% |
|
|
|
%% The file is already expanded (i.e. lager_util:expand_path already added the |
|
|
|
%% "log_root"), but the file paths inside Handlers are not. |
|
|
|
%% "logRoot"), but the file paths inside Handlers are not. |
|
|
|
find_file(_File1, _Handlers = []) -> |
|
|
|
false; |
|
|
|
find_file(File1, [{{lager_file_backend, File2}, _Handler, _Sink} = HandlerInfo | Handlers]) -> |
|
|
@ -853,20 +850,20 @@ mask_to_levels_test() -> |
|
|
|
ok. |
|
|
|
|
|
|
|
expand_path_test() -> |
|
|
|
OldRootVal = application:get_env(lager, log_root), |
|
|
|
OldRootVal = application:get_env(lager, logRoot), |
|
|
|
|
|
|
|
ok = application:unset_env(lager, log_root), |
|
|
|
?assertEqual(filename:absname("/foo/bar"), expand_path("/foo/bar")), |
|
|
|
?assertEqual(filename:absname("foo/bar"), expand_path("foo/bar")), |
|
|
|
ok = application:unset_env(lager, logRoot), |
|
|
|
?assertEqual(filename:absname("/foo/bar"), parsePath("/foo/bar")), |
|
|
|
?assertEqual(filename:absname("foo/bar"), parsePath("foo/bar")), |
|
|
|
|
|
|
|
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 |
|
|
|
ok = application:set_env(lager, logRoot, "log/dir"), |
|
|
|
?assertEqual(filename:absname("/foo/bar"), parsePath("/foo/bar")), % Absolute path should not be changed |
|
|
|
?assertEqual(filename:absname("log/dir/foo/bar"), parsePath("foo/bar")), |
|
|
|
?assertEqual(filename:absname("log/dir/foo/bar"), parsePath("log/dir/foo/bar")), %% gh #304 |
|
|
|
|
|
|
|
case OldRootVal of |
|
|
|
undefined -> application:unset_env(lager, log_root); |
|
|
|
{ok, Root} -> application:set_env(lager, log_root, Root) |
|
|
|
undefined -> application:unset_env(lager, logRoot); |
|
|
|
{ok, Root} -> application:set_env(lager, logRoot, Root) |
|
|
|
end, |
|
|
|
ok. |
|
|
|
|
|
|
|