Skip to content
Newer
Older
100644 94 lines (73 sloc) 3.17 KB
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
1 * Overview
7e68976 @Vagabond Try to improve M:F(A) printing a little
Vagabond authored Jul 5, 2011
2 Lager (as in the beer) is a logging framework for Erlang. Its purpose is
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
3 to provide a more traditional way to perform logging in an erlang application
4 that plays nicely with traditional UNIX logging tools like logrotate and
5 syslog.
6
953b8ae @Vagabond Tweak README
Vagabond authored Jul 13, 2011
7 * Features
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
8 - Finer grained log levels (debug, info, notice, warning, error, critical,
9 alert, emergency)
10 - Logger calls are transformed using a parse transform to allow capturing
11 Module/Function/Line/Pid information
12 - When no handler is consuming a log level (eg. debug) no event is even sent
13 to the log handler
de705e4 @Vagabond Corrections to README
Vagabond authored Jul 8, 2011
14 - Supports multiple backends, including console and file. More are planned.
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
15
16 * Usage
17 To use lager in your application, you need to define it as a rebar dep or have
18 some other way of including it in erlang's path. You can then add the
19 following option to the erlang compiler flags
20
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
21 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
22 {parse_transform, lager_transform}
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
23 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
24
de21911 @Vagabond Typo
Vagabond authored Jul 14, 2011
25 Alternately, you can add it to the module you wish to compile with logging
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
26 enabled:
27
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
28 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
29 -compile([{parse_transform, lager_transform}]).
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
30 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
31
32 Once you have built your code with lager, you can then generate log messages
33 by doing the following:
34
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
35 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
36 lager:error("Some message")
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
37 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
38
39 Or:
40
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
41 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
42 lager:warning("Some message with a term: ~p", [Term])
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored Jun 24, 2011
43 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored Jun 24, 2011
44
45 The general form is lager:Severity() where Severity is one of the log levels
46 mentioned above.
47
48 * Configuration
9d48bae @Vagabond More README
Vagabond authored Jun 29, 2011
49 To configure lager's backends, you use an application variable (probably in
50 your app.config):
51
52 #+BEGIN_EXAMPLE
53 {lager,
54 {handlers, [
f45f9c9 @Vagabond Typo in config example
Vagabond authored Jul 20, 2011
55 {lager_console_backend, info},
9d48bae @Vagabond More README
Vagabond authored Jun 29, 2011
56 {lager_file_backend, [{"error.log", error}, {"console.log", info}]}
57 ]}
58 }.
59 #+END_EXAMPLE
60
61 The available configuration options for each backend are listed in their
62 module's documentation.
63
64 * Error logger integration
65 Lager is also supplied with a error_logger handler module that translates
66 traditional erlang error messages into a friendlier format and sends them into
0859c90 @Vagabond Default the error_logger redirect to be on, log to the 'log' dir
Vagabond authored Jun 30, 2011
67 lager itself to be treated like a regular lager log call. To disable this, set
68 the lager application variable `error_logger_redirect' to `false'.
69
70 The error_logger handler will also log more complete error messages (protected
71 with use of trunc_io) to a "crash log" which can be referred to for further
61ae86f @Vagabond Minor documentation tweaks
Vagabond authored Jul 5, 2011
72 information. The location of the crash log can be specified by the crash_log
73 application variable. If undefined it is not written at all.
9d48bae @Vagabond More README
Vagabond authored Jun 29, 2011
74
75 * Runtime loglevel changes
76 You can change the log level of any lager backend at runtime by doing the
77 following:
78
79 #+BEGIN_EXAMPLE
80 lager:set_loglevel(lager_console_backend, debug).
81 #+END_EXAMPLE
82
83 Or, for the backend with multiple handles (files, mainly):
84
85 #+BEGIN_EXAMPLE
61ae86f @Vagabond Minor documentation tweaks
Vagabond authored Jul 5, 2011
86 lager:set_loglevel(lager_file_backend, "console.log" debug).
9d48bae @Vagabond More README
Vagabond authored Jun 29, 2011
87 #+END_EXAMPLE
88
89 Lager keeps track of the minium log level being used by any backend and
90 supresses generation of messages lower than that level. This means that debug
91 log messages, when no backend is consuming debug messages, are effectively
de705e4 @Vagabond Corrections to README
Vagabond authored Jul 8, 2011
92 free. A simple benchmark of doing 1 million debug log messages while the
9d48bae @Vagabond More README
Vagabond authored Jun 29, 2011
93 minimum threshold was above that takes less than half a second.
Something went wrong with that request. Please try again.