Skip to content

Commit 40e8622

Browse files
committed
Initial commit
0 parents  commit 40e8622

File tree

10 files changed

+332
-0
lines changed

10 files changed

+332
-0
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
REBAR=`which rebar`
3+
all: compile
4+
5+
compile: precompile
6+
@($(REBAR) compile skip_deps=true)
7+
8+
precompile:
9+
@($(REBAR) check-deps skip_deps=true)
10+
11+
clean:
12+
@($(REBAR) clean skip_deps=true)
13+
14+
.PHONY: deps test compile precompile

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Fast Erlang/OTP Logging Support
2+
3+
This small OTP application aims to bring together several utilities to provide the fastest and most efficient logging support for Erlang/OTP applications. This includes the formatting enhancements for SASL logging provided by [riak_err](https://github.com/basho/riak_err), and support for *disk_log* based logging plus a few other things.
4+
5+
## Status and Version Management
6+
7+
This project is in alpha at the moment and will use semantic versioning.

ebin/fastlog.app

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{application,
2+
fastlog,
3+
[{description,[]},
4+
{vsn,"1"},
5+
{modules,[fastlog_app,fastlog_server,fastlog_sup]},
6+
{registered,[fastlog_server]},
7+
{applications,[kernel,stdlib,sasl,riak_err]},
8+
{mod,{fastlog_app,[]}},
9+
{env,[{levels,[{debug,on},{warn,on},{info,on},{error,on}]}]}]}.

ebin/fastlog_app.beam

644 Bytes
Binary file not shown.

ebin/fastlog_server.beam

2.31 KB
Binary file not shown.

ebin/fastlog_sup.beam

884 Bytes
Binary file not shown.

rebar.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
{erl_opts, [{outdir, "ebin"}]}.
3+
4+
%% project wide dependencies
5+
{deps, [
6+
%% use riak_err to manage sasl logging
7+
{riak_err, "1.0.1"},
8+
{gen_server2, "1.0.0"}
9+
]}.
10+
11+
{require_otp_vsn, "R13B04|R14"}.

src/fastlog_app.erl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
%% -----------------------------------------------------------------------------
2+
%%
3+
%% fastlog_server: TBD
4+
%%
5+
%% Copyright (c) 2008-2010 Tim Watson (watson.timothy@gmail.com)
6+
%%
7+
%% Permission is hereby granted, free of charge, to any person obtaining a copy
8+
%% of this software and associated documentation files (the "Software"), to deal
9+
%% in the Software without restriction, including without limitation the rights
10+
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
%% copies of the Software, and to permit persons to whom the Software is
12+
%% furnished to do so, subject to the following conditions:
13+
%%
14+
%% The above copyright notice and this permission notice shall be included in
15+
%% all copies or substantial portions of the Software.
16+
%%
17+
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
%% THE SOFTWARE.
24+
%% -----------------------------------------------------------------------------
25+
%%
26+
%% TBC
27+
%%
28+
%% -----------------------------------------------------------------------------
29+
30+
-module(fastlog_app).
31+
32+
-behaviour(application).
33+
34+
%% Application callbacks
35+
-export([start/2, stop/1]).
36+
37+
%% ===================================================================
38+
%% Application callbacks
39+
%% ===================================================================
40+
41+
start(_StartType, _StartArgs) ->
42+
fastlog_sup:start_link().
43+
44+
stop(_State) ->
45+
ok.

src/fastlog_server.erl

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
%% -----------------------------------------------------------------------------
2+
%%
3+
%% fastlog_server: TBD
4+
%%
5+
%% Copyright (c) 2008-2010 Tim Watson (watson.timothy@gmail.com)
6+
%%
7+
%% Permission is hereby granted, free of charge, to any person obtaining a copy
8+
%% of this software and associated documentation files (the "Software"), to deal
9+
%% in the Software without restriction, including without limitation the rights
10+
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
%% copies of the Software, and to permit persons to whom the Software is
12+
%% furnished to do so, subject to the following conditions:
13+
%%
14+
%% The above copyright notice and this permission notice shall be included in
15+
%% all copies or substantial portions of the Software.
16+
%%
17+
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
%% THE SOFTWARE.
24+
%% -----------------------------------------------------------------------------
25+
%%
26+
%% TBC
27+
%% TODO: support for disk_log
28+
%%
29+
%% -----------------------------------------------------------------------------
30+
31+
-module(fastlog_server).
32+
-behaviour(gen_server2).
33+
34+
-spec(debug/1 :: (string()) -> 'ok').
35+
-spec(debug/2 :: (string(), [any()]) -> 'ok').
36+
-spec(info/1 :: (string()) -> 'ok').
37+
-spec(info/2 :: (string(), [any()]) -> 'ok').
38+
-spec(warn/1 :: (string()) -> 'ok').
39+
-spec(warn/2 :: (string(), [any()]) -> 'ok').
40+
-spec(error/1 :: (string()) -> 'ok').
41+
-spec(error/2 :: (string(), [any()]) -> 'ok').
42+
43+
-export([init/1
44+
,handle_call/3
45+
,handle_cast/2
46+
,handle_info/2
47+
,terminate/2
48+
,code_change/3]).
49+
50+
-export([start/0
51+
,start/1
52+
,start_link/0
53+
,start_link/1
54+
,debug/1
55+
,debug/2
56+
,info/1
57+
,info/2
58+
,warn/1
59+
,warn/2
60+
,error/1
61+
,error/2]).
62+
63+
-type(mode() :: on | off).
64+
65+
-record(state, {
66+
debug = off :: mode(),
67+
info = off :: mode(),
68+
warn = off :: mode(),
69+
error = on :: mode()
70+
}).
71+
72+
-spec(start/0 :: () -> {'ok', pid()} | 'ignore' | {'error', any()}).
73+
%% @doc starts erlxsl_fast_log (standalong) with the default options.
74+
start() ->
75+
start([]).
76+
77+
-spec(start/1 :: ([{atom(), term()}]) -> {'ok', pid()} | 'ignore' | {'error', any()}).
78+
%% @doc starts erlxsl_fast_log (standalone) with the supplied options.
79+
start(Options) ->
80+
gen_server:start({local, ?MODULE}, ?MODULE, Options, []).
81+
82+
-spec(start_link/0 :: () -> {'ok', pid()} | 'ignore' | {'error', any()}).
83+
%% @doc starts erlxsl_fast_log with the default options.
84+
start_link() ->
85+
start_link([]).
86+
87+
-spec(start_link/1 :: ([{atom(), term()}]) -> {'ok', pid()} | 'ignore' | {'error', any()}).
88+
%% @doc starts erlxsl_fast_log with the supplied options, for supervision tree membership.
89+
%% Options = {verbose, on | off} %% turn on verbose logging (i.e., log all messages)
90+
%% {debug, on | off} %% turn on debug logging
91+
%% {info, on | off} %% turn on infomational logging
92+
%% {warn, on | off} %% turn on warning logging
93+
%% {error, on | off} %% turn on error logging
94+
start_link(Options) ->
95+
gen_server:start_link({local, ?MODULE}, ?MODULE, Options, []).
96+
97+
debug(Format) ->
98+
gen_server:cast(?MODULE, {debug, Format}).
99+
100+
debug(Format, Args) when is_list(Args) ->
101+
gen_server:cast(?MODULE, {debug, Format, Args}).
102+
103+
info(Format) ->
104+
gen_server:cast(?MODULE, {info, Format}).
105+
106+
info(Format, Args) when is_list(Args) ->
107+
gen_server:cast(?MODULE, {info, Format, Args}).
108+
109+
warn(Format) ->
110+
gen_server:cast(?MODULE, {warn, Format}).
111+
112+
warn(Format, Args) when is_list(Args) ->
113+
gen_server:cast(?MODULE, {warn, Format, Args}).
114+
115+
error(Format) ->
116+
gen_server:cast(?MODULE, {error, Format}).
117+
118+
error(Format, Args) when is_list(Args) ->
119+
gen_server:cast(?MODULE, {error, Format, Args}).
120+
121+
%%--------------------------------------------------------------------
122+
123+
init(Options) ->
124+
Verbose = proplists:get_value(verbose, Options, on),
125+
{ok, #state{
126+
debug = proplists:get_value(debug, Options, Verbose),
127+
info = proplists:get_value(info, Options, Verbose),
128+
warn = proplists:get_value(warn, Options, Verbose),
129+
error = proplists:get_value(error, Options, Verbose)
130+
}}.
131+
132+
handle_call(_Request, _From, State) ->
133+
{noreply, State}.
134+
135+
handle_cast({debug, _}, #state{debug=off}=State) ->
136+
{noreply, State};
137+
handle_cast({debug, Format}, State) ->
138+
error_logger:info_msg(Format, []),
139+
{noreply, State};
140+
handle_cast({debug, _, _}, #state{debug=off}=State) ->
141+
{noreply, State};
142+
handle_cast({debug, Format, Args}, State) ->
143+
error_logger:info_msg(Format, Args),
144+
{noreply, State};
145+
handle_cast({info, _}, #state{debug=off}=State) ->
146+
{noreply, State};
147+
handle_cast({info, Format}, State) ->
148+
error_logger:info_msg(Format, []),
149+
{noreply, State};
150+
handle_cast({info, _, _}, #state{info=off}=State) ->
151+
{noreply, State};
152+
handle_cast({info, Format, Args}, State) ->
153+
error_logger:info_msg(Format, Args),
154+
{noreply, State};
155+
handle_cast({warn, _}, #state{warn=off}=State) ->
156+
{noreply, State};
157+
handle_cast({warn, Format}, State) ->
158+
error_logger:warning_msg(Format, []),
159+
{noreply, State};
160+
handle_cast({warn, _, _}, #state{warn=off}=State) ->
161+
{noreply, State};
162+
handle_cast({warn, Format, Args}, State) ->
163+
error_logger:warning_msg(Format, Args),
164+
{noreply, State};
165+
handle_cast({error, _}, #state{error=off}=State) ->
166+
{noreply, State};
167+
handle_cast({error, Format}, State) ->
168+
error_logger:error_msg(Format, []),
169+
{noreply, State};
170+
handle_cast({error, _, _}, #state{error=off}=State) ->
171+
{noreply, State};
172+
handle_cast({error, Format, Args}, State) ->
173+
error_logger:error_msg(Format, Args),
174+
{noreply, State};
175+
handle_cast(_Msg, State) ->
176+
{noreply, State}.
177+
178+
handle_info({driver_log, {Level, Format}}, State) ->
179+
handle_cast({Level, Format}, State);
180+
handle_info(_Info, State) ->
181+
{noreply, State}.
182+
183+
terminate(_Reason, _State) ->
184+
ok.
185+
186+
code_change(_OldVsn, State, _Extra) ->
187+
{ok, State}.

src/fastlog_sup.erl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
%% -----------------------------------------------------------------------------
2+
%%
3+
%% fastlog_server: TBD
4+
%%
5+
%% Copyright (c) 2008-2010 Tim Watson (watson.timothy@gmail.com)
6+
%%
7+
%% Permission is hereby granted, free of charge, to any person obtaining a copy
8+
%% of this software and associated documentation files (the "Software"), to deal
9+
%% in the Software without restriction, including without limitation the rights
10+
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
%% copies of the Software, and to permit persons to whom the Software is
12+
%% furnished to do so, subject to the following conditions:
13+
%%
14+
%% The above copyright notice and this permission notice shall be included in
15+
%% all copies or substantial portions of the Software.
16+
%%
17+
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
%% THE SOFTWARE.
24+
%% -----------------------------------------------------------------------------
25+
%%
26+
%% TBC
27+
%%
28+
%% -----------------------------------------------------------------------------
29+
30+
-module(fastlog_sup).
31+
32+
-behaviour(supervisor).
33+
34+
%% API
35+
-export([start_link/0]).
36+
37+
%% Supervisor callbacks
38+
-export([init/1]).
39+
40+
%% ===================================================================
41+
%% API functions
42+
%% ===================================================================
43+
44+
start_link() ->
45+
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
46+
47+
%% ===================================================================
48+
%% Supervisor callbacks
49+
%% ===================================================================
50+
51+
init(Config) ->
52+
%% FIXME: setting debug=on should set all the others too..
53+
LogLevels = proplists:get_value(levels, Config, []),
54+
{ok, {{one_for_one, 5, 10}, [
55+
{fastlog_server,
56+
{fastlog_server, start_link, [LogLevels]},
57+
permanent, 5000, worker, [gen_server]}
58+
]}}.
59+

0 commit comments

Comments
 (0)