Browse files

version 0.9

  • Loading branch information...
1 parent bce1577 commit d385ccc3af4730add4e6ff4e9dc3175e81b6a106 @ahmednawras ahmednawras committed Feb 2, 2010
View
9 src/console_appender.erl
@@ -28,9 +28,9 @@ init({Level}) ->
init({Level, Format} = _Args) ->
?LOG2("Initializing console_appender with args = ~p~n",[_Args]),
{ok, Toks} = log_formatter:parse(Format),
- ?LOG2("Tokens received is ~p",[Toks]),
+ ?LOG2("Tokens received is ~p~n",[Toks]),
State = #console_appender{level = Level, format = Toks},
- ?LOG2("State is ~p",[State]),
+ ?LOG2("State is ~p~n",[State]),
{ok, State}.
handle_event({change_level, Level}, State) ->
@@ -48,8 +48,13 @@ handle_call({change_format, Format}, State) ->
?LOG2("Adding format of ~p~n",[Tokens]),
State1 = State#console_appender{format=Tokens},
{ok, ok, State1};
+handle_call({change_level, Level}, State) ->
+ State2 = State#console_appender{level = Level},
+ ?LOG2("Changed level to ~p~n",[Level]),
+ {ok, ok, State2};
handle_call(_Request, State) ->
Reply = ok,
+ ?LOG2("Received unknown request ~p~n", [_Request]),
{ok, Reply, State}.
handle_info(_Info, State) ->
View
2 src/dummy_appender.erl
@@ -18,10 +18,12 @@ handle_event(_Event, State) ->
{ok, State}.
handle_call(_Request, State) ->
+ io:format("dummy_appender called with message ~p~n",[_Request]),
Reply = ok,
{ok, Reply, State}.
handle_info(_Info, State) ->
+ io:format("dummy_appender got info message ~p~n",[_Info]),
{ok, State}.
terminate(_Reason, _State) ->
View
74 src/file_appender.erl
@@ -79,9 +79,9 @@ handle_event({change_level, Level}, State) ->
{ok, State2};
handle_event({log,LLog}, State) ->
?LOG2("handl_event:log = ~p~n",[LLog]),
- ResState = check_rotation(State),
- do_log(LLog, ResState),
- {ok, ResState}.
+ do_log(LLog, State),
+ Res = check_rotation(State),
+ {ok, Res}.
handle_call({change_format, Format}, State) ->
@@ -124,57 +124,18 @@ do_log(_Other, _State) ->
rotate(#file_appender{fd = Fd, dir=Dir, file_name=Fn, counter=Cntr, rotation=Rot, suffix=Suf, log_type=Ltype, level=Level, format=Format} = _S) ->
file:close(Fd),
?LOG("Starting rotation~n"),
- C = if
- Rot == 0 ->
- 0;
- Cntr >= Rot ->
- 1;
- true ->
- Cntr+1
- end,
+ rotate_file(Dir ++ "/" ++ Fn, Rot - 1, Suf),
Src = Dir ++ "/" ++ Fn ++ "." ++ Suf,
- Fname = case C of
- 0 ->
- Dir ++ "/" ++ Fn ++ "." ++ Suf;
- _ ->
- Dir ++ "/" ++ Fn ++ "_" ++ integer_to_list(C) ++ "." ++ Suf
- end,
- ?LOG2("Renaming file from ~p to ~p~n",[Src, Fname]),
- file:rename(Src, Fname),
{ok ,Fd2} = file:open(Src, ?FILE_OPTIONS_ROTATE),
- State2 = #file_appender{dir = Dir, file_name = Fn, fd = Fd2, counter=C, log_type = Ltype, rotation = Rot, suffix=Suf, level=Level, format=Format},
- {ok, State2}.
-
-rotate_daily(#file_appender{fd = Fd, dir=Dir, file_name=Fn, counter=Cntr, rotation=Rot, suffix=Suf, log_type=Ltype, level=Level, format=Format} = _S, {Year, Month, Day}) ->
- file:close(Fd),
- ?LOG("Starting daily rotation~n"),
- Date = lists:flatten(io_lib:format("~4.10.0B-~2.10.0B-~2.10.0B", [Year, Month, Day])),
- Folder = Dir ++ "/" ++ Fn ++ "." ++ lists:flatten(io_lib:format("~4.10.0B-~2.10.0B", [Year, Month])),
- Src = Dir ++ "/" ++ Fn ++ "." ++ Suf,
- Fname = Folder ++ "/" ++ Fn ++ "." ++ Date ++ "." ++ Suf,
- ?LOG2("Moving file from ~p to ~p~n", [Src, Fname]),
-
- % each month has it's own log dir
- file:make_dir(Folder),
- file:rename(Src, Fname),
-
- case erlang:date() of
- {Year, Month, _} -> ok;
- _ ->
- % compress to zip and remove all previous month log files
- RemoveOld = fun() ->
- {ok, _} = zip:create(Folder ++ ".zip", [Folder]),
- {ok, Files} = file:list_dir(Folder),
- lists:foreach(fun(F) -> file:delete(Folder ++ "/" ++ F) end, Files),
- file:del_dir(Folder)
- end,
- spawn(RemoveOld)
- end,
-
- {ok, Fd2} = file:open(Src, ?FILE_OPTIONS_ROTATE),
State2 = #file_appender{dir = Dir, file_name = Fn, fd = Fd2, counter=Cntr, log_type = Ltype, rotation = Rot, suffix=Suf, level=Level, format=Format},
{ok, State2}.
+rotate_file(FileBase, Index, Suffix) when Index > 0 ->
+ file:rename(FileBase ++ "_" ++ integer_to_list(Index) ++ "." ++ Suffix,
+ FileBase ++ "_" ++ integer_to_list(Index + 1) ++ "." ++ Suffix),
+ rotate_file(FileBase, Index - 1, Suffix);
+rotate_file(FileBase, _Index, Suffix) ->
+ file:rename(FileBase ++ "." ++ Suffix, FileBase ++ "_1." ++ Suffix).
% Check if the file needs to be rotated
@@ -193,19 +154,8 @@ check_rotation(State) ->
true ->
State
end;
-
- daily ->
- File = Dir ++ "/" ++ Fname ++ "." ++ Suf,
- {ok, Finfo} = file:read_file_info(File),
- {CDate, _CTime} = Finfo#file_info.ctime,
- case erlang:date() of
- CDate ->
- State;
- _ ->
- {ok, State2} = rotate_daily(State, CDate),
- State2
- end;
-
+ %% time-based rotation is not implemented yet
_ ->
State
end.
+
View
3 src/log4erl.erl
@@ -145,7 +145,8 @@ log(Logger, Level, Log, Data) ->
filter_log(Level, {log, Logger, Level, Log, Data}).
filter_log(Level, Msg) ->
- case log4erl_utils:to_log(log_filter:cutoff_level(), Level) of
+ %case log4erl_utils:to_log(log_filter:cutoff_level(), Level) of
+ case log4erl_utils:to_log(Level, log_filter:cutoff_level()) of
true ->
try_msg(Msg);
false ->
View
2 src/log_filter.erl
@@ -4,4 +4,4 @@
-export([cutoff_level/0]).
-cutoff_level() -> debug.
+cutoff_level() -> all.
View
4 src/log_filter_codegen.erl
@@ -6,7 +6,7 @@
-export([reset/0, set_cutoff_level/1]).
reset() ->
- set_cutoff_level(debug).
+ set_cutoff_level(all).
set_cutoff_level(CutoffLevel) ->
LogFilterMod = log_filter_mod(CutoffLevel),
@@ -25,4 +25,4 @@ log_filter_mod(CutoffLevel) ->
[{attribute,1,module,log_filter},
{attribute,3,export,[{cutoff_level,0}]},
{function,5,cutoff_level,0,[{clause,5,[],[],[{atom,5,CutoffLevel}]}]},
- {eof,5}].
+ {eof,5}].
View
2 src/log_manager.erl
@@ -58,7 +58,7 @@ notify_logger(Logger, Msg) ->
call_appender(Logger, Appender, Msg) ->
try
Apps = gen_event:which_handlers(Logger),
- ?LOG2("log_manager:change_format/3 get apps ~p~n",[Apps]),
+ ?LOG2("log_manager:call_appender/3 get apps ~p~n",[Apps]),
case lists:filter(fun({_,X}) -> X =:= Appender end, Apps) of
[] ->
{error, no_appender_found};
View
4 src/smtp_appender.erl
@@ -79,6 +79,10 @@ handle_call({change_format, Format}, State) ->
S2 = S#msg_opts{msg=Tokens},
State2 = State#smtp_appender{msg_opts=S2},
{ok, ok, State2};
+handle_call({change_level, Level}, State) ->
+ State2 = State#smtp_appender{level = Level},
+ ?LOG2("Changed level to ~p~n",[Level]),
+ {ok, ok, State2};
handle_call(_Request, State) ->
{ok, ok, State}.
View
4 src/syslog_appender.erl
@@ -68,6 +68,10 @@ handle_call({change_format, Format}, State) ->
?LOG2("Adding format of ~p~n",[Tokens]),
S2 = State#syslog_appender{format=Tokens},
{ok, ok, S2};
+handle_call({change_level, Level}, State) ->
+ State2 = State#syslog_appender{level = Level},
+ ?LOG2("Changed level to ~p~n",[Level]),
+ {ok, ok, State2};
handle_call(_Request, State) ->
{ok, ok, State}.
View
4 src/xml_appender.erl
@@ -85,6 +85,10 @@ handle_event({log,LLog}, State) ->
handle_call({change_format, _Format}, State) ->
?LOG("Cannot change format in xml_appender~n"),
{ok, ok, State};
+handle_call({change_level, Level}, State) ->
+ State2 = State#xml_appender{level = Level},
+ ?LOG2("Changed level to ~p~n",[Level]),
+ {ok, ok, State2};
handle_call(_Request, State) ->
Reply = ok,
{ok, Reply, State}.

0 comments on commit d385ccc

Please sign in to comment.