Permalink
Browse files

Add caching of 'sync_dispatch_log' app env value in proc dict

Works better than vanilla app env lookup on each dispatch.
  • Loading branch information...
1 parent 7ad002b commit 987ee58ff83c2a73dc8c3acfa67398098b797991 @aleksandr-vin committed Nov 30, 2012
Showing with 16 additions and 7 deletions.
  1. +16 −7 src/lager.erl
View
@@ -74,15 +74,11 @@ dispatch_log(Severity, Metadata, Format, Args, Size) when is_atom(Severity)->
A when is_list(A) ->safe_format_chop(Format,Args,Size);
_ -> Format
end,
- SyncMode =
- case application:get_env(lager, sync_dispatch_log) of
- {ok, true} -> true;
- _ -> false
- end,
- if SyncMode ->
+ case is_sync_dispatch_log() of
+ true ->
gen_event:sync_notify(Pid, {log, lager_msg:new(Msg, Timestamp,
Severity, Metadata, Destinations)});
- true ->
+ _ ->
gen_event:notify(Pid, {log, lager_msg:new(Msg, Timestamp,
Severity, Metadata, Destinations)})
end;
@@ -275,3 +271,16 @@ safe_format(Fmt, Args, Limit, Options) ->
%% @private
safe_format_chop(Fmt, Args, Limit) ->
safe_format(Fmt, Args, Limit, [{chomp, true}]).
+
+%% private
+is_sync_dispatch_log() ->
+ case erlang:get(sync_dispatch_log) of
+ undefined ->
+ Env = case application:get_env(lager, sync_dispatch_log) of
+ {ok, true} -> true;
+ _ -> false
+ end,
+ erlang:put(sync_dispatch_log, Env),
+ Env;
+ V -> V
+ end.

0 comments on commit 987ee58

Please sign in to comment.