Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

93 строки
3.2 KiB

14 лет назад
14 лет назад
13 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
14 лет назад
  1. * Overview
  2. Lager (as in the beer) 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 and file. More are planned.
  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. The location of the crash log can be specified by the crash_log
  58. application variable. If undefined it is not written at all.
  59. * Runtime loglevel changes
  60. You can change the log level of any lager backend at runtime by doing the
  61. following:
  62. #+BEGIN_EXAMPLE
  63. lager:set_loglevel(lager_console_backend, debug).
  64. #+END_EXAMPLE
  65. Or, for the backend with multiple handles (files, mainly):
  66. #+BEGIN_EXAMPLE
  67. lager:set_loglevel(lager_file_backend, "console.log" debug).
  68. #+END_EXAMPLE
  69. Lager keeps track of the minium log level being used by any backend and
  70. supresses generation of messages lower than that level. This means that debug
  71. log messages, when no backend is consuming debug messages, are effectively
  72. free. A simple benchmark of doing 1 million debug log messages while the
  73. minimum threshold was above that takes less than half a second.