|
@ -54,12 +54,32 @@ |
|
|
-define(SHOULD_LOG(Level), |
|
|
-define(SHOULD_LOG(Level), |
|
|
lager_util:level_to_num(Level) =< lager_mochiglobal:get(loglevel, ?LOG_NONE)). |
|
|
lager_util:level_to_num(Level) =< lager_mochiglobal:get(loglevel, ?LOG_NONE)). |
|
|
|
|
|
|
|
|
|
|
|
-define(NOTIFY(Level, Pid, Format, Args), |
|
|
|
|
|
gen_event:notify(lager_event, {log, lager_util:level_to_num(Level), |
|
|
|
|
|
lager_util:format_time(), [io_lib:format("[~p] ", [Level]), |
|
|
|
|
|
io_lib:format("~p ", [Pid]), io_lib:format(Format, Args)]})). |
|
|
|
|
|
|
|
|
|
|
|
%% FOR INTERNAL USE ONLY |
|
|
%% internal non-blocking logging call |
|
|
%% internal non-blocking logging call |
|
|
|
|
|
%% there's some special handing for when we try to log (usually errors) while |
|
|
|
|
|
%% lager is still starting. |
|
|
-define(INT_LOG(Level, Format, Args), |
|
|
-define(INT_LOG(Level, Format, Args), |
|
|
case ?SHOULD_LOG(Level) of |
|
|
|
|
|
true -> |
|
|
|
|
|
gen_event:notify(lager_event, {log, lager_util:level_to_num(Level), |
|
|
|
|
|
lager_util:format_time(), [io_lib:format("[~p] ", [Level]), io_lib:format("~p ", [self()]), io_lib:format(Format, Args)]}); |
|
|
|
|
|
_ -> ok |
|
|
|
|
|
end). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Self = self(), |
|
|
|
|
|
%% do this in a spawn so we don't cause a deadlock calling gen_event:which_handlers |
|
|
|
|
|
%% from a gen_event handler |
|
|
|
|
|
spawn(fun() -> |
|
|
|
|
|
case catch(gen_event:which_handlers(lager_event)) of |
|
|
|
|
|
X when X == []; X == {'EXIT', noproc} -> |
|
|
|
|
|
%% there's no handlers yet or lager isn't running, try again |
|
|
|
|
|
%% in half a second. |
|
|
|
|
|
timer:sleep(500), |
|
|
|
|
|
?NOTIFY(Level, Self, Format, Args); |
|
|
|
|
|
_ -> |
|
|
|
|
|
case ?SHOULD_LOG(Level) of |
|
|
|
|
|
true -> |
|
|
|
|
|
?NOTIFY(Level, Self, Format, Args); |
|
|
|
|
|
_ -> |
|
|
|
|
|
ok |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
end)). |