Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cleanups and support for elog/elogger/fast_log

  • Loading branch information...
commit 7adb11e8d794378c5af2a09c8c25ace474aa09f8 1 parent c2beb7e
Andrew Thompson authored

Showing 4 changed files with 104 additions and 11 deletions. Show diff stats Hide diff stats

  1. +1 7 bin/bench
  2. +4 1 rebar.config
  3. +2 1  run.sh
  4. +97 2 src/logbench.erl
8 bin/bench
@@ -36,7 +36,7 @@ run(Bench, Format, Iterations) ->
36 36 {Setup, Fun, Stop} = logbench:Bench(logfmt:Format()),
37 37 Setup(),
38 38 io:format("running ~p ~p with ~p iterations~n", [Bench, Format, Iterations]),
39   - {Time, _} = timer:tc(fun() -> [Fun() || _ <- lists:seq(0, Runs)], Stop() end),
  39 + {Time, _} = timer:tc(fun() -> [Fun() || _ <- lists:seq(1, Runs)], Stop() end),
40 40 Seconds = Time / 1000000,
41 41 io:format("Result ~p ops/sec ~p~n", [trunc(Runs/Seconds), Seconds]),
42 42 OutFile = lists:flatten(["results/", atom_to_list(Bench), "_", atom_to_list(Format)]),
@@ -62,12 +62,6 @@ usage() ->
62 62 setup_paths() ->
63 63 true = code:add_pathz(filename:dirname(escript:script_name())
64 64 ++ "/../ebin"),
65   - true = code:add_pathz(filename:dirname(escript:script_name())
66   - ++ "/../deps/lager/ebin"),
67   - true = code:add_pathz(filename:dirname(escript:script_name())
68   - ++ "/../deps/log4erl/ebin"),
69   - true = code:add_pathz(filename:dirname(escript:script_name())
70   - ++ "/../deps/alog/ebin"),
71 65 ok.
72 66
73 67
5 rebar.config
@@ -5,7 +5,10 @@
5 5 {deps, [
6 6 {lager, "2.0.*", {git, "git://github.com/basho/lager", {branch, "master"}}},
7 7 {log4erl, "0.9.*", {git, "git://github.com/ahmednawras/log4erl.git", {branch, "master"}}},
8   - {alog, "1", {git, "git://github.com/siberian-fast-food/alogger.git", {branch, "master"}}}
  8 + {alog, "1", {git, "git://github.com/siberian-fast-food/alogger.git", {branch, "master"}}},
  9 + {elogger, "1.2", {git, "git://github.com/etnt/elogger.git", {branch, "master"}}},
  10 + {elog, "2.5", {git, "git://github.com/inaka/elog.git", {branch, "master"}}},
  11 + {fast_log, ".*", {git, "git://github.com/opscode/fast-log-erlang.git", {branch, "master"}}}
9 12 ]
10 13 }.
11 14
3  run.sh
... ... @@ -1,6 +1,7 @@
1 1 #!/bin/sh
2 2
3   -for BENCH in el_console sync_el_console lager_console log4erl_console alog_console el_file sync_el_file lager_file log4erl_file; do
  3 +#for BENCH in el_console sync_el_console lager_console log4erl_console alog_console el_file sync_el_file lager_file log4erl_file; do
  4 +for BENCH in el_file sync_el_file lager_file log4erl_file elog_file elogger_file fast_log_file; do
4 5 for FMT in simple small large; do
5 6 for I in 1 2 3; do
6 7 ./bin/bench $BENCH $FMT 10000
99 src/logbench.erl
... ... @@ -1,6 +1,7 @@
1 1 -module(logbench).
2 2
3 3 -compile([{parse_transform, lager_transform}, export_all]).
  4 +-include_lib("elog/include/elog.hrl").
4 5
5 6 el_console({Fmt, Args}) ->
6 7 {fun() -> ok end,
@@ -16,7 +17,11 @@ sync_el_console({Fmt, Args}) ->
16 17
17 18 lager_console({Fmt, Args}) ->
18 19 {fun() ->
  20 + true = code:add_pathz(filename:dirname(escript:script_name())
  21 + ++ "/../deps/lager/ebin"),
19 22 application:load(lager),
  23 + application:set_env(lager, error_logger_redirect, false),
  24 + application:set_env(lager, crash_log, undefined),
20 25 application:set_env(lager, handlers, [{lager_console_backend, info}]),
21 26 lager:start()
22 27 end,
@@ -28,6 +33,8 @@ lager_console({Fmt, Args}) ->
28 33
29 34 log4erl_console({Fmt, Args}) ->
30 35 {fun() ->
  36 + true = code:add_pathz(filename:dirname(escript:script_name())
  37 + ++ "/../deps/log4erl/ebin"),
31 38 application:load(log4erl),
32 39 application:start(log4erl),
33 40 log4erl:add_console_appender(cmd_logs, {info, "%j %T [%L] %l%n"})
@@ -36,10 +43,13 @@ log4erl_console({Fmt, Args}) ->
36 43 log4erl:error(Fmt, Args)
37 44 end,
38 45 fun() -> ok end
  46 + %fun() -> _ = gen_event:which_handlers(default_logger) end
39 47 }.
40 48
41 49 alog_console({Fmt, Args}) ->
42 50 {fun() ->
  51 + true = code:add_pathz(filename:dirname(escript:script_name())
  52 + ++ "/../deps/alog/ebin"),
43 53 application:start(sasl),
44 54 application:start(alog),
45 55 ok = alog_control:delete_all_flows(),
@@ -71,7 +81,11 @@ sync_el_file({Fmt, Args}) ->
71 81
72 82 lager_file({Fmt, Args}) ->
73 83 {fun() ->
  84 + true = code:add_pathz(filename:dirname(escript:script_name())
  85 + ++ "/../deps/lager/ebin"),
74 86 application:load(lager),
  87 + application:set_env(lager, error_logger_redirect, false),
  88 + application:set_env(lager, crash_log, undefined),
75 89 application:set_env(lager, handlers, [{lager_file_backend, [{"logs/lager.log", info}]}]),
76 90 lager:start()
77 91 end,
@@ -83,18 +97,23 @@ lager_file({Fmt, Args}) ->
83 97
84 98 log4erl_file({Fmt, Args}) ->
85 99 {fun() ->
  100 + true = code:add_pathz(filename:dirname(escript:script_name())
  101 + ++ "/../deps/log4erl/ebin"),
86 102 application:load(log4erl),
87 103 application:start(log4erl),
88   - log4erl:add_file_appender(cmd_logs, {"logs", "log4erl", {time, 0}, 4, "log", info, "%j %T [%L] %l%n"})
  104 + log4erl:add_file_appender(cmd_logs, {"logs", "log4erl", {size, 10*1024*1024}, 4, "log", info, "%j %T [%L] %l%n"})
89 105 end,
90 106 fun() ->
91 107 log4erl:error(Fmt, Args)
92 108 end,
  109 + %fun() -> _ = gen_event:which_handlers(default_logger) end
93 110 fun() -> ok end
94 111 }.
95 112
96 113 alog_file({Fmt, Args}) ->
97 114 {fun() ->
  115 + true = code:add_pathz(filename:dirname(escript:script_name())
  116 + ++ "/../deps/alog/ebin"),
98 117 application:start(sasl),
99 118 application:load(alog),
100 119 application:set_env(alog, enabled_loggers, [alog_disk_log]),
@@ -108,6 +127,82 @@ alog_file({Fmt, Args}) ->
108 127 fun() ->
109 128 alog:error(Fmt, Args)
110 129 end,
111   - fun() -> ok end
  130 + %% this seems a little flaky, but better than nothing
  131 + fun() -> _ = sys:get_status(alog_disk_log) end
  132 + }.
  133 +
  134 +elog_file({Fmt, Args}) ->
  135 + {fun() ->
  136 + true = code:add_pathz(filename:dirname(escript:script_name())
  137 + ++ "/../deps/elog/ebin"),
  138 + application:load(elog),
  139 + application:set_env(elog, level, info),
  140 + application:set_env(elog, info, [{logger, {elogger_file, [{file, "logs/elog.log"},
  141 + {size_limit, 10 * 1024 * 1024},
  142 + {date_break, false}]}}]),
  143 + application:start(elog)
  144 + end,
  145 + fun() ->
  146 + ?INFO(Fmt, Args)
  147 + end,
  148 + fun() -> _ = sys:get_status('elogger-info', infinity) end
  149 + }.
  150 +
  151 +elog_console({Fmt, Args}) ->
  152 + {fun() ->
  153 + true = code:add_pathz(filename:dirname(escript:script_name())
  154 + ++ "/../deps/elog/ebin"),
  155 + application:load(elog),
  156 + %% force module load order
  157 + code:add_patha("deps/elog/ebin"),
  158 + %% reload the elogger module, as it conflicts with the elogger project
  159 + code:load_file(elogger),
  160 + application:set_env(elog, level, info),
  161 + application:set_env(elog, info, [{logger, {elogger_console, []}}]),
  162 + application:start(elog)
  163 + end,
  164 + fun() ->
  165 + ?INFO(Fmt, Args)
  166 + end,
  167 + fun() -> _ = sys:get_status('elogger-info', infinity) end
  168 + }.
  169 +
  170 +elogger_file({Fmt, Args}) ->
  171 + {fun() ->
  172 + true = code:add_pathz(filename:dirname(escript:script_name())
  173 + ++ "/../deps/elogger/ebin"),
  174 + [[SaslGL]] = ets:match(ac_tab, {{application_master, kernel}, '$1'}),
  175 + %% set our group leader to the one from kernel
  176 + %% so elogger can use application:get_env/1
  177 + erlang:group_leader(SaslGL, self()),
  178 + %% force module load order
  179 + code:add_patha("deps/elogger/ebin"),
  180 + %% reload the elogger module, as it conflicts with the elogger project
  181 + code:load_file(elogger),
  182 + application:set_env(kernel, error_logger_mf_file, "logs/elogger"),
  183 + application:set_env(kernel, error_logger_mf_maxbytes, 10 * 1024 * 1024),
  184 + application:set_env(kernel, error_logger_mf_maxfiles, 5),
  185 + elogger:start_link(),
  186 + %% NOW remove the tty handler, if we do it before elogger tries to call
  187 + %% error_logger:simple_logger() which causes a crash
  188 + error_logger:tty(false)
  189 + end,
  190 + fun() -> error_logger:error_msg(Fmt, Args) end,
  191 + fun() -> _ = gen_event:which_handlers(error_logger) end
  192 + }.
  193 +
  194 +fast_log_file({Fmt, Args}) ->
  195 + {fun() ->
  196 + true = code:add_pathz(filename:dirname(escript:script_name())
  197 + ++ "/../deps/fast_log/ebin"),
  198 + code:add_patha("deps/fast_log/ebin"),
  199 + application:load(fast_log),
  200 + application:set_env(fast_log, loggers, [[{name, fast_logger}, {file, "logs/fast_log.log"}, {file_size, 10 * 1024 * 1024}]]),
  201 + error_logger:tty(false),
  202 + application:start(sasl),
  203 + application:start(fast_log)
  204 + end,
  205 + fun() -> fast_log:info(fast_logger, token, Fmt, Args) end,
  206 + fun() -> _ = gen_event:which_handlers(fast_logger) end
112 207 }.
113 208

0 comments on commit 7adb11e

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