選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

92 行
3.0 KiB

14年前
14年前
  1. * Overview
  2. Lager (pronounced lAAger) is a logging framework for Erlang. Its purpose is
  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. Features
  7. - Finer grained log levels (debug, info, notice, warning, error, critical,
  8. alert, emergency)
  9. - Logger calls are transformed using a parse transform to allow capturing
  10. Module/Function/Line/Pid information
  11. - When no handler is consuming a log level (eg. debug) no event is even sent
  12. to the log handler
  13. - Supports multiple backends, including console, file and syslog.
  14. * Usage
  15. To use lager in your application, you need to define it as a rebar dep or have
  16. some other way of including it in erlang's path. You can then add the
  17. following option to the erlang compiler flags
  18. #+BEGIN_EXAMPLE
  19. {parse_transform, lager_transform}
  20. #+END_EXAMPLE
  21. Alternately, you can add it to the module you which to compile with logging
  22. enabled:
  23. #+BEGIN_EXAMPLE
  24. -compile([{parse_transform, lager_transform}]).
  25. #+END_EXAMPLE
  26. Once you have built your code with lager, you can then generate log messages
  27. by doing the following:
  28. #+BEGIN_EXAMPLE
  29. lager:error("Some message")
  30. #+END_EXAMPLE
  31. Or:
  32. #+BEGIN_EXAMPLE
  33. lager:warning("Some message with a term: ~p", [Term])
  34. #+END_EXAMPLE
  35. The general form is lager:Severity() where Severity is one of the log levels
  36. mentioned above.
  37. * Configuration
  38. To configure lager's backends, you use an application variable (probably in
  39. your app.config):
  40. #+BEGIN_EXAMPLE
  41. {lager,
  42. {handlers, [
  43. {lager_console_backend, [info]},
  44. {lager_file_backend, [{"error.log", error}, {"console.log", info}]}
  45. ]}
  46. }.
  47. #+END_EXAMPLE
  48. The available configuration options for each backend are listed in their
  49. module's documentation.
  50. * Error logger integration
  51. Lager is also supplied with a error_logger handler module that translates
  52. traditional erlang error messages into a friendlier format and sends them into
  53. lager itself to be treated like a regular lager log call. To disable this, set
  54. the lager application variable `error_logger_redirect' to `false'.
  55. The error_logger handler will also log more complete error messages (protected
  56. with use of trunc_io) to a "crash log" which can be referred to for further
  57. information.
  58. * Runtime loglevel changes
  59. You can change the log level of any lager backend at runtime by doing the
  60. following:
  61. #+BEGIN_EXAMPLE
  62. lager:set_loglevel(lager_console_backend, debug).
  63. #+END_EXAMPLE
  64. Or, for the backend with multiple handles (files, mainly):
  65. #+BEGIN_EXAMPLE
  66. lager:set_loglevel(lager_console_backend, "console.log" debug).
  67. #+END_EXAMPLE
  68. Lager keeps track of the minium log level being used by any backend and
  69. supresses generation of messages lower than that level. This means that debug
  70. log messages, when no backend is consuming debug messages, are effectively
  71. free. A simple benchmark of doing 1 million debug log messages while the the
  72. minimum threshold was above that takes less than half a second.