Permalink
Browse files

One function doesn't make a module

  • Loading branch information...
1 parent 277dafa commit e07c0481acec6a1a2557357cd9bdc4428e3b8504 @Vagabond Vagabond committed Aug 28, 2012
Showing with 19 additions and 60 deletions.
  1. +0 −56 src/lager_backend_utils.erl
  2. +1 −1 src/lager_console_backend.erl
  3. +1 −1 src/lager_file_backend.erl
  4. +16 −1 src/lager_util.erl
  5. +1 −1 test/lager_test_backend.erl
View
56 src/lager_backend_utils.erl
@@ -1,56 +0,0 @@
-%% Copyright (c) 2011 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 Module containing useful functions for writing lager backends.
-
--module(lager_backend_utils).
-
-%%
-%% Include files
-%%
--include_lib("lager/include/lager.hrl").
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
-%%
-%% Exported Functions
-%%
--export([is_loggable/3]).
-
-%%
-%% API Functions
-%%
-
-
--spec is_loggable(#lager_log_message{},integer(),term()) -> boolean().
-is_loggable(#lager_log_message{severity_as_int=Severity,destinations=Destinations},SeverityThreshold,MyName) ->
- %?debugFmt("is_loggable: Severity=~p, Threshold=~p, Destinations=~p, MyName=~p", [Severity,SeverityThreshold,Destinations,MyName]),
- Severity =< SeverityThreshold orelse lists:member(MyName, Destinations).
-
-
--ifdef(TEST).
-
-is_loggable_test_() ->
- [
- {"Loggable by severity only", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[]},2,me))},
- {"Not loggable by severity only", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[]},1,me))},
- {"Loggable by severity with destination", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[you]},2,me))},
- {"Not loggable by severity with destination", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[you]},1,me))},
- {"Loggable by destination overriding severity", ?_assert(is_loggable(#lager_log_message{severity_as_int=2,destinations=[me]},1,me))}
- ].
-
--endif.
View
2 src/lager_console_backend.erl
@@ -69,7 +69,7 @@ handle_call(_Request, State) ->
%% @private
handle_event(#lager_log_message{}=Message,
#state{level=L,formatter=Formatter,format_config=FormatConfig} = State) ->
- case lager_backend_utils:is_loggable(Message, L, ?MODULE) of
+ case lager_util:is_loggable(Message, L, ?MODULE) of
true ->
io:put_chars(user, Formatter:format(Message,FormatConfig)),
{ok, State};
View
2 src/lager_file_backend.erl
@@ -93,7 +93,7 @@ handle_call(_Request, State) ->
%% @private
handle_event(Message,
#state{name=Name, level=L,formatter=Formatter,formatter_config=FormatConfig} = State) ->
- case lager_backend_utils:is_loggable(Message,L,{lager_file_backend, Name}) of
+ case lager_util:is_loggable(Message,L,{lager_file_backend, Name}) of
true ->
{ok,write(State, Message#lager_log_message.severity_as_int, Formatter:format(Message,FormatConfig)) };
false ->
View
17 src/lager_util.erl
@@ -21,12 +21,14 @@
-export([levels/0, level_to_num/1, num_to_level/1, open_logfile/2,
ensure_logfile/4, rotate_logfile/2, format_time/0, format_time/1,
localtime_ms/0, maybe_utc/1, parse_rotation_date_spec/1,
- calculate_next_rotation/1, validate_trace/1, check_traces/4]).
+ calculate_next_rotation/1, validate_trace/1, check_traces/4, is_loggable/3]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
+-include("lager.hrl").
+
levels() ->
[debug, info, notice, warning, error, critical, alert, emergency].
@@ -327,6 +329,10 @@ check_trace_iter(Attrs, [{Key, Match}|T]) ->
false
end.
+-spec is_loggable(#lager_log_message{},integer(),term()) -> boolean().
+is_loggable(#lager_log_message{severity_as_int=Severity,destinations=Destinations},SeverityThreshold,MyName) ->
+ Severity =< SeverityThreshold orelse lists:member(MyName, Destinations).
+
-ifdef(TEST).
parse_test() ->
@@ -454,4 +460,13 @@ check_trace_test() ->
{[{module, '*'}], 0, bar}], [])),
ok.
+is_loggable_test_() ->
+ [
+ {"Loggable by severity only", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[]},2,me))},
+ {"Not loggable by severity only", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[]},1,me))},
+ {"Loggable by severity with destination", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[you]},2,me))},
+ {"Not loggable by severity with destination", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[you]},1,me))},
+ {"Loggable by destination overriding severity", ?_assert(is_loggable(#lager_log_message{severity_as_int=2,destinations=[me]},1,me))}
+ ].
+
-endif.
View
2 test/lager_test_backend.erl
@@ -56,7 +56,7 @@ handle_call(_Request, State) ->
handle_event(#lager_log_message{severity_as_int=Level,timestamp=Time, message=Message, metadata=Metadata}=Msg,
#state{level=LogLevel,buffer=Buffer,ignored=Ignored} = State) ->
- case lager_backend_utils:is_loggable(Msg, LogLevel, ?MODULE) of
+ case lager_util:is_loggable(Msg, LogLevel, ?MODULE) of
true -> {ok, State#state{buffer=Buffer ++ [{Level, Time, Message, Metadata}]}};
_ -> {ok, State#state{ignored=Ignored ++ [ignored]}}
end;

0 comments on commit e07c048

Please sign in to comment.