Przeglądaj źródła

Cleanup logfile option validation, as suggested by @jtuple

pull/1/head
Andrew Thompson 13 lat temu
rodzic
commit
b2d9d06abd
2 zmienionych plików z 31 dodań i 34 usunięć
  1. +28
    -31
      src/lager_file_backend.erl
  2. +3
    -3
      src/lager_sup.erl

+ 28
- 31
src/lager_file_backend.erl Wyświetl plik

@ -174,39 +174,36 @@ write(#file{name=Name, fd=FD, inode=Inode, flap=Flap, size=RotSize,
validate_logfiles([]) ->
[];
validate_logfiles([{Name, Level, Size, Date, Count}|T]) ->
case lists:member(Level, ?LEVELS) of
true ->
case (is_integer(Size) andalso Size >= 0) of
true ->
case (is_integer(Count) andalso Count >= 0) of
true ->
case lager_util:parse_rotation_date_spec(Date) of
{ok, Spec} ->
[{Name, Level, Size, Spec,
Count}|validate_logfiles(T)];
{error, _} when Date == "" ->
%% blank ones are fine.
[{Name, Level, Size, undefined,
Count}|validate_logfiles(T)];
{error, _} ->
?INT_LOG(error, "Invalid rotation date of ~p for ~s.",
[Date, Name]),
validate_logfiles(T)
end;
_ ->
?INT_LOG(error, "Invalid rotation count of ~p for ~s.",
[Count, Name]),
validate_logfiles(T)
end;
_ ->
?INT_LOG(error, "Invalid rotation size of ~p for ~s.",
[Size, Name]),
validate_logfiles(T)
end;
_ ->
ValidLevel = (lists:member(Level, ?LEVELS)),
ValidSize = (is_integer(Size) andalso Size >= 0),
ValidCount = (is_integer(Count) andalso Count >= 0),
case {ValidLevel, ValidSize, ValidCount} of
{false, _, _} ->
?INT_LOG(error, "Invalid log level of ~p for ~s.",
[Level, Name]),
validate_logfiles(T)
validate_logfiles(T);
{_, false, _} ->
?INT_LOG(error, "Invalid rotation size of ~p for ~s.",
[Size, Name]),
validate_logfiles(T);
{_, _, false} ->
?INT_LOG(error, "Invalid rotation count of ~p for ~s.",
[Count, Name]),
validate_logfiles(T);
{true, true, true} ->
case lager_util:parse_rotation_date_spec(Date) of
{ok, Spec} ->
[{Name, Level, Size, Spec,
Count}|validate_logfiles(T)];
{error, _} when Date == "" ->
%% blank ones are fine.
[{Name, Level, Size, undefined,
Count}|validate_logfiles(T)];
{error, _} ->
?INT_LOG(error, "Invalid rotation date of ~p for ~s.",
[Date, Name]),
validate_logfiles(T)
end
end;
validate_logfiles([H|T]) ->
?INT_LOG(error, "Invalid logfile config ~p.", [H]),

+ 3
- 3
src/lager_sup.erl Wyświetl plik

@ -42,15 +42,15 @@ init([]) ->
Crash = case application:get_env(lager, crash_log) of
{ok, File} ->
MaxBytes = case application:get_env(lager, crash_log_msg_size) of
{ok, Val} when is_integer(Val) -> Val;
{ok, Val} when is_integer(Val) andalso Val > 0 -> Val;
_ -> 65536
end,
RotationSize = case application:get_env(lager, crash_log_size) of
{ok, Val1} when is_integer(Val1) -> Val1;
{ok, Val1} when is_integer(Val1) andalso Val1 >= 0 -> Val1;
_ -> 0
end,
RotationCount = case application:get_env(lager, crash_log_count) of
{ok, Val2} when is_integer(Val2) -> Val2;
{ok, Val2} when is_integer(Val2) andalso Val2 >=0 -> Val2;
_ -> 0
end,
RotationDate = case application:get_env(lager, crash_log_date) of

Ładowanie…
Anuluj
Zapisz