Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 93 lines (72 sloc) 3.118 kb
7bcf044 @Vagabond Initial import
Vagabond authored
1 * Overview
7e68976 @Vagabond Try to improve M:F(A) printing a little
Vagabond authored
2 Lager (as in the beer) is a logging framework for Erlang. Its purpose is
7bcf044 @Vagabond Initial import
Vagabond authored
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
7 Features
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
14 - Supports multiple backends, including console, file and syslog.
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
21 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
22 {parse_transform, lager_transform}
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored
23 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
24
25 Alternately, you can add it to the module you which to compile with logging
26 enabled:
27
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored
28 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
29 -compile([{parse_transform, lager_transform}]).
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored
30 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
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
35 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
36 lager:error("Some message")
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored
37 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
38
39 Or:
40
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored
41 #+BEGIN_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
42 lager:warning("Some message with a term: ~p", [Term])
d4b06a0 @Vagabond Adventures in org mode
Vagabond authored
43 #+END_EXAMPLE
7bcf044 @Vagabond Initial import
Vagabond authored
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
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, [
55 {lager_console_backend, [info]},
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
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
72 information.
9d48bae @Vagabond More README
Vagabond authored
73
74 * Runtime loglevel changes
75 You can change the log level of any lager backend at runtime by doing the
76 following:
77
78 #+BEGIN_EXAMPLE
79 lager:set_loglevel(lager_console_backend, debug).
80 #+END_EXAMPLE
81
82 Or, for the backend with multiple handles (files, mainly):
83
84 #+BEGIN_EXAMPLE
85 lager:set_loglevel(lager_console_backend, "console.log" debug).
86 #+END_EXAMPLE
87
88 Lager keeps track of the minium log level being used by any backend and
89 supresses generation of messages lower than that level. This means that debug
90 log messages, when no backend is consuming debug messages, are effectively
91 free. A simple benchmark of doing 1 million debug log messages while the the
92 minimum threshold was above that takes less than half a second.
Something went wrong with that request. Please try again.