소스 검색

Support backend modules defining their own gen_event handler ID

pull/102/head
Andrew Thompson 12 년 전
부모
커밋
da4e0cfa84
2개의 변경된 파일22개의 추가작업 그리고 7개의 파일을 삭제
  1. +11
    -7
      src/lager_app.erl
  2. +11
    -0
      src/lager_file_backend.erl

+ 11
- 7
src/lager_app.erl 파일 보기

@ -79,17 +79,21 @@ stop(Handlers) ->
expand_handlers([]) ->
[];
expand_handlers([{lager_file_backend, Configs}|T]) ->
[ to_config(Config) || Config <- Configs] ++
[ {lager_file_backend:config_to_id(Config), Config} || Config <- Configs] ++
expand_handlers(T);
expand_handlers([{Mod, Config}|T]) when is_atom(Mod) ->
%% allow the backend to generate a gen_event handler id, if it wants to
code:load_file(Mod),
Res = case erlang:function_exported(Mod, config_to_id, 1) of
true ->
{Mod:config_to_id(Config), Config};
false ->
{Mod, Config}
end,
[Res | expand_handlers(T)];
expand_handlers([H|T]) ->
[H | expand_handlers(T)].
to_config({Name,Severity}) ->
{{lager_file_backend, Name}, {Name, Severity}};
to_config({Name,_Severity,_Size,_Rotation,_Count}=Config) ->
{{lager_file_backend, Name}, Config};
to_config([{Name,_Severity,_Size,_Rotation,_Count}, _Format] = Config) ->
{{lager_file_backend, Name}, Config}.

+ 11
- 0
src/lager_file_backend.erl 파일 보기

@ -41,6 +41,8 @@
-export([init/1, handle_call/2, handle_event/2, handle_info/2, terminate/2,
code_change/3]).
-export([config_to_id/1]).
-record(state, {
name :: string(),
level :: integer(),
@ -121,6 +123,15 @@ terminate(_Reason, #state{fd=FD}) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%% convert the config into a gen_event handler ID
config_to_id({Name,_Severity}) ->
{?MODULE, Name};
config_to_id({Name,_Severity,_Size,_Rotation,_Count}) ->
{?MODULE, Name};
config_to_id([{Name,_Severity,_Size,_Rotation,_Count}, _Format]) ->
{?MODULE, Name}.
write(#state{name=Name, fd=FD, inode=Inode, flap=Flap, size=RotSize,
count=Count} = State, Level, Msg) ->
case lager_util:ensure_logfile(Name, FD, Inode, true) of

불러오는 중...
취소
저장