Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove riak_err as a dep; fix some warnings

  • Loading branch information...
commit a1fe3f4496b6ffbabc6392e87c4d94042288ac7a 1 parent 399e43f
@Vagabond Vagabond authored
View
4 rebar.config
@@ -1,8 +1,8 @@
-{erl_opts, [debug_info, fail_on_warning]}.
+{erl_opts, [debug_info]}.
{cover_enabled, true}.
{deps, [
- {riak_err, "1.0.*", {git, "git://github.com/basho/riak_err.git", {branch, "master"}}}
+% {riak_err, "1.0.*", {git, "git://github.com/basho/riak_err.git", {branch, "master"}}}
]}.
View
4 src/lager.erl
@@ -67,14 +67,14 @@ log(Level, Module, Function, Line, Pid, {{Y, M, D}, {H, Mi, S}}, Format, Args) -
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level), Time, Msg}).
log(Level, Pid, Message) ->
- {{Y, M, D}, {H, Mi, S}} = riak_err_stdlib:maybe_utc(erlang:localtime()),
+ {{Y, M, D}, {H, Mi, S}} = lager_stdlib:maybe_utc(erlang:localtime()),
Time = io_lib:format("~b-~b-~b ~b:~b:~b", [Y, M, D, H, Mi, S]),
Msg = io_lib:format("[~p] ~p ~s", [Level, Pid, Message]),
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level),
Time, Msg}).
log(Level, Pid, Format, Args) ->
- {{Y, M, D}, {H, Mi, S}} = riak_err_stdlib:maybe_utc(erlang:localtime()),
+ {{Y, M, D}, {H, Mi, S}} = lager_stdlib:maybe_utc(erlang:localtime()),
Time = io_lib:format("~b-~b-~b ~b:~b:~b", [Y, M, D, H, Mi, S]),
Msg = io_lib:format("[~p] ~p ~s", [Level, Pid, io_lib:format(Format, Args)]),
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level),
View
39 src/lager_stdlib.erl
@@ -26,7 +26,7 @@
-module(lager_stdlib).
--export([string_p/1]).
+-export([string_p/1, maybe_utc/1]).
string_p([]) ->
false;
@@ -49,3 +49,40 @@ string_p1([H|T]) when is_list(H) ->
end;
string_p1([]) -> true;
string_p1(_) -> false.
+
+%% From calendar
+-type year1970() :: 1970..10000. % should probably be 1970..
+-type month() :: 1..12.
+-type day() :: 1..31.
+-type hour() :: 0..23.
+-type minute() :: 0..59.
+-type second() :: 0..59.
+-type t_time() :: {hour(),minute(),second()}.
+-type t_datetime1970() :: {{year1970(),month(),day()},t_time()}.
+
+-spec maybe_utc(t_datetime1970()) -> {utc, t_datetime1970()} | t_datetime1970().
+maybe_utc(Time) ->
+ UTC = case application:get_env(sasl, utc_log) of
+ {ok, Val} ->
+ Val;
+ undefined ->
+ %% Backwards compatible:
+ case application:get_env(stdlib, utc_log) of
+ {ok, Val} ->
+ Val;
+ undefined ->
+ false
+ end
+ end,
+ if
+ UTC =:= true ->
+ UTCTime = case calendar:local_time_to_universal_time_dst(Time) of
+ [] -> calendar:local_time();
+ [T0|_] -> T0
+ end,
+ {utc, UTCTime};
+ true ->
+ Time
+ end.
+
+
View
2  src/lager_transform.erl
@@ -77,7 +77,7 @@ transform_statement({call, Line, {remote, Line1, {atom, Line2, lager},
{integer, Line3, Line},
{call, Line3, {atom, Line3 ,self}, []},
{call, Line3, {remote, Line3,
- {atom, Line3 ,riak_err_stdlib},
+ {atom, Line3 ,lager_stdlib},
{atom,Line3,maybe_utc}},
[{call,Line3,{remote,Line3,
{atom,Line3,erlang},
View
17 test/crash.erl
@@ -5,7 +5,9 @@
-behaviour(gen_server).
--compile([export_all]).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
+
+-export([start/0]).
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [], []).
@@ -31,7 +33,7 @@ handle_call(if_clause, _, State) ->
end;
handle_call(try_clause, _, State) ->
Res = try tuple_to_list(State) of
- [A, B] -> ok
+ [_A, _B] -> ok
catch
_:_ -> ok
end,
@@ -60,11 +62,20 @@ handle_call(badarity, _, State) ->
F = fun(A, B, C) -> A + B + C end,
Res = F(State),
{reply, Res, State};
-handle_call(Call, From, State) ->
+handle_call(_Call, _From, State) ->
{reply, ok, State}.
+handle_cast(_Cast, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
terminate(_, _) ->
ok.
+code_change(_, State, _) ->
+ {ok, State}.
+
function(X) when is_list(X) ->
ok.
View
38 test/lager_test_backend.erl
@@ -54,7 +54,7 @@ handle_call(_Request, State) ->
handle_event({log, Level, Time, Message}, #state{level=LogLevel,
buffer=Buffer} = State) when Level >= LogLevel ->
{ok, State#state{buffer=Buffer ++ [{Level, Time, Message}]}};
-handle_event({log, Level, Time, Message}, #state{ignored=Ignored} = State) ->
+handle_event({log, _Level, _Time, _Message}, #state{ignored=Ignored} = State) ->
{ok, State#state{ignored=Ignored ++ [ignored]}};
handle_event(_Event, State) ->
{ok, State}.
@@ -94,9 +94,9 @@ lager_test_() ->
fun() ->
lager:warning("test message"),
?assertEqual(1, count()),
- {Level, Time, Message} = pop(),
+ {Level, _Time, Message} = pop(),
?assertMatch(Level, lager_util:level_to_num(warning)),
- [LevelStr, LocStr, MsgStr] = re:split(Message, " ", [{return, list}, {parts, 3}]),
+ [LevelStr, _LocStr, MsgStr] = re:split(Message, " ", [{return, list}, {parts, 3}]),
?assertEqual("[warning]", LevelStr),
?assertEqual("test message", MsgStr),
ok
@@ -106,9 +106,9 @@ lager_test_() ->
fun() ->
lager:warning("test message ~p", [self()]),
?assertEqual(1, count()),
- {Level, Time, Message} = pop(),
+ {Level, _Time, Message} = pop(),
?assertMatch(Level, lager_util:level_to_num(warning)),
- [LevelStr, LocStr, MsgStr] = re:split(Message, " ", [{return, list}, {parts, 3}]),
+ [LevelStr, _LocStr, MsgStr] = re:split(Message, " ", [{return, list}, {parts, 3}]),
?assertEqual("[warning]", LevelStr),
?assertEqual(lists:flatten(io_lib:format("test message ~p", [self()])), MsgStr),
ok
@@ -127,7 +127,7 @@ lager_test_() ->
{"logging works from inside a list comprehension",
fun() ->
?assertEqual(0, count()),
- [lager:warning("test message") || N <- lists:seq(1, 10)],
+ [lager:warning("test message") || _N <- lists:seq(1, 10)],
?assertEqual(10, count()),
ok
end
@@ -135,7 +135,7 @@ lager_test_() ->
{"logging works from a begin/end block inside a list comprehension",
fun() ->
?assertEqual(0, count()),
- [ begin lager:warning("test message") end || N <- lists:seq(1, 10)],
+ [ begin lager:warning("test message") end || _N <- lists:seq(1, 10)],
?assertEqual(10, count()),
ok
end
@@ -143,8 +143,8 @@ lager_test_() ->
{"logging works from a nested list comprehension",
fun() ->
?assertEqual(0, count()),
- [ [lager:warning("test message") || N <- lists:seq(1, 10)] ||
- I <- lists:seq(1, 10)],
+ [ [lager:warning("test message") || _N <- lists:seq(1, 10)] ||
+ _I <- lists:seq(1, 10)],
?assertEqual(100, count()),
ok
end
@@ -444,6 +444,26 @@ error_logger_redirect_test_() ->
Expected = lists:flatten(io_lib:format("[info] ~w Supervisor foo started foo:bar/1 at pid baz", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
+ },
+ {"messages should not be generated if they don't satisfy the threshold",
+ fun() ->
+ lager:set_loglevel(?MODULE, error),
+ error_logger:info_report([hello, world]),
+ timer:sleep(100),
+ ?assertEqual(0, count()),
+ ?assertEqual(0, count_ignored()),
+ lager:set_loglevel(?MODULE, info),
+ error_logger:info_report([hello, world]),
+ timer:sleep(100),
+ ?assertEqual(1, count()),
+ ?assertEqual(0, count_ignored()),
+ lager:set_loglevel(?MODULE, error),
+ lager_mochiglobal:put(loglevel, 0),
+ error_logger:info_report([hello, world]),
+ timer:sleep(100),
+ ?assertEqual(1, count()),
+ ?assertEqual(1, count_ignored())
+ end
}
]
}.

0 comments on commit a1fe3f4

Please sign in to comment.
Something went wrong with that request. Please try again.