Permalink
Browse files

Cleanups suggested by @mshonle

  • Loading branch information...
1 parent cf89804 commit 5b3fae60b162c601e365ebcc1cc992157d56571b @Vagabond Vagabond committed Mar 14, 2013
Showing with 32 additions and 9 deletions.
  1. +4 −4 src/lager.erl
  2. +5 −4 src/lager_app.erl
  3. +23 −1 src/lager_backend_throttle.erl
View
@@ -78,13 +78,13 @@ dispatch_log(Severity, Metadata, Format, Args, Size) when is_atom(Severity)->
_ ->
Format
end,
+ LagerMsg = lager_msg:new(Msg, Timestamp,
+ Severity, Metadata, Destinations),
case lager_config:get(async, false) of
true ->
- gen_event:notify(Pid, {log, lager_msg:new(Msg, Timestamp,
- Severity, Metadata, Destinations)});
+ gen_event:notify(Pid, {log, LagerMsg});
false ->
- gen_event:sync_notify(Pid, {log, lager_msg:new(Msg, Timestamp,
- Severity, Metadata, Destinations)})
+ gen_event:sync_notify(Pid, {log, LagerMsg})
end;
false ->
ok
View
@@ -39,10 +39,11 @@ start(_StartType, _StartArgs) ->
case application:get_env(lager, async_threshold) of
undefined ->
ok;
- {ok, Threshold} when is_integer(Threshold), Threshold > 0 ->
- _ = supervisor:start_child(lager_handler_watcher_sup, [lager_event, lager_backend_throttle, [Threshold]]);
- {ok, _BadVal} ->
- ok
+ {ok, Threshold} when is_integer(Threshold), Threshold >= 0 ->
+ _ = supervisor:start_child(lager_handler_watcher_sup, [lager_event, lager_backend_throttle, Threshold]);
+ {ok, BadVal} ->
+ error_logger:error_msg("Invalid value for 'async_threshold': ~p~n", [BadVal]),
+ throw({error, bad_config})
end,
Handlers = case application:get_env(lager, handlers) of
@@ -1,3 +1,25 @@
+%% Copyright (c) 2011-2012 Basho Technologies, Inc. All Rights Reserved.
+%%
+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License. You may obtain
+%% a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+
+%% @doc A simple gen_event backend used to monitor mailbox size and
+%% switch log messages between synchronous and asynchronous modes.
+%% A gen_event handler is used because a process getting its own mailbox
+%% size doesn't involve getting a lock, and gen_event handlers run in their
+%% parent's process.
+
-module(lager_backend_throttle).
-include("lager.hrl").
@@ -12,7 +34,7 @@
async = true
}).
-init([Hwm]) ->
+init(Hwm) ->
lager_config:set(async, true),
{ok, #state{hwm=Hwm}}.

0 comments on commit 5b3fae6

Please sign in to comment.