Permalink
Browse files

Add preprocessor defines for choosing 'sync' or 'async' mode of the l…

…ager

For those who need more efficiency on each log call: there are now
LAGER_ASYNC_NOTIFY and LAGER_SYNC_NOTIFY preprocessor definitions. The last one
has higher effective level. If no one is defined, a dynamic mode selection is
used, based on app env 'sync_dispatch_log'.
  • Loading branch information...
1 parent 987ee58 commit 1ba4003f7060f451ac7643777530c2d2552893b9 @aleksandr-vin committed Dec 1, 2012
Showing with 20 additions and 8 deletions.
  1. +20 −8 src/lager.erl
View
@@ -74,14 +74,8 @@ dispatch_log(Severity, Metadata, Format, Args, Size) when is_atom(Severity)->
A when is_list(A) ->safe_format_chop(Format,Args,Size);
_ -> Format
end,
- case is_sync_dispatch_log() of
- true ->
- gen_event:sync_notify(Pid, {log, lager_msg:new(Msg, Timestamp,
- Severity, Metadata, Destinations)});
- _ ->
- gen_event:notify(Pid, {log, lager_msg:new(Msg, Timestamp,
- Severity, Metadata, Destinations)})
- end;
+ notify_log(Pid, {log, lager_msg:new(Msg, Timestamp,
+ Severity, Metadata, Destinations)});
_ ->
ok
end
@@ -273,6 +267,22 @@ safe_format_chop(Fmt, Args, Limit) ->
safe_format(Fmt, Args, Limit, [{chomp, true}]).
%% private
+-ifdef(LAGER_SYNC_NOTIFY).
+notify_log(Pid, Log) ->
+ gen_event:sync_notify(Pid, Log).
+-else.
+-ifdef(LAGER_ASYNC_NOTIFY).
+notify_log(Pid, Log) ->
+ gen_event:notify(Pid, Log).
+-else.
+notify_log(Pid, Log) ->
+ case is_sync_dispatch_log() of
+ true ->
+ gen_event:sync_notify(Pid, Log);
+ _ ->
+ gen_event:notify(Pid, Log)
+ end.
+
is_sync_dispatch_log() ->
case erlang:get(sync_dispatch_log) of
undefined ->
@@ -284,3 +294,5 @@ is_sync_dispatch_log() ->
Env;
V -> V
end.
+-endif.
+-endif.

0 comments on commit 1ba4003

Please sign in to comment.