rewrite from lager
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1288 rindas
48 KiB

pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
  1. Overview
  2. --------
  3. Lager (as in the beer) is a logging framework for Erlang. Its purpose is to provide a more traditional way to perform
  4. logging in an erlang application that plays nicely with traditional UNIX logging tools like logrotate and syslog.
  5. [Travis-CI](http://travis-ci.org/erlang-lager/lager) :: [![Build Status](https://travis-ci.org/erlang-lager/lager.svg?branch=master)]
  6. [![Hex pm](https://img.shields.io/hexpm/v/lager)](https://hex.pm/packages/lager)
  7. Features
  8. --------
  9. * Finer grained log levels (debug, info, notice, warning, error, critical, alert, emergency)
  10. * Logger calls are transformed using a parse transform to allow capturing Module/Function/Line/Pid information
  11. * When no handler is consuming a log level (eg. debug) no event is sent to the log handler
  12. * Supports multiple backends, including console and file.
  13. * Supports multiple sinks
  14. * Rewrites common OTP error messages into more readable messages
  15. * Support for pretty printing records encountered at compile time
  16. * Tolerant in the face of large or many log messages, won't out of memory the node
  17. * Optional feature to bypass log size truncation ("unsafe")
  18. * Supports internal time and date based rotation, as well as external rotation tools
  19. * Syslog style log level comparison flags
  20. * Colored terminal output (requires R16+)
  21. * Map support (requires 17+)
  22. * Optional load shedding by setting a high water mark to kill (and reinstall)
  23. a sink after a configurable cool down timer
  24. Contributing
  25. ------------
  26. We welcome contributions from the community. We are always excited to get ideas for improving lager.
  27. If you are looking for an idea to help out, please take a look at our open issues - a number of them are tagged
  28. with [Help Wanted](https://github.com/erlang-lager/lager/issues?q=is%3Aopen+is%3Aissue+label%3A%22Help+Wanted%22)
  29. and [Easy](https://github.com/erlang-lager/lager/issues?q=is%3Aopen+is%3Aissue+label%3AEasy) - some of them are tagged
  30. as both! We are happy to mentor people get started with any of these issues, and they don't need prior discussion.
  31. That being said, before you send large changes please open an issue first to discuss the change you'd like to make along
  32. with an idea of your proposal to implement that change.
  33. ### PR guidelines ###
  34. * Large changes without prior discussion are likely to be rejected.
  35. * Changes without test cases are likely to be rejected.
  36. * Please use the style of the existing codebase when submitting PRs.
  37. We review PRs and issues at least once a month as described below.
  38. OTP Support Policy
  39. ------------------
  40. The lager maintainers intend to support the past three OTP releases from current on the main 3.x branch of the project.
  41. As of August 2019 that includes 22, 21 20
  42. Lager may or may not run on older OTP releases but it will only be guaranteed tested on the previous three OTP releases.
  43. If you need a version of lager which runs on older OTP releases, we recommend you use either the 3.4.0 release or the
  44. 2.x branch.
  45. Monthly triage cadence
  46. ----------------------
  47. We have (at least) monthly issue and PR triage for lager in the #lager room on the
  48. [freenode](https://freenode.net) IRC network every third Thursday at 2 pm US/Pacific, 10 pm UTC. You are welcome to join
  49. us there to ask questions about lager or participate in the triage.
  50. Usage
  51. -----
  52. To use lager in your application, you need to define it as a rebar dep or have some other way of including it in
  53. Erlang's path. You can then add the following option to the erlang compiler flags:
  54. ```erlang
  55. {parse_transform, lager_transform}
  56. ```
  57. Alternately, you can add it to the module you wish to compile with logging enabled:
  58. ```erlang
  59. -compile([{parse_transform, lager_transform}]).
  60. ```
  61. Before logging any messages, you'll need to start the lager application. The lager module's `start` function takes care
  62. of loading and starting any dependencies lager requires.
  63. ```erlang
  64. lager:start().
  65. ```
  66. You can also start lager on startup with a switch to `erl`:
  67. ```erlang
  68. erl -pa path/to/lager/ebin -s lager
  69. ```
  70. Once you have built your code with lager and started the lager application, you can then generate log messages by doing
  71. the following:
  72. ```erlang
  73. lager:error("Some message")
  74. ```
  75. Or:
  76. ```erlang
  77. lager:warning("Some message with a term: ~p", [Term])
  78. ```
  79. The general form is `lager:Severity()` where `Severity` is one of the log levels mentioned above.
  80. Configuration
  81. -------------
  82. To configure lager's backends, you use an application variable (probably in your app.config):
  83. ```erlang
  84. {lager, [
  85. {log_root, "/var/log/hello"},
  86. {handlers, [
  87. {lager_console_backend, [{level, info}]},
  88. {lager_file_backend, [{file, "error.log"}, {level, error}]},
  89. {lager_file_backend, [{file, "console.log"}, {level, info}]}
  90. ]}
  91. ]}.
  92. ```
  93. ```log_root``` variable is optional, by default file paths are relative to CWD.
  94. The available configuration options for each backend are listed in their module's documentation.
  95. Sinks
  96. -----
  97. Lager has traditionally supported a single sink (implemented as a
  98. `gen_event` manager) named `lager_event` to which all backends were connected.
  99. Lager now supports extra sinks; each sink can have different sync/async message thresholds and different backends.
  100. ### Sink configuration
  101. To use multiple sinks (beyond the built-in sink of lager and lager_event), you need to:
  102. 1. Setup rebar.config
  103. 2. Configure the backends in app.config
  104. #### Names
  105. Each sink has two names: one atom to be used like a module name for sending messages, and that atom with `_lager_event`
  106. appended for backend configuration.
  107. This reflects the legacy behavior: `lager:info` (or `critical`, or
  108. `debug`, etc) is a way of sending a message to a sink named
  109. `lager_event`. Now developers can invoke `audit:info` or
  110. `myCompanyName:debug` so long as the corresponding `audit_lager_event` or
  111. `myCompanyName_lager_event` sinks are configured.
  112. #### rebar.config
  113. In `rebar.config` for the project that requires lager, include a list of sink names (without the `_lager_event` suffix)
  114. in `erl_opts`:
  115. `{lager_extra_sinks, [audit]}`
  116. #### Runtime requirements
  117. To be useful, sinks must be configured at runtime with backends.
  118. In `app.config` for the project that requires lager, for example, extend the lager configuration to include
  119. an `extra_sinks` tuple with backends (aka "handlers") and optionally `async_threshold` and
  120. `async_threshold_window` values (see **Overload Protection**
  121. below). If async values are not configured, no overload protection will be applied on that sink.
  122. ```erlang
  123. [{lager, [
  124. {log_root, "/tmp"},
  125. %% Default handlers for lager/lager_event
  126. {handlers, [
  127. {lager_console_backend, [{level, info}]},
  128. {lager_file_backend, [{file, "error.log"}, {level, error}]},
  129. {lager_file_backend, [{file, "console.log"}, {level, info}]}
  130. ]},
  131. %% Any other sinks
  132. {extra_sinks,
  133. [
  134. {audit_lager_event,
  135. [{handlers,
  136. [{lager_file_backend,
  137. [{file, "sink1.log"},
  138. {level, info}
  139. ]
  140. }]
  141. },
  142. {async_threshold, 500},
  143. {async_threshold_window, 50}]
  144. }]
  145. }
  146. ]
  147. }
  148. ].
  149. ```
  150. Custom Formatting
  151. -----------------
  152. All loggers have a default formatting that can be overriden. A formatter is any module that
  153. exports `format(#lager_log_message{},Config#any())`. It is specified as part of the configuration for the backend:
  154. ```erlang
  155. {lager, [
  156. {handlers, [
  157. {lager_console_backend, [{level, info}, {formatter, lager_default_formatter},
  158. {formatter_config, [time, " [",severity, "] ", message, "\n"]}]},
  159. {lager_file_backend, [{file, "error.log"}, {level, error}, {formatter, lager_default_formatter},
  160. {formatter_config, [date, " ", time, " [", severity, "] ",pid, " ", message, "\n"]}]},
  161. {lager_file_backend, [{file, "console.log"}, {level, info}]}
  162. ]}
  163. ]}.
  164. ```
  165. Included is `lager_default_formatter`. This provides a generic, default formatting for log messages using a structure
  166. similar to Erlang's
  167. [iolist](http://learnyousomeerlang.com/buckets-of-sockets#io-lists) which we call "semi-iolist":
  168. * Any traditional iolist elements in the configuration are printed verbatim.
  169. * Atoms in the configuration are treated as placeholders for lager metadata and extracted from the log message.
  170. * The placeholders `date`, `time`, `message`, `sev` and `severity` will always exist.
  171. * `sev` is an abbreviated severity which is interpreted as a capitalized single letter encoding of the severity
  172. level (e.g. `'debug'` -> `$D`)
  173. * The placeholders `pid`, `file`, `line`, `module`, `function`, and `node`
  174. will always exist if the parse transform is used.
  175. * The placeholder `application` may exist if the parse transform is used. It is dependent on finding the
  176. applications `app.src` file.
  177. * If the error logger integration is used, the placeholder `pid`
  178. will always exist and the placeholder `name` may exist.
  179. * Applications can define their own metadata placeholder.
  180. * A tuple of `{atom(), semi-iolist()}` allows for a fallback for the atom placeholder. If the value represented by
  181. the atom cannot be found, the semi-iolist will be interpreted instead.
  182. * A tuple of `{atom(), semi-iolist(), semi-iolist()}` represents a conditional operator: if a value for the atom
  183. placeholder can be found, the first semi-iolist will be output; otherwise, the second will be used.
  184. * A tuple of `{pterm, atom()}` will attempt to lookup the value of the specified atom from the
  185. [persistent_term](http://erlang.org/doc/man/persistent_term.html)
  186. feature added in OTP 21.2. The default value is `""`. The default value will be used if the key cannot be found or
  187. if this formatting term is specified on an OTP release before OTP 21.
  188. * A tuple of `{pterm, atom(), semi-iolist()}` will attempt to lookup the value of the specified atom from the
  189. persistent_term feature added in OTP 21.2. The default value is the specified semi-iolist(). The default value
  190. will be used if the key cannot be found or the if this formatting term is specified on an OTP release before OTP
  191. 21.
  192. Examples:
  193. ```
  194. ["Foo"] -> "Foo", regardless of message content.
  195. [message] -> The content of the logged message, alone.
  196. [{pid,"Unknown Pid"}] -> "<?.?.?>" if pid is in the metadata, "Unknown Pid" if not.
  197. [{pid, ["My pid is ", pid], ["Unknown Pid"]}] -> if pid is in the metadata print "My pid is <?.?.?>", otherwise print "Unknown Pid"
  198. [{server,{pid, ["(", pid, ")"], ["(Unknown Server)"]}}] -> user provided server metadata, otherwise "(<?.?.?>)", otherwise "(Unknown Server)"
  199. [{pterm, pterm_key, <<"undefined">>}] -> if a value for 'pterm_key' is found in OTP 21 (or later) persistent_term storage it is used, otherwise "undefined"
  200. ```
  201. Universal time
  202. --------------
  203. By default, lager formats timestamps as local time for whatever computer generated the log message.
  204. To make lager use UTC timestamps, you can set the `sasl` application's
  205. `utc_log` configuration parameter to `true` in your application configuration file.
  206. Example:
  207. ```
  208. %% format log timestamps as UTC
  209. [{sasl, [{utc_log, true}]}].
  210. ```
  211. Error logger integration
  212. ------------------------
  213. Lager is also supplied with a `error_logger` handler module that translates traditional erlang error messages into a
  214. friendlier format and sends them into lager itself to be treated like a regular lager log call. To disable this, set the
  215. lager application variable `error_logger_redirect` to `false`. You can also disable reformatting for OTP and Cowboy
  216. messages by setting variable
  217. `error_logger_format_raw` to `true`.
  218. If you installed your own handler(s) into `error_logger`, you can tell lager to leave it alone by using
  219. the `error_logger_whitelist` environment variable with a list of handlers to allow.
  220. ```
  221. {error_logger_whitelist, [my_handler]}
  222. ```
  223. The `error_logger` handler will also log more complete error messages (protected with use of `trunc_io`) to a "crash
  224. log" which can be referred to for further information. The location of the crash log can be specified by the `crash_log`
  225. application variable. If set to `false` it is not written at all.
  226. Messages in the crash log are subject to a maximum message size which can be specified via the `crash_log_msg_size`
  227. application variable.
  228. Messages from `error_logger` will be redirected to `error_logger_lager_event` sink if it is defined so it can be
  229. redirected to another log file.
  230. For example:
  231. ```
  232. [{lager, [
  233. {extra_sinks,
  234. [
  235. {error_logger_lager_event,
  236. [{handlers, [
  237. {lager_file_backend, [{file, "error_logger.log"}, {level, info}]}]
  238. }]
  239. }]
  240. }]
  241. }].
  242. ```
  243. will send all `error_logger` messages to `error_logger.log` file.
  244. Overload Protection
  245. -------------------
  246. ### Asynchronous mode
  247. Prior to lager 2.0, the `gen_event` at the core of lager operated purely in synchronous mode. Asynchronous mode is
  248. faster, but has no protection against message queue overload. As of lager 2.0, the `gen_event` takes a hybrid approach.
  249. it polls its own mailbox size and toggles the messaging between synchronous and asynchronous depending on mailbox size.
  250. ```erlang
  251. {async_threshold, 20},
  252. {async_threshold_window, 5}
  253. ```
  254. This will use async messaging until the mailbox exceeds 20 messages, at which point synchronous messaging will be used,
  255. and switch back to asynchronous, when size reduces to `20 - 5 = 15`.
  256. If you wish to disable this behaviour, simply set `async_threshold` to `undefined`. It defaults to a low number to
  257. prevent the mailbox growing rapidly beyond the limit and causing problems. In general, lager should process messages as
  258. fast as they come in, so getting 20 behind should be relatively exceptional anyway.
  259. If you want to limit the number of messages per second allowed from `error_logger`, which is a good idea if you want to
  260. weather a flood of messages when lots of related processes crash, you can set a limit:
  261. ```erlang
  262. {error_logger_hwm, 50}
  263. ```
  264. It is probably best to keep this number small.
  265. ### Event queue flushing
  266. When the high-water mark is exceeded, lager can be configured to flush all event notifications in the message queue.
  267. This can have unintended consequences for other handlers in the same event manager (in e.g. the `error_logger`), as
  268. events they rely on may be wrongly discarded. By default, this behavior is enabled, but can be controlled, for
  269. the `error_logger` via:
  270. ```erlang
  271. {error_logger_flush_queue, true | false}
  272. ```
  273. or for a specific sink, using the option:
  274. ```erlang
  275. {flush_queue, true | false}
  276. ```
  277. If `flush_queue` is true, a message queue length threshold can be set, at which messages will start being discarded. The
  278. default threshold is `0`, meaning that if `flush_queue` is true, messages will be discarded if the high-water mark is
  279. exceeded, regardless of the length of the message queue. The option to control the threshold is, for `error_logger`:
  280. ```erlang
  281. {error_logger_flush_threshold, 1000}
  282. ```
  283. and for sinks:
  284. ```erlang
  285. {flush_threshold, 1000}
  286. ```
  287. ### Sink Killer
  288. In some high volume situations, it may be preferable to drop all pending log messages instead of letting them drain over
  289. time.
  290. If you prefer, you may choose to use the sink killer to shed load. In this operational mode, if the `gen_event` mailbox
  291. exceeds a configurable high water mark, the sink will be killed and reinstalled after a configurable cool down time.
  292. You can configure this behavior by using these configuration directives:
  293. ```erlang
  294. {killer_hwm, 1000},
  295. {killer_reinstall_after, 5000}
  296. ```
  297. This means if the sink's mailbox size exceeds 1000 messages, kill the entire sink and reload it after 5000 milliseconds.
  298. This behavior can also be installed into alternative sinks if desired.
  299. By default, the manager killer *is not installed* into any sink. If the `killer_reinstall_after` cool down time is not
  300. specified it defaults to 5000.
  301. "Unsafe"
  302. --------
  303. The unsafe code pathway bypasses the normal lager formatting code and uses the same code as error_logger in OTP. This
  304. provides a marginal speedup to your logging code (we measured between 0.5-1.3% improvement during our benchmarking;
  305. others have reported better improvements.)
  306. This is a **dangerous** feature. It *will not* protect you against large log messages - large messages can kill your
  307. application and even your Erlang VM dead due to memory exhaustion as large terms are copied over and over in a failure
  308. cascade. We strongly recommend that this code pathway only be used by log messages with a well bounded upper size of
  309. around 500 bytes.
  310. If there's any possibility the log messages could exceed that limit, you should use the normal lager message formatting
  311. code which will provide the appropriate size limitations and protection against memory exhaustion.
  312. If you want to format an unsafe log message, you may use the severity level (as usual) followed by `_unsafe`. Here's an
  313. example:
  314. ```erlang
  315. lager:info_unsafe("The quick brown ~s jumped over the lazy ~s", ["fox", "dog"]).
  316. ```
  317. Runtime loglevel changes
  318. ------------------------
  319. You can change the log level of any lager backend at runtime by doing the following:
  320. ```erlang
  321. lager:set_loglevel(lager_console_backend, debug).
  322. ```
  323. Or, for the backend with multiple handles (files, mainly):
  324. ```erlang
  325. lager:set_loglevel(lager_file_backend, "console.log", debug).
  326. ```
  327. Lager keeps track of the minimum log level being used by any backend and suppresses generation of messages lower than
  328. that level. This means that debug log messages, when no backend is consuming debug messages, are effectively free. A
  329. simple benchmark of doing 1 million debug log messages while the minimum threshold was above that takes less than half a
  330. second.
  331. Syslog style loglevel comparison flags
  332. --------------------------------------
  333. In addition to the regular log level names, you can also do finer grained masking of what you want to log:
  334. ```
  335. info - info and higher (>= is implicit)
  336. =debug - only the debug level
  337. !=info - everything but the info level
  338. <=notice - notice and below
  339. <warning - anything less than warning
  340. ```
  341. These can be used anywhere a loglevel is supplied, although they need to be either a quoted atom or a string.
  342. Internal log rotation
  343. ---------------------
  344. Lager can rotate its own logs or have it done via an external process. To use internal rotation, use the `size`, `date`
  345. and `count` values in the file backend's config:
  346. ```erlang
  347. [{file, "error.log"}, {level, error}, {size, 10485760}, {date, "$D0"}, {count, 5}]
  348. ```
  349. This tells lager to log error and above messages to `error.log` and to rotate the file at midnight or when it reaches
  350. 10mb, whichever comes first, and to keep 5 rotated logs in addition to the current one. Setting the count to 0 does not
  351. disable rotation, it instead rotates the file and keeps no previous versions around. To disable rotation set the size to
  352. 0 and the date to "".
  353. The `$D0` syntax is taken from the syntax newsyslog uses in newsyslog.conf. The relevant extract follows:
  354. ```
  355. Day, week and month time format: The lead-in character
  356. for day, week and month specification is a `$'-sign.
  357. The particular format of day, week and month
  358. specification is: [Dhh], [Ww[Dhh]] and [Mdd[Dhh]],
  359. respectively. Optional time fields default to
  360. midnight. The ranges for day and hour specifications
  361. are:
  362. hh hours, range 0 ... 23
  363. w day of week, range 0 ... 6, 0 = Sunday
  364. dd day of month, range 1 ... 31, or the
  365. letter L or l to specify the last day of
  366. the month.
  367. Some examples:
  368. $D0 rotate every night at midnight
  369. $D23 rotate every day at 23:00 hr
  370. $W0D23 rotate every week on Sunday at 23:00 hr
  371. $W5D16 rotate every week on Friday at 16:00 hr
  372. $M1D0 rotate on the first day of every month at
  373. midnight (i.e., the start of the day)
  374. $M5D6 rotate on every 5th day of the month at
  375. 6:00 hr
  376. ```
  377. On top of the day, week and month time format from newsyslog, hour specification is added from
  378. PR [#420](https://github.com/erlang-lager/lager/pull/420)
  379. ```
  380. Format of hour specification is : [Hmm]
  381. The range for minute specification is:
  382. mm minutes, range 0 ... 59
  383. Some examples:
  384. $H00 rotate every hour at HH:00
  385. $D12H30 rotate every day at 12:30
  386. $W0D0H0 rotate every week on Sunday at 00:00
  387. ```
  388. To configure the crash log rotation, the following application variables are used:
  389. * `crash_log_size`
  390. * `crash_log_date`
  391. * `crash_log_count`
  392. * `crash_log_rotator`
  393. See the `.app.src` file for further details.
  394. Custom Log Rotation
  395. -------------------
  396. Custom log rotator could be configured with option for `lager_file_backend`
  397. ```erlang
  398. {rotator, lager_rotator_default}
  399. ```
  400. The module should provide the following callbacks as `lager_rotator_behaviour`
  401. ```erlang
  402. %% @doc Create a log file
  403. -callback(create_logfile(Name::list(), Buffer::{integer(), integer()} | any()) ->
  404. {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}).
  405. %% @doc Open a log file
  406. -callback(open_logfile(Name::list(), Buffer::{integer(), integer()} | any()) ->
  407. {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}).
  408. %% @doc Ensure reference to current target, could be rotated
  409. -callback(ensure_logfile(Name::list(), FD::file:io_device(), Inode::integer(),
  410. Buffer::{integer(), integer()} | any()) ->
  411. {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}).
  412. %% @doc Rotate the log file
  413. -callback(rotate_logfile(Name::list(), Count::integer()) ->
  414. ok).
  415. ```
  416. Syslog Support
  417. --------------
  418. Lager syslog output is provided as a separate application:
  419. [lager_syslog](https://github.com/erlang-lager/lager_syslog). It is packaged as a separate application so lager itself
  420. doesn't have an indirect dependency on a port driver. Please see the `lager_syslog` README for configuration
  421. information.
  422. Other Backends
  423. --------------
  424. There are lots of them! Some connect log messages to AMQP, various logging analytic
  425. services ([bunyan](https://github.com/Vagabond/lager_bunyan_formatter),
  426. [loggly](https://github.com/kivra/lager_loggly), etc), and
  427. more. [Looking on hex](https://hex.pm/packages?_utf8=✓&search=lager&sort=recent_downloads) or using "lager BACKEND"
  428. where "BACKEND" is your preferred log solution on your favorite search engine is a good starting point.
  429. Exception Pretty Printing
  430. ----------------------
  431. Up to OTP 20:
  432. ```erlang
  433. try
  434. foo()
  435. catch
  436. Class:Reason ->
  437. lager:error(
  438. "~nStacktrace:~s",
  439. [lager:pr_stacktrace(erlang:get_stacktrace(), {Class, Reason})])
  440. end .
  441. ```
  442. On OTP 21+:
  443. ```erlang
  444. try
  445. foo()
  446. catch
  447. Class:Reason:Stacktrace ->
  448. lager:error(
  449. "~nStacktrace:~s",
  450. [lager:pr_stacktrace(Stacktrace, {Class, Reason})])
  451. end .
  452. ```
  453. Record Pretty Printing
  454. ----------------------
  455. Lager's parse transform will keep track of any record definitions it encounters and store them in the module's
  456. attributes. You can then, at runtime, print any record a module compiled with the lager parse transform knows about by
  457. using the
  458. `lager:pr/2` function, which takes the record and the module that knows about the record:
  459. ```erlang
  460. lager:info("My state is ~p", [lager:pr(State, ?MODULE)])
  461. ```
  462. Often, `?MODULE` is sufficent, but you can obviously substitute that for a literal module name.
  463. `lager:pr` also works from the shell.
  464. Colored terminal output
  465. -----------------------
  466. If you have Erlang R16 or higher, you can tell lager's console backend to be colored. Simply add to lager's application
  467. environment config:
  468. ```erlang
  469. {colored, true}
  470. ```
  471. If you don't like the default colors, they are also configurable; see the `.app.src` file for more details.
  472. The output will be colored from the first occurrence of the atom color in the formatting configuration. For example:
  473. ```erlang
  474. {lager_console_backend, [{level, info}, {formatter, lager_default_formatter},
  475. {formatter_config, [time, color, " [", severity, "] ", message, "\e[0m\r\n"]}]]}
  476. ```
  477. This will make the entire log message, except time, colored. The escape sequence before the line break is needed in
  478. order to reset the color after each log message.
  479. Tracing
  480. -------
  481. Lager supports basic support for redirecting log messages based on log message attributes. Lager automatically captures
  482. the pid, module, function and line at the log message callsite. However, you can add any additional attributes you wish:
  483. ```erlang
  484. lager:warning([{request, RequestID}, {vhost, Vhost}], "Permission denied to ~s", [User])
  485. ```
  486. Then, in addition to the default trace attributes, you'll be able to trace based on request or vhost:
  487. ```erlang
  488. lager:trace_file("logs/example.com.error", [{vhost, "example.com"}], error)
  489. ```
  490. To persist metadata for the life of a process, you can use `lager:md/1` to store metadata in the process dictionary:
  491. ```erlang
  492. lager:md([{zone, forbidden}])
  493. ```
  494. Note that `lager:md` will *only* accept a list of key/value pairs keyed by atoms.
  495. You can also omit the final argument, and the loglevel will default to
  496. `debug`.
  497. Tracing to the console is similar:
  498. ```erlang
  499. lager:trace_console([{request, 117}])
  500. ```
  501. In the above example, the loglevel is omitted, but it can be specified as the second argument if desired.
  502. You can also specify multiple expressions in a filter, or use the `*` atom as a wildcard to match any message that has
  503. that attribute, regardless of its value. You may also use the special value `!` to mean, only select if this key is **
  504. not** present.
  505. Tracing to an existing logfile is also supported (but see **Multiple sink support** below):
  506. ```erlang
  507. lager:trace_file("log/error.log", [{module, mymodule}, {function, myfunction}], warning)
  508. ```
  509. To view the active log backends and traces, you can use the `lager:status()`
  510. function. To clear all active traces, you can use `lager:clear_all_traces()`.
  511. To delete a specific trace, store a handle for the trace when you create it, that you later pass
  512. to `lager:stop_trace/1`:
  513. ```erlang
  514. {ok, Trace} = lager:trace_file("log/error.log", [{module, mymodule}]),
  515. ...
  516. lager:stop_trace(Trace)
  517. ```
  518. Tracing to a pid is somewhat of a special case, since a pid is not a data-type that serializes well. To trace by pid,
  519. use the pid as a string:
  520. ```erlang
  521. lager:trace_console([{pid, "<0.410.0>"}])
  522. ```
  523. ### Filter expressions
  524. As of lager 3.3.1, you can also use a 3 tuple while tracing where the second element is a comparison operator. The
  525. currently supported comparison operators are:
  526. * `<` - less than
  527. * `=<` - less than or equal
  528. * `=` - equal to
  529. * `!=` - not equal to
  530. * `>` - greater than
  531. * `>=` - greater than or equal
  532. ```erlang
  533. lager:trace_console([{request, '>', 117}, {request, '<', 120}])
  534. ```
  535. Using `=` is equivalent to the 2-tuple form.
  536. ### Filter composition
  537. As of lager 3.3.1 you may also use the special filter composition keys of
  538. `all` or `any`. For example the filter example above could be expressed as:
  539. ```erlang
  540. lager:trace_console([{all, [{request, '>', 117}, {request, '<', 120}]}])
  541. ```
  542. `any` has the effect of "OR style" logical evaluation between filters; `all`
  543. means "AND style" logical evaluation between filters. These compositional filters expect a list of additional filter
  544. expressions as their values.
  545. ### Null filters
  546. The `null` filter has a special meaning. A filter of `{null, false}` acts as a black hole; nothing is passed through. A
  547. filter of `{null, true}` means
  548. *everything* passes through. No other values for the null filter are valid and will be rejected.
  549. ### Multiple sink support
  550. If using multiple sinks, there are limitations on tracing that you should be aware of.
  551. Traces are specific to a sink, which can be specified via trace filters:
  552. ```erlang
  553. lager:trace_file("log/security.log", [{sink, audit_event}, {function, myfunction}], warning)
  554. ```
  555. If no sink is thus specified, the default lager sink will be used.
  556. This has two ramifications:
  557. * Traces cannot intercept messages sent to a different sink.
  558. * Tracing to a file already opened via `lager:trace_file` will only be successful if the same sink is specified.
  559. The former can be ameliorated by opening multiple traces; the latter can be fixed by rearchitecting lager's file
  560. backend, but this has not been tackled.
  561. ### Traces from configuration
  562. Lager supports starting traces from its configuration file. The keyword to define them is `traces`, followed by a
  563. proplist of tuples that define a backend handler and zero or more filters in a required list, followed by an optional
  564. message severity level.
  565. An example looks like this:
  566. ```erlang
  567. {lager, [
  568. {handlers, [...]},
  569. {traces, [
  570. %% handler, filter, message level (defaults to debug if not given)
  571. {lager_console_backend, [{module, foo}], info},
  572. {{lager_file_backend, "trace.log"}, [{request, '>', 120}], error},
  573. {{lager_file_backend, "event.log"}, [{module, bar}]} %% implied debug level here
  574. ]}
  575. ]}.
  576. ```
  577. In this example, we have three traces. One using the console backend, and two using the file backend. If the message
  578. severity level is left out, it defaults to `debug` as in the last file backend example.
  579. The `traces` keyword works on alternative sinks too but the same limitations and caveats noted above apply.
  580. **IMPORTANT**: You **must** define a severity level in all lager releases up to and including 3.1.0 or previous. The
  581. 2-tuple form wasn't added until 3.2.0.
  582. Setting dynamic metadata at compile-time
  583. ----------------------------------------
  584. Lager supports supplying metadata from external sources by registering a callback function. This metadata is also
  585. persistent across processes even if the process dies.
  586. In general use you won't need to use this feature. However it is useful in situations such as:
  587. * Tracing information provided by
  588. [seq_trace](http://erlang.org/doc/man/seq_trace.html)
  589. * Contextual information about your application
  590. * Persistent information which isn't provided by the default placeholders
  591. * Situations where you would have to set the metadata before every logging call
  592. You can add the callbacks by using the `{lager_parse_transform_functions, X}`
  593. option. It is only available when using `parse_transform`. In rebar, you can add it to `erl_opts` as below:
  594. ```erlang
  595. {erl_opts, [{parse_transform, lager_transform},
  596. {lager_function_transforms,
  597. [
  598. %% Placeholder Resolve type Callback tuple
  599. {metadata_placeholder, on_emit, {module_name, function_name}},
  600. {other_metadata_placeholder, on_log, {module_name, function_name}}
  601. ]}]}.
  602. ```
  603. The first atom is the placeholder atom used for the substitution in your custom formatter.
  604. See [Custom Formatting](#custom-formatting) for more information.
  605. The second atom is the resolve type. This specify the callback to resolve at the time of the message being emitted or at
  606. the time of the logging call. You have to specify either the atom `on_emit` or `on_log`. There is not a 'right' resolve
  607. type to use, so please read the uses/caveats of each and pick the option which fits your requirements best.
  608. `on_emit`:
  609. * The callback functions are not resolved until the message is emitted by the backend.
  610. * If the callback function cannot be resolved, not loaded or produces unhandled errors then `undefined` will be
  611. returned.
  612. * Since the callback function is dependent on a process, there is the chance that message will be emitted after the
  613. dependent process has died resulting in `undefined` being returned. This process can also be your own process
  614. `on_log`:
  615. * The callback functions are resolved regardless whether the message is
  616. emitted or not
  617. * If the callback function cannot be resolved or not loaded the errors are not handled by lager itself.
  618. * Any potential errors in callback should be handled in the callback function itself.
  619. * Because the function is resolved at log time there should be less chance of the dependent process dying before you can
  620. resolve it, especially if you are logging from the app which contains the callback.
  621. The third element is the callback to your function consisting of a tuple in the form `{Module Function}`. The callback
  622. should look like the following regardless if using `on_emit` or `on_log`:
  623. * It should be exported
  624. * It should takes no arguments e.g. has an arity of 0
  625. * It should return any traditional iolist elements or the atom `undefined`
  626. * For errors generated within your callback see the resolve type documentation above.
  627. If the callback returns `undefined` then it will follow the same fallback and conditional operator rules as documented
  628. in the
  629. [Custom Formatting](#custom-formatting) section.
  630. This example would work with `on_emit` but could be unsafe to use with
  631. `on_log`. If the call failed in `on_emit` it would default to `undefined`, however with `on_log` it would error.
  632. ```erlang
  633. -export([my_callback/0]).
  634. my_callback() ->
  635. my_app_serv:call('some options').
  636. ```
  637. This example would be to safe to work with both `on_emit` and `on_log`
  638. ```erlang
  639. -export([my_callback/0]).
  640. my_callback() ->
  641. try my_app_serv:call('some options') of
  642. Result ->
  643. Result
  644. catch
  645. _ ->
  646. %% You could define any traditional iolist elements you wanted here
  647. undefined
  648. end.
  649. ```
  650. Note that the callback can be any Module:Function/0. It does not have be part of your application. For example you could
  651. use `cpu_sup:avg1/0` as your
  652. callback function like so `{cpu_avg1, on_emit, {cpu_sup, avg1}}`
  653. Examples:
  654. ```erlang
  655. -export([reductions/0]).
  656. reductions() ->
  657. proplists:get_value(reductions, erlang:process_info(self())).
  658. ```
  659. ```erlang
  660. -export([seq_trace/0]).
  661. seq_trace() ->
  662. case seq_trace:get_token(label) of
  663. {label, TraceLabel} ->
  664. TraceLabel;
  665. _ ->
  666. undefined
  667. end.
  668. ```
  669. **IMPORTANT**: Since `on_emit` relies on function calls injected at the point where a log message is emitted, your
  670. logging performance (ops/sec)
  671. will be impacted by what the functions you call do and how much latency they may introduce. This impact will even
  672. greater with `on_log` since the calls are injected at the point a message is logged.
  673. Setting the truncation limit at compile-time
  674. --------------------------------------------
  675. Lager defaults to truncating messages at 4096 bytes, you can alter this by using the `{lager_truncation_size, X}`
  676. option. In rebar, you can add it to
  677. `erl_opts`:
  678. ```erlang
  679. {erl_opts, [{parse_transform, lager_transform}, {lager_truncation_size, 1024}]}.
  680. ```
  681. You can also pass it to `erlc`, if you prefer:
  682. ```
  683. erlc -pa lager/ebin +'{parse_transform, lager_transform}' +'{lager_truncation_size, 1024}' file.erl
  684. ```
  685. Suppress applications and supervisors start/stop logs
  686. -----------------------------------------------------
  687. If you don't want to see supervisors and applications start/stop logs in debug level of your application, you can use
  688. these configs to turn it off:
  689. ```erlang
  690. {lager, [{suppress_application_start_stop, true},
  691. {suppress_supervisor_start_stop, true}]}
  692. ```
  693. Sys debug functions
  694. --------------------
  695. Lager provides an integrated way to use sys 'debug functions'. You can install a debug function in a target process by
  696. doing
  697. ```erlang
  698. lager:install_trace(Pid, notice).
  699. ```
  700. You can also customize the tracing somewhat:
  701. ```erlang
  702. lager:install_trace(Pid, notice, [{count, 100}, {timeout, 5000}, {format_string, "my trace event ~p ~p"]}).
  703. ```
  704. The trace options are currently:
  705. * timeout - how long the trace stays installed: `infinity` (the default) or a millisecond timeout
  706. * count - how many trace events to log: `infinity` (default) or a positive number
  707. * format_string - the format string to log the event with. *Must* have 2 format specifiers for the 2 parameters
  708. supplied.
  709. This will, on every 'system event' for an OTP process (usually inbound messages, replies and state changes) generate a
  710. lager message at the specified log level.
  711. You can remove the trace when you're done by doing:
  712. ```erlang
  713. lager:remove_trace(Pid).
  714. ```
  715. If you want to start an OTP process with tracing enabled from the very beginning, you can do something like this:
  716. ```erlang
  717. gen_server:start_link(mymodule, [], [{debug, [{install, {fun lager:trace_func/3, lager:trace_state(undefined, notice, [])}}]}]).
  718. ```
  719. The third argument to the trace_state function is the Option list documented above.
  720. Console output to another group leader process
  721. ----------------------------------------------
  722. If you want to send your console output to another group_leader (typically on another node) you can provide
  723. a `{group_leader, Pid}` argument to the console backend. This can be combined with another console config option, `id`
  724. and gen_event's `{Module, ID}` to allow remote tracing of a node to standard out via nodetool:
  725. ```erlang
  726. GL = erlang:group_leader(),
  727. Node = node(GL),
  728. lager_app:start_handler(lager_event, {lager_console_backend, Node},
  729. [{group_leader, GL}, {level, none}, {id, {lager_console_backend, Node}}]),
  730. case lager:trace({lager_console_backend, Node}, Filter, Level) of
  731. ...
  732. ```
  733. In the above example, the code is assumed to be running via a `nodetool rpc`
  734. invocation so that the code is executing on the Erlang node, but the group_leader is that of the reltool node (eg.
  735. appname_maint_12345@127.0.0.1).
  736. If you intend to use tracing with this feature, make sure the second parameter to start_handler and the `id` parameter
  737. match. Thus when the custom group_leader process exits, lager will remove any associated traces for that handler.
  738. Elixir Support
  739. --------------
  740. There are 2 ways in which Lager can be leveraged in an Elixir project:
  741. 1. Lager Backend for Elixir Logger
  742. 2. Directly
  743. ### Lager Backend for Elixir Logger
  744. [Elixir's Logger](https://hexdocs.pm/logger/Logger.html) is the idiomatic way to add logging into elixir code. Logger
  745. has a plug-in model, allowing for different logging [Backends](https://hexdocs.pm/logger/Logger.html#module-backends)
  746. to be used without the need to change the logging code within your project.
  747. This approach will benefit from the fact that most elixir libs and frameworks are likely to use the elixir Logger and as
  748. such logging will all flow via the same logging mechanism.
  749. In [elixir 1.5 support for parse transforms was deprecated](https://github.com/elixir-lang/elixir/issues/5762). Taking
  750. the "Lager as a Logger Backend" approach is likely bypass any related regression issues that would be introduced into a
  751. project which is using lager directly when updating to elixir 1.5.
  752. There are open source elixir Logger backends for Lager available:
  753. - [LagerLogger](https://github.com/PSPDFKit-labs/lager_logger)
  754. - [LoggerLagerBackend](https://github.com/jonathanperret/logger_lager_backend)
  755. ### Directly
  756. It is fully possible prior to elixir 1.5 to use lager and all its features directly.
  757. After elixir 1.5 there is no support for parse transforms, and it is recommended to use an elixir wrapper for the lager
  758. api that provides compile time log level exclusion via elixir macros when opting for direct use of lager.
  759. Including Lager as a dependency:
  760. ``` elixir
  761. # mix.exs
  762. def application do
  763. [
  764. applications: [:lager],
  765. erl_opts: [parse_transform: "lager_transform"]
  766. ]
  767. end
  768. defp deps do
  769. [{:lager, "~> 3.2"}]
  770. end
  771. ```
  772. Example Configuration:
  773. ``` elixir
  774. # config.exs
  775. use Mix.Config
  776. # Stop lager writing a crash log
  777. config :lager, :crash_log, false
  778. config :lager,
  779. log_root: '/var/log/hello',
  780. handlers: [
  781. lager_console_backend: :info,
  782. lager_file_backend: [file: "error.log", level: :error],
  783. lager_file_backend: [file: "console.log", level: :info]
  784. ]
  785. ```
  786. There is a known issue where Elixir's Logger and Lager both contest for the Erlang `error_logger` handle if used side by
  787. side.
  788. If using both add the following to your `config.exs`:
  789. ```elixir
  790. # config.exs
  791. use Mix.Config
  792. # Stop lager redirecting :error_logger messages
  793. config :lager, :error_logger_redirect, false
  794. # Stop lager removing Logger's :error_logger handler
  795. config :lager, :error_logger_whitelist, [Logger.ErrorHandler]
  796. ```
  797. Example Usage:
  798. ``` elixir
  799. :lager.error('Some message')
  800. :lager.warning('Some message with a term: ~p', [term])
  801. ```
  802. 3.x Changelog
  803. -------------
  804. 3.8.1 - 28 August 2020
  805. * Feature: Allow metadata fields to be whitelisted in log formatting (#514)
  806. * Feature: Enable a persistent_term log formatter (#530) (#531)
  807. * Bugfix: Handle gen_statem crashes in newer OTP releases correctly (#523)
  808. * Cleanup: Add a hex badge (#525)
  809. * Cleanup: Fix Travis CI badge link
  810. * Policy: Officially ending support for OTP 20 (Support OTP 21, 22, 23)
  811. 3.8.0 - 9 August 2019
  812. * Breaking API change: Modify the `lager_rotator_behaviour` to pass in a
  813. file's creation time to `ensure_logfile/5` to be used to determine if
  814. file has changed on systems where inodes are not available (i.e.
  815. `win32`). The return value from `create_logfile/2`, `open_logfile/2` and
  816. `ensure_logfile/5` now requires ctime to be returned (#509)
  817. * Bugfix: ensure log file rotation works on `win32` (#509)
  818. * Bugfix: ensure test suite passes on `win32` (#509)
  819. * Bugfix: ensure file paths with Unicode are formatted properly (#510)
  820. 3.7.0 - 24 May 2019
  821. * Policy: Officially ending support for OTP 19 (Support OTP 20, 21, 22)
  822. * Cleanup: Fix all dialyzer errors
  823. * Bugfix: Minor changes to FSM/statem exits in OTP 22.
  824. 3.6.10 - 30 April 2019
  825. * Documentation: Fix pr_stacktrace invocation example (#494)
  826. * Bugfix: Do not count suppressed messages for message drop counts (#499)
  827. 3.6.9 - 13 March 2019
  828. * Bugfix: Fix file rotation on windows (#493)
  829. 3.6.8 - 21 December 2018
  830. * Documentation: Document the error_logger_whitelist environment variable. (#489)
  831. * Bugfix: Remove the built in handler inside of OTP 21 `logger` system. (#488)
  832. * Bugfix: Cleanup unneeded check for is_map (#486)
  833. * Bugfix: Cleanup ranch errors treated as cowboy errors (#485)
  834. * Testing: Remove OTP 18 from TravisCI testing matrix
  835. 3.6.7 - 14 October 2018
  836. * Bugfix: fix tracing to work with OTP21 #480
  837. 3.6.6 - 24 September 2018
  838. * Bugfix: When printing records, handle an improper list correctly. #478
  839. * Bugfix: Fix various tests and make some rotation code more explicit. #476
  840. * Bugfix: Make sure not to miscount messages during high-water mark check. #475
  841. 3.6.5 - 3 September 2018
  842. * Feature: Allow the console backend to redirect output to a remote node #469
  843. * Feature: is_loggble - support for severity as atom #472
  844. * Bugfix: Prevent silent dropping of messages when hwm is exceeded #467
  845. * Bugfix: rotation - default log file not deleted #474
  846. * Bugfix: Handle strange crash report from gen_statem #473
  847. * Documentation: Various markup fixes: #468 #470
  848. 3.6.4 - 11 July 2018
  849. * Bugfix: Reinstall handlers after a sink is killed #459
  850. * Bugfix: Fix platform_define matching not to break on OSX Mojave #461
  851. * Feature: Add support for installing a sys trace function #462
  852. 3.6.3 - 6 June 2018
  853. * OTP 21 support
  854. 3.6.2 - 26 April 2018
  855. * Bugfix: flush_threshold not working (#449)
  856. * Feature: Add `node` as a formatting option (#447)
  857. * Documentation: Update Elixir section with information about parse_transform (#446)
  858. * Bugfix: Correct default console configuation to use "[{level,info}]" instead (#445)
  859. * Feature: Pretty print lists of records at top level and field values with lager:pr (#442)
  860. * Bugfix: Ignore return value of lager:dispatch_log in lager.hrl (#441)
  861. 3.6.1 - 1 February 2018
  862. * Bugfix: Make a few corrections to the recent mailbox flushing changes (#436)
  863. * Bugfix: add flush options to proplist validation (#439)
  864. * Bugfix: Don't log when we dropped 0 messages (#440)
  865. 3.6.0 - 16 January 2018
  866. * Feature: Support logging with macros per level (#419)
  867. * Feature: Support custom file rotation handler; support hourly file
  868. rotation (#420)
  869. * Feature: Optionally reverse pretty stacktraces (so errors are
  870. at the top and the failed function call is at the bottom.)
  871. (#424)
  872. * Bugfix: Handle OTP 20 gen_server failure where client pid
  873. is dead. (#426)
  874. * Feature: Optionally don't flush notify messages at
  875. high water mark. (#427)
  876. * Bugfix: Handle another stacktrace format (#429)
  877. * Bugfix: Fix test failure using macros on OTP 18 (#430)
  878. * Policy: Remove all code which supports R15 (#432)
  879. 3.5.2 - 19 October 2017
  880. * Bugfix: Properly check for unicode characters in potentially deep
  881. character list. (#417)
  882. 3.5.1 - 15 June 2017
  883. * Doc fix: Missed a curly brace in an example. (#412)
  884. * Feature: Dynamic metadata functions (#392) - It is now possible to
  885. dynamically add metadata to lager messages. See the "dynamic
  886. metadata" section above for more information.
  887. * Doc fix: Add information about the "application" placeholder. (#414)
  888. 3.5.0 - 28 May 2017
  889. * Bugfix: Support OTP 20 gen_event messages (#410)
  890. * Feature: Enable console output to standard_error.
  891. Convert to proplist configuration style (like file handler)
  892. Deprecate previous configuration directives (#409)
  893. * Bugfix: Enable the event shaper to filter messages before they're
  894. counted; do not count application/supervisor start/stops
  895. toward high water mark. (#411)
  896. * Docs: Add PR guidelines; add info about the #lager chat room on freenode.
  897. 3.4.2 - 26 April 2017
  898. * Docs: Document how to make lager use UTC timestamps (#405)
  899. * Docs: Add a note about our triage cadence.
  900. * Docs: Update lager_syslog URL
  901. * Docs: Document placeholders for error_logger integration (#404)
  902. * Feature: Add hex.pm metadata and full rebar3 support.
  903. 3.4.1 - 28 March 2017
  904. * Docs: Added documentation around using lager in the context of elixir applications (#398)
  905. * Bugfix: Properly expand paths when log_root is set. (#386)
  906. * Policy: Removed R15 from Travis configuration
  907. 3.4.0 - 16 March 2017
  908. * Policy: Adopt official OTP support policy. (This is the **last** lager 3.x release
  909. that will support R15.)
  910. * Test: Fix timeouts, R15 missing functions on possibly long-running tests in Travis. (#394, #395)
  911. * Feature: capture and log metadata from error_logger messages (#397)
  912. * Feature: Expose new trace filters and enable filter composition (#389)
  913. * Feature: Log crashes from gen_fsm and gen_statem correctly (#391)
  914. * Docs: Typo in badge URL (#390)
  915. 3.3.0 - 16 February 2017
  916. * Docs: Fix documentation to make 'it' unambiguous when discussing asychronous
  917. operation. (#387)
  918. * Test: Fix test flappiness due to insufficient sanitation between test runs (#384, #385)
  919. * Feature: Allow metadata only logging. (#380)
  920. * Feature: Add an upper case severity formatter (#372)
  921. * Feature: Add support for suppressing start/stop messages from supervisors (#368)
  922. * Bugfix: Fix ranch crash messages (#366)
  923. * Test: Update Travis config for 18.3 and 19.0 (#365)
  924. 3.2.4 - 11 October 2016
  925. * Test: Fix dialyzer warnings.
  926. 3.2.3 - 29 September 2016
  927. * Dependency: Update to goldrush 0.19
  928. 3.2.2 - 22 September 2016
  929. * Bugfix: Backwards-compatibility fix for `{crash_log, undefined}` (#371)
  930. * Fix documentation/README to reflect the preference for using `false`
  931. as the `crash_log` setting value rather than `undefined` to indicate
  932. that the crash log should not be written (#364)
  933. * Bugfix: Backwards-compatibility fix for `lager_file_backend` "legacy"
  934. configuration format (#374)
  935. 3.2.1 - 10 June 2016
  936. * Bugfix: Recent `get_env` changes resulted in launch failure (#355)
  937. * OTP: Support typed records for Erlang 19.0 (#361)
  938. 3.2.0 - 08 April 2016
  939. * Feature: Optional sink killer to shed load when mailbox size exceeds a
  940. configurable high water mark (#346)
  941. * Feature: Export `configure_sink/2` so users may dynamically configure
  942. previously setup and parse transformed sinks from their own code. (#342)
  943. * Feature: Re-enable Travis CI and update .travis.yml (#340)
  944. * Bugfix: Fix test race conditions for Travis CI (#344)
  945. * Bugfix: Add the atom 'none' to the log_level() type so downstream
  946. users won't get dialyzer failures if they use the 'none' log level. (#343)
  947. * Bugfix: Fix typo in documentation. (#341)
  948. * Bugfix: Fix OTP 18 test failures due to `warning_map/0` response
  949. change. (#337)
  950. * Bugfix: Make sure traces that use the file backend work correctly
  951. when specified in lager configuration. (#336)
  952. * Bugfix: Use `lager_app:get_env/3` for R15 compatibility. (#335)
  953. * Bugfix: Make sure lager uses `id` instead of `name` when reporting
  954. supervisor children failures. (The atom changed in OTP in 2014.) (#334)
  955. * Bugfix: Make lager handle improper iolists (#327)
  956. 3.1.0 - 27 January 2016
  957. * Feature: API calls to a rotate handler, sink or all. This change
  958. introduces a new `rotate` message for 3rd party lager backends; that's
  959. why this is released as a new minor version number. (#311)
  960. 3.0.3 - 27 January 2016
  961. * Feature: Pretty printer for human readable stack traces (#298)
  962. * Feature: Make error reformatting optional (#305)
  963. * Feature: Optional and explicit sink for error_logger messages (#303)
  964. * Bugfix: Always explicitly close a file after its been rotated (#316)
  965. * Bugfix: If a relative path already contains the log root, do not add it again (#317)
  966. * Bugfix: Configure and start extra sinks before traces are evaluated (#307)
  967. * Bugfix: Stop and remove traces correctly (#306)
  968. * Bugfix: A byte value of 255 is valid for Unicode (#300)
  969. * Dependency: Bump to goldrush 0.1.8 (#313)