Permalink
Browse files

Cleanups and support for elog/elogger/fast_log

  • Loading branch information...
1 parent c2beb7e commit 7adb11e8d794378c5af2a09c8c25ace474aa09f8 @Vagabond committed Mar 13, 2013
Showing with 104 additions and 11 deletions.
  1. +1 −7 bin/bench
  2. +4 −1 rebar.config
  3. +2 −1 run.sh
  4. +97 −2 src/logbench.erl
View
@@ -36,7 +36,7 @@ run(Bench, Format, Iterations) ->
{Setup, Fun, Stop} = logbench:Bench(logfmt:Format()),
Setup(),
io:format("running ~p ~p with ~p iterations~n", [Bench, Format, Iterations]),
- {Time, _} = timer:tc(fun() -> [Fun() || _ <- lists:seq(0, Runs)], Stop() end),
+ {Time, _} = timer:tc(fun() -> [Fun() || _ <- lists:seq(1, Runs)], Stop() end),
Seconds = Time / 1000000,
io:format("Result ~p ops/sec ~p~n", [trunc(Runs/Seconds), Seconds]),
OutFile = lists:flatten(["results/", atom_to_list(Bench), "_", atom_to_list(Format)]),
@@ -62,12 +62,6 @@ usage() ->
setup_paths() ->
true = code:add_pathz(filename:dirname(escript:script_name())
++ "/../ebin"),
- true = code:add_pathz(filename:dirname(escript:script_name())
- ++ "/../deps/lager/ebin"),
- true = code:add_pathz(filename:dirname(escript:script_name())
- ++ "/../deps/log4erl/ebin"),
- true = code:add_pathz(filename:dirname(escript:script_name())
- ++ "/../deps/alog/ebin"),
ok.
View
@@ -5,7 +5,10 @@
{deps, [
{lager, "2.0.*", {git, "git://github.com/basho/lager", {branch, "master"}}},
{log4erl, "0.9.*", {git, "git://github.com/ahmednawras/log4erl.git", {branch, "master"}}},
- {alog, "1", {git, "git://github.com/siberian-fast-food/alogger.git", {branch, "master"}}}
+ {alog, "1", {git, "git://github.com/siberian-fast-food/alogger.git", {branch, "master"}}},
+ {elogger, "1.2", {git, "git://github.com/etnt/elogger.git", {branch, "master"}}},
+ {elog, "2.5", {git, "git://github.com/inaka/elog.git", {branch, "master"}}},
+ {fast_log, ".*", {git, "git://github.com/opscode/fast-log-erlang.git", {branch, "master"}}}
]
}.
View
3 run.sh
@@ -1,6 +1,7 @@
#!/bin/sh
-for BENCH in el_console sync_el_console lager_console log4erl_console alog_console el_file sync_el_file lager_file log4erl_file; do
+#for BENCH in el_console sync_el_console lager_console log4erl_console alog_console el_file sync_el_file lager_file log4erl_file; do
+for BENCH in el_file sync_el_file lager_file log4erl_file elog_file elogger_file fast_log_file; do
for FMT in simple small large; do
for I in 1 2 3; do
./bin/bench $BENCH $FMT 10000
View
@@ -1,6 +1,7 @@
-module(logbench).
-compile([{parse_transform, lager_transform}, export_all]).
+-include_lib("elog/include/elog.hrl").
el_console({Fmt, Args}) ->
{fun() -> ok end,
@@ -16,7 +17,11 @@ sync_el_console({Fmt, Args}) ->
lager_console({Fmt, Args}) ->
{fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/lager/ebin"),
application:load(lager),
+ application:set_env(lager, error_logger_redirect, false),
+ application:set_env(lager, crash_log, undefined),
application:set_env(lager, handlers, [{lager_console_backend, info}]),
lager:start()
end,
@@ -28,6 +33,8 @@ lager_console({Fmt, Args}) ->
log4erl_console({Fmt, Args}) ->
{fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/log4erl/ebin"),
application:load(log4erl),
application:start(log4erl),
log4erl:add_console_appender(cmd_logs, {info, "%j %T [%L] %l%n"})
@@ -36,10 +43,13 @@ log4erl_console({Fmt, Args}) ->
log4erl:error(Fmt, Args)
end,
fun() -> ok end
+ %fun() -> _ = gen_event:which_handlers(default_logger) end
}.
alog_console({Fmt, Args}) ->
{fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/alog/ebin"),
application:start(sasl),
application:start(alog),
ok = alog_control:delete_all_flows(),
@@ -71,7 +81,11 @@ sync_el_file({Fmt, Args}) ->
lager_file({Fmt, Args}) ->
{fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/lager/ebin"),
application:load(lager),
+ application:set_env(lager, error_logger_redirect, false),
+ application:set_env(lager, crash_log, undefined),
application:set_env(lager, handlers, [{lager_file_backend, [{"logs/lager.log", info}]}]),
lager:start()
end,
@@ -83,18 +97,23 @@ lager_file({Fmt, Args}) ->
log4erl_file({Fmt, Args}) ->
{fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/log4erl/ebin"),
application:load(log4erl),
application:start(log4erl),
- log4erl:add_file_appender(cmd_logs, {"logs", "log4erl", {time, 0}, 4, "log", info, "%j %T [%L] %l%n"})
+ log4erl:add_file_appender(cmd_logs, {"logs", "log4erl", {size, 10*1024*1024}, 4, "log", info, "%j %T [%L] %l%n"})
end,
fun() ->
log4erl:error(Fmt, Args)
end,
+ %fun() -> _ = gen_event:which_handlers(default_logger) end
fun() -> ok end
}.
alog_file({Fmt, Args}) ->
{fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/alog/ebin"),
application:start(sasl),
application:load(alog),
application:set_env(alog, enabled_loggers, [alog_disk_log]),
@@ -108,6 +127,82 @@ alog_file({Fmt, Args}) ->
fun() ->
alog:error(Fmt, Args)
end,
- fun() -> ok end
+ %% this seems a little flaky, but better than nothing
+ fun() -> _ = sys:get_status(alog_disk_log) end
+ }.
+
+elog_file({Fmt, Args}) ->
+ {fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/elog/ebin"),
+ application:load(elog),
+ application:set_env(elog, level, info),
+ application:set_env(elog, info, [{logger, {elogger_file, [{file, "logs/elog.log"},
+ {size_limit, 10 * 1024 * 1024},
+ {date_break, false}]}}]),
+ application:start(elog)
+ end,
+ fun() ->
+ ?INFO(Fmt, Args)
+ end,
+ fun() -> _ = sys:get_status('elogger-info', infinity) end
+ }.
+
+elog_console({Fmt, Args}) ->
+ {fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/elog/ebin"),
+ application:load(elog),
+ %% force module load order
+ code:add_patha("deps/elog/ebin"),
+ %% reload the elogger module, as it conflicts with the elogger project
+ code:load_file(elogger),
+ application:set_env(elog, level, info),
+ application:set_env(elog, info, [{logger, {elogger_console, []}}]),
+ application:start(elog)
+ end,
+ fun() ->
+ ?INFO(Fmt, Args)
+ end,
+ fun() -> _ = sys:get_status('elogger-info', infinity) end
+ }.
+
+elogger_file({Fmt, Args}) ->
+ {fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/elogger/ebin"),
+ [[SaslGL]] = ets:match(ac_tab, {{application_master, kernel}, '$1'}),
+ %% set our group leader to the one from kernel
+ %% so elogger can use application:get_env/1
+ erlang:group_leader(SaslGL, self()),
+ %% force module load order
+ code:add_patha("deps/elogger/ebin"),
+ %% reload the elogger module, as it conflicts with the elogger project
+ code:load_file(elogger),
+ application:set_env(kernel, error_logger_mf_file, "logs/elogger"),
+ application:set_env(kernel, error_logger_mf_maxbytes, 10 * 1024 * 1024),
+ application:set_env(kernel, error_logger_mf_maxfiles, 5),
+ elogger:start_link(),
+ %% NOW remove the tty handler, if we do it before elogger tries to call
+ %% error_logger:simple_logger() which causes a crash
+ error_logger:tty(false)
+ end,
+ fun() -> error_logger:error_msg(Fmt, Args) end,
+ fun() -> _ = gen_event:which_handlers(error_logger) end
+ }.
+
+fast_log_file({Fmt, Args}) ->
+ {fun() ->
+ true = code:add_pathz(filename:dirname(escript:script_name())
+ ++ "/../deps/fast_log/ebin"),
+ code:add_patha("deps/fast_log/ebin"),
+ application:load(fast_log),
+ application:set_env(fast_log, loggers, [[{name, fast_logger}, {file, "logs/fast_log.log"}, {file_size, 10 * 1024 * 1024}]]),
+ error_logger:tty(false),
+ application:start(sasl),
+ application:start(fast_log)
+ end,
+ fun() -> fast_log:info(fast_logger, token, Fmt, Args) end,
+ fun() -> _ = gen_event:which_handlers(fast_logger) end
}.

0 comments on commit 7adb11e

Please sign in to comment.