From e31ef4326ffeb15f81b955a77e8648c0379dbf1d Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Sat, 27 Feb 2021 18:30:07 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 457 +++--------------------------- eRum.sample.config | 100 +++---- src/eRum.erl | 56 ++-- src/formatter/rumFormatter.erl | 4 +- src/misc/rumErrLoggerH.erl | 302 ++++++++++---------- src/misc/rumTruncIo.erl | 32 +-- test/crash_statem.erl | 8 +- test/lager_test_backend.erl | 502 ++++++++++++++++----------------- 8 files changed, 546 insertions(+), 915 deletions(-) diff --git a/README.md b/README.md index 3517d2d..c9a5d87 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ -# 基于lager 3.9.0 rewrite - - Overview -------- -Lager (as in the beer) is a logging framework for Erlang. Its purpose is to provide a more traditional way to perform -logging in an erlang application that plays nicely with traditional UNIX logging tools like logrotate and syslog. - -[Travis-CI](http://travis-ci.org/erlang-lager/lager) :: [![Build Status](https://travis-ci.org/erlang-lager/lager.svg?branch=master)] -[![Hex pm](https://img.shields.io/hexpm/v/lager)](https://hex.pm/packages/lager) +eRum is a Erlang logger. 基于lager3.9.0 rewrite Features -------- @@ -23,95 +16,60 @@ Features * Optional feature to bypass log size truncation ("unsafe") * Supports internal time and date based rotation, as well as external rotation tools * Syslog style log level comparison flags -* Colored terminal output (requires R16+) -* Map support (requires 17+) +* Colored terminal output * Optional load shedding by setting a high water mark to kill (and reinstall) a sink after a configurable cool down timer - -Contributing ------------- -We welcome contributions from the community. We are always excited to get ideas for improving lager. - -If you are looking for an idea to help out, please take a look at our open issues - a number of them are tagged -with [Help Wanted](https://github.com/erlang-lager/lager/issues?q=is%3Aopen+is%3Aissue+label%3A%22Help+Wanted%22) -and [Easy](https://github.com/erlang-lager/lager/issues?q=is%3Aopen+is%3Aissue+label%3AEasy) - some of them are tagged -as both! We are happy to mentor people get started with any of these issues, and they don't need prior discussion. - -That being said, before you send large changes please open an issue first to discuss the change you'd like to make along -with an idea of your proposal to implement that change. - -### PR guidelines ### - -* Large changes without prior discussion are likely to be rejected. -* Changes without test cases are likely to be rejected. -* Please use the style of the existing codebase when submitting PRs. - -We review PRs and issues at least once a month as described below. - -OTP Support Policy ------------------- -The lager maintainers intend to support the past three OTP releases from current on the main 3.x branch of the project. -As of August 2019 that includes 22, 21 20 - -Lager may or may not run on older OTP releases but it will only be guaranteed tested on the previous three OTP releases. -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 -2.x branch. - -Monthly triage cadence ----------------------- -We have (at least) monthly issue and PR triage for lager in the #lager room on the -[freenode](https://freenode.net) IRC network every third Thursday at 2 pm US/Pacific, 10 pm UTC. You are welcome to join -us there to ask questions about lager or participate in the triage. +* rewrite term format fun, it's more efficient Usage ----- -To use lager in your application, you need to define it as a rebar dep or have some other way of including it in -Erlang's path. You can then add the following option to the erlang compiler flags: +To use eRum in your application, you need to define it as a rebar dep or have some other way of including it in Erlang's +path. You can then add the following option to the erlang compiler flags: ```erlang -{parse_transform, lager_transform} +{parse_transform, rumTransform} ``` Alternately, you can add it to the module you wish to compile with logging enabled: ```erlang --compile([{parse_transform, lager_transform}]). +-compile([{parse_transform, rumTransform}]). ``` -Before logging any messages, you'll need to start the lager application. The lager module's `start` function takes care -of loading and starting any dependencies lager requires. +Before logging any messages, you'll need to start the eRum application. The eRum module's `start` function takes care of +loading and starting any dependencies eRum requires. ```erlang -lager:start(). +eRum:start(). ``` -You can also start lager on startup with a switch to `erl`: +You can also start eRum on startup with a switch to `erl`: ```erlang -erl -pa path/to/lager/ebin -s lager +erl -pa path/to/eRum/ebin -s eRum ``` -Once you have built your code with lager and started the lager application, you can then generate log messages by doing +Once you have built your code with eRum and started the eRum application, you can then generate log messages by doing the following: ```erlang -lager:error("Some message") +eRum:error("Some message") ``` Or: ```erlang -lager:warning("Some message with a term: ~p", [Term]) +eRum:warning("Some message with a term: ~p", [Term]) ``` -The general form is `lager:Severity()` where `Severity` is one of the log levels mentioned above. +The general form is `eRum:Severity()` where `Severity` is one of the log levels mentioned above. Configuration ------------- -To configure lager's backends, you use an application variable (probably in your app.config): +To configure eRum's backends, you use an application variable (probably in your app.config): ```erlang -{lager, [ +{eRum, [ {log_root, "/var/log/hello"}, {handlers, [ {lager_console_backend, [{level, info}]}, @@ -241,7 +199,7 @@ similar to Erlang's * A tuple of `{pterm, atom(), semi-iolist()}` will attempt to lookup the value of the specified atom from the persistent_term feature added in OTP 21.2. The default value is the specified semi-iolist(). The default value will be used if the key cannot be found or the if this formatting term is specified on an OTP release before OTP - 21. + 21. Examples: @@ -525,21 +483,21 @@ The module should provide the following callbacks as `lager_rotator_behaviour` ```erlang %% @doc Create a log file --callback(create_logfile(Name::list(), Buffer::{integer(), integer()} | any()) -> - {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}). +-callback(create_logfile(Name :: list(), Buffer :: {integer(), integer()} | any()) -> + {ok, {FD :: file:io_device(), Inode :: integer(), Size :: integer()}} | {error, any()}). %% @doc Open a log file --callback(open_logfile(Name::list(), Buffer::{integer(), integer()} | any()) -> - {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}). +-callback(open_logfile(Name :: list(), Buffer :: {integer(), integer()} | any()) -> + {ok, {FD :: file:io_device(), Inode :: integer(), Size :: integer()}} | {error, any()}). %% @doc Ensure reference to current target, could be rotated --callback(ensure_logfile(Name::list(), FD::file:io_device(), Inode::integer(), - Buffer::{integer(), integer()} | any()) -> - {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}). +-callback(ensure_logfile(Name :: list(), FD :: file:io_device(), Inode :: integer(), + Buffer :: {integer(), integer()} | any()) -> + {ok, {FD :: file:io_device(), Inode :: integer(), Size :: integer()}} | {error, any()}). %% @doc Rotate the log file --callback(rotate_logfile(Name::list(), Count::integer()) -> - ok). +-callback(rotate_logfile(Name :: list(), Count :: integer()) -> + ok). ``` Syslog Support @@ -837,7 +795,7 @@ This example would work with `on_emit` but could be unsafe to use with -export([my_callback/0]). my_callback() -> - my_app_serv:call('some options'). + my_app_serv:call('some options'). ``` This example would be to safe to work with both `on_emit` and `on_log` @@ -846,14 +804,14 @@ This example would be to safe to work with both `on_emit` and `on_log` -export([my_callback/0]). my_callback() -> - try my_app_serv:call('some options') of - Result -> - Result - catch - _ -> - %% You could define any traditional iolist elements you wanted here - undefined - end. + try my_app_serv:call('some options') of + Result -> + Result + catch + _ -> + %% You could define any traditional iolist elements you wanted here + undefined + end. ``` Note that the callback can be any Module:Function/0. It does not have be part of your application. For example you could @@ -866,19 +824,19 @@ Examples: -export([reductions/0]). reductions() -> - proplists:get_value(reductions, erlang:process_info(self())). + proplists:get_value(reductions, erlang:process_info(self())). ``` ```erlang -export([seq_trace/0]). seq_trace() -> - case seq_trace:get_token(label) of - {label, TraceLabel} -> - TraceLabel; - _ -> - undefined - end. + case seq_trace:get_token(label) of + {label, TraceLabel} -> + TraceLabel; + _ -> + undefined + end. ``` **IMPORTANT**: Since `on_emit` relies on function calls injected at the point where a log message is emitted, your @@ -974,330 +932,3 @@ appname_maint_12345@127.0.0.1). If you intend to use tracing with this feature, make sure the second parameter to start_handler and the `id` parameter match. Thus when the custom group_leader process exits, lager will remove any associated traces for that handler. - -Elixir Support --------------- - -There are 2 ways in which Lager can be leveraged in an Elixir project: - -1. Lager Backend for Elixir Logger -2. Directly - -### Lager Backend for Elixir Logger - -[Elixir's Logger](https://hexdocs.pm/logger/Logger.html) is the idiomatic way to add logging into elixir code. Logger -has a plug-in model, allowing for different logging [Backends](https://hexdocs.pm/logger/Logger.html#module-backends) -to be used without the need to change the logging code within your project. - -This approach will benefit from the fact that most elixir libs and frameworks are likely to use the elixir Logger and as -such logging will all flow via the same logging mechanism. - -In [elixir 1.5 support for parse transforms was deprecated](https://github.com/elixir-lang/elixir/issues/5762). Taking -the "Lager as a Logger Backend" approach is likely bypass any related regression issues that would be introduced into a -project which is using lager directly when updating to elixir 1.5. - -There are open source elixir Logger backends for Lager available: - -- [LagerLogger](https://github.com/PSPDFKit-labs/lager_logger) -- [LoggerLagerBackend](https://github.com/jonathanperret/logger_lager_backend) - -### Directly - -It is fully possible prior to elixir 1.5 to use lager and all its features directly. - -After elixir 1.5 there is no support for parse transforms, and it is recommended to use an elixir wrapper for the lager -api that provides compile time log level exclusion via elixir macros when opting for direct use of lager. - -Including Lager as a dependency: - -``` elixir -# mix.exs -def application do - [ - applications: [:lager], - erl_opts: [parse_transform: "lager_transform"] - ] -end - -defp deps do - [{:lager, "~> 3.2"}] -end -``` - -Example Configuration: - -``` elixir -# config.exs -use Mix.Config - -# Stop lager writing a crash log -config :lager, :crash_log, false - -config :lager, - log_root: '/var/log/hello', - handlers: [ - lager_console_backend: :info, - lager_file_backend: [file: "error.log", level: :error], - lager_file_backend: [file: "console.log", level: :info] - ] -``` - -There is a known issue where Elixir's Logger and Lager both contest for the Erlang `error_logger` handle if used side by -side. - -If using both add the following to your `config.exs`: - -```elixir -# config.exs -use Mix.Config - -# Stop lager redirecting :error_logger messages -config :lager, :error_logger_redirect, false - -# Stop lager removing Logger's :error_logger handler -config :lager, :error_logger_whitelist, [Logger.ErrorHandler] -``` - -Example Usage: - -``` elixir -:lager.error('Some message') -:lager.warning('Some message with a term: ~p', [term]) -``` - -3.x Changelog -------------- -3.9.0 - 24 February 2021 - - * Bugfix: Try to make a log root of "log" more sensible (#540) - * Feature: Further adapt to OTP 24 (also remove pre OTP 21 code), - adopt Github Actions for tests - -3.8.2 - 4 February 2021 - - * Bugfix: Make directory expansion return an absolute path (#535) - * Feature: Write crash.log under the log_root location (#536) - * Bugfix: Handle line numbering correctly in forthcoming OTP 24 release (#537) - - -3.8.1 - 28 August 2020 - - * Feature: Allow metadata fields to be whitelisted in log formatting (#514) - * Feature: Enable a persistent_term log formatter (#530) (#531) - * Bugfix: Handle gen_statem crashes in newer OTP releases correctly (#523) - * Cleanup: Add a hex badge (#525) - * Cleanup: Fix Travis CI badge link - * Policy: Officially ending support for OTP 20 (Support OTP 21, 22, 23) - -3.8.0 - 9 August 2019 - - * Breaking API change: Modify the `lager_rotator_behaviour` to pass in a - file's creation time to `ensure_logfile/5` to be used to determine if - file has changed on systems where inodes are not available (i.e. - `win32`). The return value from `create_logfile/2`, `open_logfile/2` and - `ensure_logfile/5` now requires ctime to be returned (#509) - * Bugfix: ensure log file rotation works on `win32` (#509) - * Bugfix: ensure test suite passes on `win32` (#509) - * Bugfix: ensure file paths with Unicode are formatted properly (#510) - -3.7.0 - 24 May 2019 - - * Policy: Officially ending support for OTP 19 (Support OTP 20, 21, 22) - * Cleanup: Fix all dialyzer errors - * Bugfix: Minor changes to FSM/statem exits in OTP 22. - -3.6.10 - 30 April 2019 - - * Documentation: Fix pr_stacktrace invocation example (#494) - * Bugfix: Do not count suppressed messages for message drop counts (#499) - -3.6.9 - 13 March 2019 - - * Bugfix: Fix file rotation on windows (#493) - -3.6.8 - 21 December 2018 - - * Documentation: Document the error_logger_whitelist environment variable. (#489) - * Bugfix: Remove the built in handler inside of OTP 21 `logger` system. (#488) - * Bugfix: Cleanup unneeded check for is_map (#486) - * Bugfix: Cleanup ranch errors treated as cowboy errors (#485) - * Testing: Remove OTP 18 from TravisCI testing matrix - -3.6.7 - 14 October 2018 - - * Bugfix: fix tracing to work with OTP21 #480 - -3.6.6 - 24 September 2018 - - * Bugfix: When printing records, handle an improper list correctly. #478 - * Bugfix: Fix various tests and make some rotation code more explicit. #476 - * Bugfix: Make sure not to miscount messages during high-water mark check. #475 - -3.6.5 - 3 September 2018 - - * Feature: Allow the console backend to redirect output to a remote node #469 - * Feature: is_loggble - support for severity as atom #472 - * Bugfix: Prevent silent dropping of messages when hwm is exceeded #467 - * Bugfix: rotation - default log file not deleted #474 - * Bugfix: Handle strange crash report from gen_statem #473 - * Documentation: Various markup fixes: #468 #470 - -3.6.4 - 11 July 2018 - - * Bugfix: Reinstall handlers after a sink is killed #459 - * Bugfix: Fix platform_define matching not to break on OSX Mojave #461 - * Feature: Add support for installing a sys trace function #462 - -3.6.3 - 6 June 2018 - - * OTP 21 support - -3.6.2 - 26 April 2018 - - * Bugfix: flush_threshold not working (#449) - * Feature: Add `node` as a formatting option (#447) - * Documentation: Update Elixir section with information about parse_transform (#446) - * Bugfix: Correct default console configuation to use "[{level,info}]" instead (#445) - * Feature: Pretty print lists of records at top level and field values with lager:pr (#442) - * Bugfix: Ignore return value of lager:dispatch_log in lager.hrl (#441) - -3.6.1 - 1 February 2018 - - * Bugfix: Make a few corrections to the recent mailbox flushing changes (#436) - * Bugfix: add flush options to proplist validation (#439) - * Bugfix: Don't log when we dropped 0 messages (#440) - -3.6.0 - 16 January 2018 - - * Feature: Support logging with macros per level (#419) - * Feature: Support custom file rotation handler; support hourly file - rotation (#420) - * Feature: Optionally reverse pretty stacktraces (so errors are - at the top and the failed function call is at the bottom.) - (#424) - * Bugfix: Handle OTP 20 gen_server failure where client pid - is dead. (#426) - * Feature: Optionally don't flush notify messages at - high water mark. (#427) - * Bugfix: Handle another stacktrace format (#429) - * Bugfix: Fix test failure using macros on OTP 18 (#430) - * Policy: Remove all code which supports R15 (#432) - -3.5.2 - 19 October 2017 - - * Bugfix: Properly check for unicode characters in potentially deep - character list. (#417) - -3.5.1 - 15 June 2017 - - * Doc fix: Missed a curly brace in an example. (#412) - * Feature: Dynamic metadata functions (#392) - It is now possible to - dynamically add metadata to lager messages. See the "dynamic - metadata" section above for more information. - * Doc fix: Add information about the "application" placeholder. (#414) - -3.5.0 - 28 May 2017 - - * Bugfix: Support OTP 20 gen_event messages (#410) - * Feature: Enable console output to standard_error. - Convert to proplist configuration style (like file handler) - Deprecate previous configuration directives (#409) - * Bugfix: Enable the event shaper to filter messages before they're - counted; do not count application/supervisor start/stops - toward high water mark. (#411) - * Docs: Add PR guidelines; add info about the #lager chat room on freenode. - -3.4.2 - 26 April 2017 - - * Docs: Document how to make lager use UTC timestamps (#405) - * Docs: Add a note about our triage cadence. - * Docs: Update lager_syslog URL - * Docs: Document placeholders for error_logger integration (#404) - * Feature: Add hex.pm metadata and full rebar3 support. - -3.4.1 - 28 March 2017 - - * Docs: Added documentation around using lager in the context of elixir applications (#398) - * Bugfix: Properly expand paths when log_root is set. (#386) - * Policy: Removed R15 from Travis configuration - -3.4.0 - 16 March 2017 - - * Policy: Adopt official OTP support policy. (This is the **last** lager 3.x release - that will support R15.) - * Test: Fix timeouts, R15 missing functions on possibly long-running tests in Travis. (#394, #395) - * Feature: capture and log metadata from error_logger messages (#397) - * Feature: Expose new trace filters and enable filter composition (#389) - * Feature: Log crashes from gen_fsm and gen_statem correctly (#391) - * Docs: Typo in badge URL (#390) - -3.3.0 - 16 February 2017 - - * Docs: Fix documentation to make 'it' unambiguous when discussing asychronous - operation. (#387) - * Test: Fix test flappiness due to insufficient sanitation between test runs (#384, #385) - * Feature: Allow metadata only logging. (#380) - * Feature: Add an upper case severity formatter (#372) - * Feature: Add support for suppressing start/stop messages from supervisors (#368) - * Bugfix: Fix ranch crash messages (#366) - * Test: Update Travis config for 18.3 and 19.0 (#365) - -3.2.4 - 11 October 2016 - - * Test: Fix dialyzer warnings. - -3.2.3 - 29 September 2016 - - * Dependency: Update to goldrush 0.19 - -3.2.2 - 22 September 2016 - - * Bugfix: Backwards-compatibility fix for `{crash_log, undefined}` (#371) - * Fix documentation/README to reflect the preference for using `false` - as the `crash_log` setting value rather than `undefined` to indicate - that the crash log should not be written (#364) - * Bugfix: Backwards-compatibility fix for `lager_file_backend` "legacy" - configuration format (#374) - -3.2.1 - 10 June 2016 - - * Bugfix: Recent `get_env` changes resulted in launch failure (#355) - * OTP: Support typed records for Erlang 19.0 (#361) - -3.2.0 - 08 April 2016 - - * Feature: Optional sink killer to shed load when mailbox size exceeds a - configurable high water mark (#346) - * Feature: Export `configure_sink/2` so users may dynamically configure - previously setup and parse transformed sinks from their own code. (#342) - * Feature: Re-enable Travis CI and update .travis.yml (#340) - * Bugfix: Fix test race conditions for Travis CI (#344) - * Bugfix: Add the atom 'none' to the log_level() type so downstream - users won't get dialyzer failures if they use the 'none' log level. (#343) - * Bugfix: Fix typo in documentation. (#341) - * Bugfix: Fix OTP 18 test failures due to `warning_map/0` response - change. (#337) - * Bugfix: Make sure traces that use the file backend work correctly - when specified in lager configuration. (#336) - * Bugfix: Use `lager_app:get_env/3` for R15 compatibility. (#335) - * Bugfix: Make sure lager uses `id` instead of `name` when reporting - supervisor children failures. (The atom changed in OTP in 2014.) (#334) - * Bugfix: Make lager handle improper iolists (#327) - -3.1.0 - 27 January 2016 - - * Feature: API calls to a rotate handler, sink or all. This change - introduces a new `rotate` message for 3rd party lager backends; that's - why this is released as a new minor version number. (#311) - -3.0.3 - 27 January 2016 - - * Feature: Pretty printer for human readable stack traces (#298) - * Feature: Make error reformatting optional (#305) - * Feature: Optional and explicit sink for error_logger messages (#303) - * Bugfix: Always explicitly close a file after its been rotated (#316) - * Bugfix: If a relative path already contains the log root, do not add it again (#317) - * Bugfix: Configure and start extra sinks before traces are evaluated (#307) - * Bugfix: Stop and remove traces correctly (#306) - * Bugfix: A byte value of 255 is valid for Unicode (#300) - * Dependency: Bump to goldrush 0.1.8 (#313) diff --git a/eRum.sample.config b/eRum.sample.config index 1637203..9fed749 100644 --- a/eRum.sample.config +++ b/eRum.sample.config @@ -1,56 +1,56 @@ [ {eRum, [ - %% 是否开启颜色 - {colored, false}, - %% 颜色码配置 - {colors, [ - {debug, "\e[0;38m"}, - {info, "\e[1;37m"}, - {notice, "\e[1;36m"}, - {warning, "\e[1;33m"}, - {error, "\e[1;31m"}, - {critical, "\e[1;35m"}, - {alert, "\e[1;44m"}, - {emergency, "\e[1;41m"} - ]}, - - %% crash log cfg - %% 有效值 string | false - %% 为 false 的时候 没有 crash logger. - {crash_log, "log/crash.log"}, - - %% Maximum size in bytes of events in the crash log - defaults to 65536 - {crash_log_msg_size, 65536}, - - %% Maximum size of the crash log in bytes, before its rotated, set to 0 to disable rotation - default is 0 - {crash_log_size, 10485760}, - - %% What time to rotate the crash log - default is no time rotation. See the README for a description of this format. - {crash_log_date, "$D0"}, - - %% Number of rotated crash logs to keep, 0 means keep only the current one - default is 0 - {crash_log_count, 5}, - - %% Crash Log Rotator Module - default is lager_rotator_default - {crash_log_rotator, lager_rotator_default}, - - %% Whether to redirect error_logger messages into the default lager_event sink - defaults to true - {error_logger_redirect, true}, - - %% How many messages per second to allow from error_logger before we start dropping them - {error_logger_hwm, 50}, - - %% How big the gen_event mailbox can get before it is - %% switched into sync mode. This value only applies to - %% the default sink; extra sinks can supply their own. - {async_threshold, 20}, - - %% Switch back to async mode, when gen_event mailbox size - %% decrease from `async_threshold' to async_threshold - - %% async_threshold_window. This value only applies to the - %% default sink; extra sinks can supply their own. - {async_threshold_window, 5} + %% 是否开启颜色 + {colored, false}, + %% 颜色码配置 + {colors, [ + {debug, "\e[0;38m"}, + {info, "\e[1;37m"}, + {notice, "\e[1;36m"}, + {warning, "\e[1;33m"}, + {error, "\e[1;31m"}, + {critical, "\e[1;35m"}, + {alert, "\e[1;44m"}, + {emergency, "\e[1;41m"} + ]}, + + %% crash log cfg + %% 有效值 string | false + %% 为 false 的时候 没有 crash logger. + {crash_log, "log/crash.log"}, + + %% Maximum size in bytes of events in the crash log - defaults to 65536 + {crash_log_msg_size, 65536}, + + %% Maximum size of the crash log in bytes, before its rotated, set to 0 to disable rotation - default is 0 + {crash_log_size, 10485760}, + + %% What time to rotate the crash log - default is no time rotation. See the README for a description of this format. + {crash_log_date, "$D0"}, + + %% Number of rotated crash logs to keep, 0 means keep only the current one - default is 0 + {crash_log_count, 5}, + + %% Crash Log Rotator Module - default is lager_rotator_default + {crash_log_rotator, lager_rotator_default}, + + %% Whether to redirect error_logger messages into the default lager_event sink - defaults to true + {error_logger_redirect, true}, + + %% How many messages per second to allow from error_logger before we start dropping them + {error_logger_hwm, 50}, + + %% How big the gen_event mailbox can get before it is + %% switched into sync mode. This value only applies to + %% the default sink; extra sinks can supply their own. + {async_threshold, 20}, + + %% Switch back to async mode, when gen_event mailbox size + %% decrease from `async_threshold' to async_threshold - + %% async_threshold_window. This value only applies to the + %% default sink; extra sinks can supply their own. + {async_threshold_window, 5} ]} ]. diff --git a/src/eRum.erl b/src/eRum.erl index ea146c2..0e6a37a 100644 --- a/src/eRum.erl +++ b/src/eRum.erl @@ -175,20 +175,20 @@ do_log(Severity, Metadata, Format, Args, Size, SeverityAsInt, LevelThreshold, Tr do_log_impl(Severity, Metadata, Format, Args, SeverityAsInt, LevelThreshold, TraceFilters, Sink, SinkPid, FormatFun) -> {Destinations, TraceSinkPid} = case TraceFilters of - [] -> - {[], undefined}; - _ -> - {rumUtil:check_traces(Metadata, SeverityAsInt, TraceFilters, []), whereis(?TRACE_SINK)} - end, + [] -> + {[], undefined}; + _ -> + {rumUtil:check_traces(Metadata, SeverityAsInt, TraceFilters, []), whereis(?TRACE_SINK)} + end, case (LevelThreshold band SeverityAsInt) /= 0 orelse Destinations /= [] of true -> Msg = case Args of - A when is_list(A) -> - FormatFun(); - _ -> - Format - end, + A when is_list(A) -> + FormatFun(); + _ -> + Format + end, LagerMsg = rumMsg:new(Msg, Severity, Metadata, Destinations), case rumConfig:get({Sink, async}, false) of @@ -284,24 +284,24 @@ trace_file(File, Filter, Level, Options) -> %% check if this file backend is already installed Res = case rumUtil:find_file(FileName, Handlers) of - false -> - %% install the handler - LogFileConfig = - lists:keystore(level, 1, - lists:keystore(file, 1, - Options, - {file, FileName}), - {level, none}), - HandlerInfo = - lager_app:start_handler(Sink, {lager_file_backend, FileName}, - LogFileConfig), - rumConfig:global_set(handlers, [HandlerInfo | Handlers]), - {ok, installed}; - {_Watcher, _Handler, Sink} -> - {ok, exists}; - {_Watcher, _Handler, _OtherSink} -> - {error, file_in_use} - end, + false -> + %% install the handler + LogFileConfig = + lists:keystore(level, 1, + lists:keystore(file, 1, + Options, + {file, FileName}), + {level, none}), + HandlerInfo = + lager_app:start_handler(Sink, {lager_file_backend, FileName}, + LogFileConfig), + rumConfig:global_set(handlers, [HandlerInfo | Handlers]), + {ok, installed}; + {_Watcher, _Handler, Sink} -> + {ok, exists}; + {_Watcher, _Handler, _OtherSink} -> + {error, file_in_use} + end, case Res of {ok, _} -> add_trace_to_loglevel_config(Trace, Sink), diff --git a/src/formatter/rumFormatter.erl b/src/formatter/rumFormatter.erl index b0b2064..a416028 100644 --- a/src/formatter/rumFormatter.erl +++ b/src/formatter/rumFormatter.erl @@ -251,8 +251,8 @@ uppercase_severity(emergency) -> "EMERGENCY". basic_test_() -> - Date = {1, 1,1}, - Time = {1, 1,1}, + Date = {1, 1, 1}, + Time = {1, 1, 1}, Now = 11, [{"Default formatting test", ?_assertEqual(iolist_to_binary([Date, " ", Time, " [error] ", pid_to_list(self()), " Message\n"]), diff --git a/src/misc/rumErrLoggerH.erl b/src/misc/rumErrLoggerH.erl index bb74fb3..273236b 100644 --- a/src/misc/rumErrLoggerH.erl +++ b/src/misc/rumErrLoggerH.erl @@ -184,168 +184,168 @@ log_event(Event, #state{sink = Sink} = State) -> {Md, Formatted} = format_reason_md(Reason), ?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "gen_server ~w terminated with reason: ~s", [Name, Formatted]); - {false, "** State machine " ++ _} -> - %% Check if the terminated process is gen_fsm or gen_statem - %% since they generate the same exit message - {Type, Name, StateName, Reason} = - case Args of - [TName, _Msg, TStateName, _StateData, TReason] -> - {gen_fsm, TName, TStateName, TReason}; - %% Handle changed logging in gen_fsm stdlib-3.9 (TPid, ClientArgs) - [TName, _Msg, TPid, TStateName, _StateData, TReason | _ClientArgs] when is_pid(TPid), is_atom(TStateName) -> - {gen_fsm, TName, TStateName, TReason}; - %% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) - [TName, _Msg, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> - {gen_statem, TName, TStateName, {TReason, Stacktrace}}; - %% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) - [TName, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> - {gen_statem, TName, TStateName, {TReason, Stacktrace}}; - [TName, _Msg, [{TStateName, _StateData}], _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> - %% sometimes gen_statem wraps its statename/data in a list for some reason??? - {gen_statem, TName, TStateName, {TReason, Stacktrace}} - end, - {Md, Formatted} = format_reason_md(Reason), - ?CRASH_LOG(Event), - ?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "~s ~w in state ~w terminated with reason: ~s", - [Type, Name, StateName, Formatted]); - {false, "** gen_event handler" ++ _} -> - %% gen_event handler terminate - [ID, Name, _Msg, _State, Reason] = Args, + {false, "** State machine " ++ _} -> + %% Check if the terminated process is gen_fsm or gen_statem + %% since they generate the same exit message + {Type, Name, StateName, Reason} = + case Args of + [TName, _Msg, TStateName, _StateData, TReason] -> + {gen_fsm, TName, TStateName, TReason}; + %% Handle changed logging in gen_fsm stdlib-3.9 (TPid, ClientArgs) + [TName, _Msg, TPid, TStateName, _StateData, TReason | _ClientArgs] when is_pid(TPid), is_atom(TStateName) -> + {gen_fsm, TName, TStateName, TReason}; + %% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) + [TName, _Msg, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> + {gen_statem, TName, TStateName, {TReason, Stacktrace}}; + %% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) + [TName, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> + {gen_statem, TName, TStateName, {TReason, Stacktrace}}; + [TName, _Msg, [{TStateName, _StateData}], _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> + %% sometimes gen_statem wraps its statename/data in a list for some reason??? + {gen_statem, TName, TStateName, {TReason, Stacktrace}} + end, + {Md, Formatted} = format_reason_md(Reason), + ?CRASH_LOG(Event), + ?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "~s ~w in state ~w terminated with reason: ~s", + [Type, Name, StateName, Formatted]); + {false, "** gen_event handler" ++ _} -> + %% gen_event handler terminate + [ID, Name, _Msg, _State, Reason] = Args, + {Md, Formatted} = format_reason_md(Reason), + ?CRASH_LOG(Event), + ?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "gen_event ~w installed in ~w terminated with reason: ~s", + [ID, Name, Formatted]); + {false, "** Cowboy handler" ++ _} -> + %% Cowboy HTTP server error + ?CRASH_LOG(Event), + case Args of + [Module, Function, Arity, _Request, _State] -> + %% we only get the 5-element list when its a non-exported function + ?LOGFMT(Sink, error, Pid, + "Cowboy handler ~p terminated with reason: call to undefined function ~p:~p/~p", + [Module, Module, Function, Arity]); + [Module, Function, Arity, _Class, Reason | Tail] -> + %% any other cowboy error_format list *always* ends with the stacktrace + StackTrace = lists:last(Tail), + {Md, Formatted} = format_reason_md({Reason, StackTrace}), + ?LOGFMT(Sink, error, [{pid, Pid} | Md], + "Cowboy handler ~p terminated in ~p:~p/~p with reason: ~s", + [Module, Module, Function, Arity, Formatted]) + end; + {false, "Ranch listener " ++ _} -> + %% Ranch errors + ?CRASH_LOG(Event), + case Args of + %% Error logged by cowboy, which starts as ranch error + [Ref, ConnectionPid, StreamID, RequestPid, Reason, StackTrace] -> + {Md, Formatted} = format_reason_md({Reason, StackTrace}), + ?LOGFMT(Sink, error, [{pid, RequestPid} | Md], + "Cowboy stream ~p with ranch listener ~p and connection process ~p " + "had its request process exit with reason: ~s", + [StreamID, Ref, ConnectionPid, Formatted]); + [Ref, _Protocol, Worker, {[{reason, Reason}, {mfa, {Module, Function, Arity}}, {stacktrace, StackTrace} | _], _}] -> + {Md, Formatted} = format_reason_md({Reason, StackTrace}), + ?LOGFMT(Sink, error, [{pid, Worker} | Md], + "Ranch listener ~p terminated in ~p:~p/~p with reason: ~s", + [Ref, Module, Function, Arity, Formatted]); + [Ref, _Protocol, Worker, Reason] -> {Md, Formatted} = format_reason_md(Reason), - ?CRASH_LOG(Event), - ?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "gen_event ~w installed in ~w terminated with reason: ~s", - [ID, Name, Formatted]); - {false, "** Cowboy handler" ++ _} -> - %% Cowboy HTTP server error - ?CRASH_LOG(Event), - case Args of - [Module, Function, Arity, _Request, _State] -> - %% we only get the 5-element list when its a non-exported function - ?LOGFMT(Sink, error, Pid, - "Cowboy handler ~p terminated with reason: call to undefined function ~p:~p/~p", - [Module, Module, Function, Arity]); - [Module, Function, Arity, _Class, Reason | Tail] -> - %% any other cowboy error_format list *always* ends with the stacktrace - StackTrace = lists:last(Tail), - {Md, Formatted} = format_reason_md({Reason, StackTrace}), - ?LOGFMT(Sink, error, [{pid, Pid} | Md], - "Cowboy handler ~p terminated in ~p:~p/~p with reason: ~s", - [Module, Module, Function, Arity, Formatted]) - end; - {false, "Ranch listener " ++ _} -> - %% Ranch errors - ?CRASH_LOG(Event), - case Args of - %% Error logged by cowboy, which starts as ranch error - [Ref, ConnectionPid, StreamID, RequestPid, Reason, StackTrace] -> - {Md, Formatted} = format_reason_md({Reason, StackTrace}), - ?LOGFMT(Sink, error, [{pid, RequestPid} | Md], - "Cowboy stream ~p with ranch listener ~p and connection process ~p " - "had its request process exit with reason: ~s", - [StreamID, Ref, ConnectionPid, Formatted]); - [Ref, _Protocol, Worker, {[{reason, Reason}, {mfa, {Module, Function, Arity}}, {stacktrace, StackTrace} | _], _}] -> - {Md, Formatted} = format_reason_md({Reason, StackTrace}), - ?LOGFMT(Sink, error, [{pid, Worker} | Md], - "Ranch listener ~p terminated in ~p:~p/~p with reason: ~s", - [Ref, Module, Function, Arity, Formatted]); - [Ref, _Protocol, Worker, Reason] -> - {Md, Formatted} = format_reason_md(Reason), - ?LOGFMT(Sink, error, [{pid, Worker} | Md], - "Ranch listener ~p terminated with reason: ~s", - [Ref, Formatted]); - [Ref, Protocol, Ret] -> - %% ranch_conns_sup.erl module line 119-123 has three parameters error msg, log it. - {Md, Formatted} = format_reason_md(Ret), - ?LOGFMT(Sink, error, [{pid, Protocol} | Md], - "Ranch listener ~p terminated with result:~s", - [Ref, Formatted]) - end; - {false, "webmachine error" ++ _} -> - %% Webmachine HTTP server error - ?CRASH_LOG(Event), - [Path, Error] = Args, - %% webmachine likes to mangle the stack, for some reason - StackTrace = case Error of - {error, {error, Reason, Stack}} -> - {Reason, Stack}; - _ -> - Error - end, - {Md, Formatted} = format_reason_md(StackTrace), - ?LOGFMT(Sink, error, [{pid, Pid} | Md], "Webmachine error at path ~p : ~s", [Path, Formatted]); - _ -> - ?CRASH_LOG(Event), - ?LOGFMT(Sink, error, Pid, Fmt, Args) + ?LOGFMT(Sink, error, [{pid, Worker} | Md], + "Ranch listener ~p terminated with reason: ~s", + [Ref, Formatted]); + [Ref, Protocol, Ret] -> + %% ranch_conns_sup.erl module line 119-123 has three parameters error msg, log it. + {Md, Formatted} = format_reason_md(Ret), + ?LOGFMT(Sink, error, [{pid, Protocol} | Md], + "Ranch listener ~p terminated with result:~s", + [Ref, Formatted]) end; - {error_report, _GL, {Pid, std_error, D}} -> + {false, "webmachine error" ++ _} -> + %% Webmachine HTTP server error ?CRASH_LOG(Event), - ?LOGMSG(Sink, error, Pid, print_silly_list(D)); - {error_report, _GL, {Pid, supervisor_report, D}} -> + [Path, Error] = Args, + %% webmachine likes to mangle the stack, for some reason + StackTrace = case Error of + {error, {error, Reason, Stack}} -> + {Reason, Stack}; + _ -> + Error + end, + {Md, Formatted} = format_reason_md(StackTrace), + ?LOGFMT(Sink, error, [{pid, Pid} | Md], "Webmachine error at path ~p : ~s", [Path, Formatted]); + _ -> ?CRASH_LOG(Event), - case lists:sort(D) of - [{errorContext, Ctx}, {offender, Off}, {reason, Reason}, {supervisor, Name}] -> - Offender = format_offender(Off), - {Md, Formatted} = format_reason_md(Reason), - ?LOGFMT(Sink, error, [{pid, Pid} | Md], - "Supervisor ~w had child ~s exit with reason ~s in context ~w", - [supervisor_name(Name), Offender, Formatted, Ctx]); + ?LOGFMT(Sink, error, Pid, Fmt, Args) + end; + {error_report, _GL, {Pid, std_error, D}} -> + ?CRASH_LOG(Event), + ?LOGMSG(Sink, error, Pid, print_silly_list(D)); + {error_report, _GL, {Pid, supervisor_report, D}} -> + ?CRASH_LOG(Event), + case lists:sort(D) of + [{errorContext, Ctx}, {offender, Off}, {reason, Reason}, {supervisor, Name}] -> + Offender = format_offender(Off), + {Md, Formatted} = format_reason_md(Reason), + ?LOGFMT(Sink, error, [{pid, Pid} | Md], + "Supervisor ~w had child ~s exit with reason ~s in context ~w", + [supervisor_name(Name), Offender, Formatted, Ctx]); + _ -> + ?LOGMSG(Sink, error, Pid, "SUPERVISOR REPORT " ++ print_silly_list(D)) + end; + {error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} -> + ?CRASH_LOG(Event), + {Md, Formatted} = format_crash_report(Self, Neighbours), + ?LOGMSG(Sink, error, [{pid, Pid} | Md], "CRASH REPORT " ++ Formatted); + {warning_msg, _GL, {Pid, Fmt, Args}} -> + ?LOGFMT(Sink, warning, Pid, Fmt, Args); + {warning_report, _GL, {Pid, std_warning, Report}} -> + ?LOGMSG(Sink, warning, Pid, print_silly_list(Report)); + {info_msg, _GL, {Pid, Fmt, Args}} -> + ?LOGFMT(Sink, info, Pid, Fmt, Args); + {info_report, _GL, {Pid, std_info, D}} when is_list(D) -> + Details = lists:sort(D), + case Details of + [{application, App}, {exited, Reason}, {type, _Type}] -> + case application:get_env(lager, suppress_application_start_stop, false) of + true when Reason == stopped -> + no_log; _ -> - ?LOGMSG(Sink, error, Pid, "SUPERVISOR REPORT " ++ print_silly_list(D)) + {Md, Formatted} = format_reason_md(Reason), + ?LOGFMT(Sink, info, [{pid, Pid} | Md], "Application ~w exited with reason: ~s", + [App, Formatted]) end; - {error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} -> - ?CRASH_LOG(Event), - {Md, Formatted} = format_crash_report(Self, Neighbours), - ?LOGMSG(Sink, error, [{pid, Pid} | Md], "CRASH REPORT " ++ Formatted); - {warning_msg, _GL, {Pid, Fmt, Args}} -> - ?LOGFMT(Sink, warning, Pid, Fmt, Args); - {warning_report, _GL, {Pid, std_warning, Report}} -> - ?LOGMSG(Sink, warning, Pid, print_silly_list(Report)); - {info_msg, _GL, {Pid, Fmt, Args}} -> - ?LOGFMT(Sink, info, Pid, Fmt, Args); - {info_report, _GL, {Pid, std_info, D}} when is_list(D) -> - Details = lists:sort(D), - case Details of - [{application, App}, {exited, Reason}, {type, _Type}] -> - case application:get_env(lager, suppress_application_start_stop, false) of - true when Reason == stopped -> - no_log; - _ -> - {Md, Formatted} = format_reason_md(Reason), - ?LOGFMT(Sink, info, [{pid, Pid} | Md], "Application ~w exited with reason: ~s", - [App, Formatted]) - end; + _ -> + ?LOGMSG(Sink, info, Pid, print_silly_list(D)) + end; + {info_report, _GL, {Pid, std_info, D}} -> + ?LOGFMT(Sink, info, Pid, "~w", [D]); + {info_report, _GL, {P, progress, D}} -> + Details = lists:sort(D), + case Details of + [{application, App}, {started_at, Node}] -> + case application:get_env(lager, suppress_application_start_stop, false) of + true -> + no_log; _ -> - ?LOGMSG(Sink, info, Pid, print_silly_list(D)) + ?LOGFMT(Sink, info, P, "Application ~w started on node ~w", + [App, Node]) end; - {info_report, _GL, {Pid, std_info, D}} -> - ?LOGFMT(Sink, info, Pid, "~w", [D]); - {info_report, _GL, {P, progress, D}} -> - Details = lists:sort(D), - case Details of - [{application, App}, {started_at, Node}] -> - case application:get_env(lager, suppress_application_start_stop, false) of - true -> - no_log; - _ -> - ?LOGFMT(Sink, info, P, "Application ~w started on node ~w", - [App, Node]) - end; - [{started, Started}, {supervisor, Name}] -> - case application:get_env(lager, suppress_supervisor_start_stop, false) of - true -> - no_log; - _ -> - MFA = format_mfa(get_value(mfargs, Started)), - Pid = get_value(pid, Started), - ?LOGFMT(Sink, debug, P, "Supervisor ~w started ~s at pid ~w", - [supervisor_name(Name), MFA, Pid]) - end; + [{started, Started}, {supervisor, Name}] -> + case application:get_env(lager, suppress_supervisor_start_stop, false) of + true -> + no_log; _ -> - ?LOGMSG(Sink, info, P, "PROGRESS REPORT " ++ print_silly_list(D)) + MFA = format_mfa(get_value(mfargs, Started)), + Pid = get_value(pid, Started), + ?LOGFMT(Sink, debug, P, "Supervisor ~w started ~s at pid ~w", + [supervisor_name(Name), MFA, Pid]) end; _ -> - ?LOGFMT(Sink, warning, self(), "Unexpected error_logger event ~w", [Event]) - end, + ?LOGMSG(Sink, info, P, "PROGRESS REPORT " ++ print_silly_list(D)) + end; + _ -> + ?LOGFMT(Sink, warning, self(), "Unexpected error_logger event ~w", [Event]) + end, case DidLog of logged -> {ok, State}; diff --git a/src/misc/rumTruncIo.erl b/src/misc/rumTruncIo.erl index 61eaff4..58c70b6 100644 --- a/src/misc/rumTruncIo.erl +++ b/src/misc/rumTruncIo.erl @@ -167,22 +167,22 @@ print(Binary, Max, Options) when is_binary(Binary) -> {L0, Len0} end catch - throw:{unprintable, C} -> - Index = string:chr(In, C), - case Index > 1 andalso Options#print_options.depth =< Index andalso - Options#print_options.depth > -1 andalso - not Options#print_options.force_strings of - true -> - %% print first Index-1 characters followed by ... - {L0, Len0} = alist_start(string:substr(In, 1, Index - 1), Max - 1, Options), - {L0 ++ "...", Len0 + 3}; - false -> - list_body(In, Max - 4, dec_depth(Options), true) - end - end; - _ -> - list_body(B, Max - 4, dec_depth(Options), true) - end, + throw:{unprintable, C} -> + Index = string:chr(In, C), + case Index > 1 andalso Options#print_options.depth =< Index andalso + Options#print_options.depth > -1 andalso + not Options#print_options.force_strings of + true -> + %% print first Index-1 characters followed by ... + {L0, Len0} = alist_start(string:substr(In, 1, Index - 1), Max - 1, Options), + {L0 ++ "...", Len0 + 3}; + false -> + list_body(In, Max - 4, dec_depth(Options), true) + end + end; + _ -> + list_body(B, Max - 4, dec_depth(Options), true) + end, case Options#print_options.force_strings of true -> {Res, Length}; diff --git a/test/crash_statem.erl b/test/crash_statem.erl index 4db7b48..4ed8280 100644 --- a/test/crash_statem.erl +++ b/test/crash_statem.erl @@ -10,10 +10,10 @@ handle_event/4 ]). --export([terminate/3,code_change/4,init/1,callback_mode/0]). +-export([terminate/3, code_change/4, init/1, callback_mode/0]). start() -> - gen_statem:start({local,?MODULE}, ?MODULE, [], []). + gen_statem:start({local, ?MODULE}, ?MODULE, [], []). crash() -> gen_statem:call(?MODULE, boom). @@ -26,11 +26,11 @@ timeout() -> %% Mandatory callback functions terminate(_Reason, _State, _Data) -> ok. -code_change(_Vsn, State, Data, _Extra) -> {ok,State,Data}. +code_change(_Vsn, State, Data, _Extra) -> {ok, State, Data}. init([]) -> %% insert rant here about breaking changes in minor versions... case erlang:system_info(version) of - "8.0" -> {callback_mode(),state1,undefined}; + "8.0" -> {callback_mode(), state1, undefined}; _ -> {ok, state1, undefined} end. diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index af27ea3..01c20da 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -31,8 +31,8 @@ -define(TEST_SINK_EVENT, '__lager_test_sink_lager_event'). %% <-- used by lager API calls and internals for gen_event -record(state, { - level :: list(), - buffer :: list(), + level :: list(), + buffer :: list(), ignored :: term() }). -compile({parse_transform, lager_transform}). @@ -40,9 +40,9 @@ -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -record(test, { - attrs :: list(), - format :: list(), - args :: list() + attrs :: list(), + format :: list(), + args :: list() }). -export([ count/0, @@ -57,34 +57,34 @@ -endif. init(Level) -> - {ok, #state{level=lager_util:config_to_mask(Level), buffer=[], ignored=[]}}. + {ok, #state{level = lager_util:config_to_mask(Level), buffer = [], ignored = []}}. -handle_call(count, #state{buffer=Buffer} = State) -> +handle_call(count, #state{buffer = Buffer} = State) -> {ok, length(Buffer), State}; -handle_call(count_ignored, #state{ignored=Ignored} = State) -> +handle_call(count_ignored, #state{ignored = Ignored} = State) -> {ok, length(Ignored), State}; handle_call(flush, State) -> - {ok, ok, State#state{buffer=[], ignored=[]}}; -handle_call(pop, #state{buffer=Buffer} = State) -> + {ok, ok, State#state{buffer = [], ignored = []}}; +handle_call(pop, #state{buffer = Buffer} = State) -> case Buffer of [] -> {ok, undefined, State}; - [H|T] -> - {ok, H, State#state{buffer=T}} + [H | T] -> + {ok, H, State#state{buffer = T}} end; -handle_call(pop_ignored, #state{ignored=Ignored} = State) -> +handle_call(pop_ignored, #state{ignored = Ignored} = State) -> case Ignored of [] -> {ok, undefined, State}; - [H|T] -> - {ok, H, State#state{ignored=T}} + [H | T] -> + {ok, H, State#state{ignored = T}} end; -handle_call(get_buffer, #state{buffer=Buffer} = State) -> +handle_call(get_buffer, #state{buffer = Buffer} = State) -> {ok, Buffer, State}; -handle_call(get_loglevel, #state{level=Level} = State) -> +handle_call(get_loglevel, #state{level = Level} = State) -> {ok, Level, State}; handle_call({set_loglevel, Level}, State) -> - {ok, ok, State#state{level=lager_util:config_to_mask(Level)}}; + {ok, ok, State#state{level = lager_util:config_to_mask(Level)}}; handle_call(print_state, State) -> spawn(fun() -> lager:info("State ~p", [lager:pr(State, ?MODULE)]) end), timer:sleep(100), @@ -97,15 +97,15 @@ handle_call(_Request, State) -> {ok, ok, State}. handle_event({log, Msg}, - #state{level=LogLevel,buffer=Buffer,ignored=Ignored} = State) -> + #state{level = LogLevel, buffer = Buffer, ignored = Ignored} = State) -> case lager_util:is_loggable(Msg, LogLevel, ?MODULE) of true -> - {ok, State#state{buffer=Buffer ++ + {ok, State#state{buffer = Buffer ++ [{lager_msg:severity_as_int(Msg), lager_msg:datetime(Msg), lager_msg:message(Msg), lager_msg:metadata(Msg)}]}}; _ -> - {ok, State#state{ignored=Ignored ++ [Msg]}} + {ok, State#state{ignored = Ignored ++ [Msg]}} end; handle_event(_Event, State) -> {ok, State}. @@ -192,7 +192,7 @@ lager_test_() -> fun() -> lager:warning("test message"), ?assertEqual(1, count()), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual("test message", Message), ok @@ -202,7 +202,7 @@ lager_test_() -> fun() -> ?lager_warning("test message", []), ?assertEqual(1, count()), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual("test message", Message), ok @@ -212,7 +212,7 @@ lager_test_() -> fun() -> lager:warning_unsafe("test message"), ?assertEqual(1, count()), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual("test message", Message), ok @@ -222,7 +222,7 @@ lager_test_() -> fun() -> lager:warning("test message ~p", [self()]), ?assertEqual(1, count()), - {Level, _Time, Message,_Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual(lists:flatten(io_lib:format("test message ~p", [self()])), lists:flatten(Message)), ok @@ -232,7 +232,7 @@ lager_test_() -> fun() -> ?lager_warning("test message ~p", [self()]), ?assertEqual(1, count()), - {Level, _Time, Message,_Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual(lists:flatten(io_lib:format("test message ~p", [self()])), lists:flatten(Message)), ok @@ -242,7 +242,7 @@ lager_test_() -> fun() -> lager:warning_unsafe("test message ~p", [self()]), ?assertEqual(1, count()), - {Level, _Time, Message,_Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual(lists:flatten(io_lib:format("test message ~p", [self()])), lists:flatten(Message)), ok @@ -269,7 +269,7 @@ lager_test_() -> {"logging works from a begin/end block inside a list comprehension", fun() -> ?assertEqual(0, count()), - [ begin lager:warning("test message") end || _N <- lists:seq(1, 10)], + [begin lager:warning("test message") end || _N <- lists:seq(1, 10)], ?assertEqual(10, count()), ok end @@ -277,7 +277,7 @@ lager_test_() -> {"logging works from a nested list comprehension", fun() -> ?assertEqual(0, count()), - [ [lager:warning("test message") || _N <- lists:seq(1, 10)] || + [[lager:warning("test message") || _N <- lists:seq(1, 10)] || _I <- lists:seq(1, 10)], ?assertEqual(100, count()), ok @@ -305,19 +305,19 @@ lager_test_() -> lager:info(Attr, "hello ~p", Args), lager:info([{d, delta}, {g, gamma}], Fmt, Args), ?assertEqual(6, count()), - {Level, _Time, Message, Metadata} = pop(), - ?assertMatch([{a, alpha}, {b, beta}|_], Metadata), + {Level, _Time, Message, Metadata} = pop(), + ?assertMatch([{a, alpha}, {b, beta} | _], Metadata), ?assertEqual("hello", lists:flatten(Message)), - {Level, _Time2, Message2, _Metadata2} = pop(), + {Level, _Time2, Message2, _Metadata2} = pop(), ?assertEqual("hello world", lists:flatten(Message2)), - {Level, _Time3, Message3, _Metadata3} = pop(), + {Level, _Time3, Message3, _Metadata3} = pop(), ?assertEqual("format world", lists:flatten(Message3)), - {Level, _Time4, Message4, _Metadata4} = pop(), + {Level, _Time4, Message4, _Metadata4} = pop(), ?assertEqual("hello world", lists:flatten(Message4)), - {Level, _Time5, Message5, _Metadata5} = pop(), + {Level, _Time5, Message5, _Metadata5} = pop(), ?assertEqual("hello world", lists:flatten(Message5)), - {Level, _Time6, Message6, Metadata6} = pop(), - ?assertMatch([{d, delta}, {g, gamma}|_], Metadata6), + {Level, _Time6, Message6, Metadata6} = pop(), + ?assertMatch([{d, delta}, {g, gamma} | _], Metadata6), ?assertEqual("format world", lists:flatten(Message6)), ok end @@ -335,19 +335,19 @@ lager_test_() -> lager:info([{K, atom_to_list(V)} || {K, V} <- Attr], "hello ~p", [{atom, X} || X <- Args]), lager:info([{d, delta}, {g, gamma}], Fmt, [{atom, X} || X <- Args]), ?assertEqual(6, count()), - {Level, _Time, Message, Metadata} = pop(), - ?assertMatch([{a, "alpha"}, {b, "beta"}|_], Metadata), + {Level, _Time, Message, Metadata} = pop(), + ?assertMatch([{a, "alpha"}, {b, "beta"} | _], Metadata), ?assertEqual("hello", lists:flatten(Message)), - {Level, _Time2, Message2, _Metadata2} = pop(), + {Level, _Time2, Message2, _Metadata2} = pop(), ?assertEqual("hello {atom,world}", lists:flatten(Message2)), - {Level, _Time3, Message3, _Metadata3} = pop(), + {Level, _Time3, Message3, _Metadata3} = pop(), ?assertEqual("format world", lists:flatten(Message3)), - {Level, _Time4, Message4, _Metadata4} = pop(), + {Level, _Time4, Message4, _Metadata4} = pop(), ?assertEqual("hello {atom,world}", lists:flatten(Message4)), - {Level, _Time5, Message5, _Metadata5} = pop(), + {Level, _Time5, Message5, _Metadata5} = pop(), ?assertEqual("hello {atom,world}", lists:flatten(Message5)), - {Level, _Time6, Message6, Metadata6} = pop(), - ?assertMatch([{d, delta}, {g, gamma}|_], Metadata6), + {Level, _Time6, Message6, Metadata6} = pop(), + ?assertMatch([{d, delta}, {g, gamma} | _], Metadata6), ?assertEqual("format {atom,world}", lists:flatten(Message6)), ok end @@ -365,19 +365,19 @@ lager_test_() -> lager:info(fun() -> get(attrs) end(), "hello ~p", get(args)), lager:info([{d, delta}, {g, gamma}], get(format), get(args)), ?assertEqual(6, count()), - {Level, _Time, Message, Metadata} = pop(), - ?assertMatch([{a, alpha}, {b, beta}|_], Metadata), + {Level, _Time, Message, Metadata} = pop(), + ?assertMatch([{a, alpha}, {b, beta} | _], Metadata), ?assertEqual("hello", lists:flatten(Message)), - {Level, _Time2, Message2, _Metadata2} = pop(), + {Level, _Time2, Message2, _Metadata2} = pop(), ?assertEqual("hello world", lists:flatten(Message2)), - {Level, _Time3, Message3, _Metadata3} = pop(), + {Level, _Time3, Message3, _Metadata3} = pop(), ?assertEqual("format world", lists:flatten(Message3)), - {Level, _Time4, Message4, _Metadata4} = pop(), + {Level, _Time4, Message4, _Metadata4} = pop(), ?assertEqual("hello world", lists:flatten(Message4)), - {Level, _Time5, Message5, _Metadata5} = pop(), + {Level, _Time5, Message5, _Metadata5} = pop(), ?assertEqual("hello world", lists:flatten(Message5)), - {Level, _Time6, Message6, Metadata6} = pop(), - ?assertMatch([{d, delta}, {g, gamma}|_], Metadata6), + {Level, _Time6, Message6, Metadata6} = pop(), + ?assertMatch([{d, delta}, {g, gamma} | _], Metadata6), ?assertEqual("format world", lists:flatten(Message6)), ok end @@ -385,7 +385,7 @@ lager_test_() -> {"record fields inplace of literals in logging statements work", fun() -> ?assertEqual(0, count()), - Test = #test{attrs=[{a, alpha}, {b, beta}], format="format ~p", args=[world]}, + Test = #test{attrs = [{a, alpha}, {b, beta}], format = "format ~p", args = [world]}, lager:info(Test#test.attrs, "hello"), lager:info(Test#test.attrs, "hello ~p", Test#test.args), lager:info(Test#test.format, [world]), @@ -393,19 +393,19 @@ lager_test_() -> lager:info(Test#test.attrs, "hello ~p", Test#test.args), lager:info([{d, delta}, {g, gamma}], Test#test.format, Test#test.args), ?assertEqual(6, count()), - {Level, _Time, Message, Metadata} = pop(), - ?assertMatch([{a, alpha}, {b, beta}|_], Metadata), + {Level, _Time, Message, Metadata} = pop(), + ?assertMatch([{a, alpha}, {b, beta} | _], Metadata), ?assertEqual("hello", lists:flatten(Message)), - {Level, _Time2, Message2, _Metadata2} = pop(), + {Level, _Time2, Message2, _Metadata2} = pop(), ?assertEqual("hello world", lists:flatten(Message2)), - {Level, _Time3, Message3, _Metadata3} = pop(), + {Level, _Time3, Message3, _Metadata3} = pop(), ?assertEqual("format world", lists:flatten(Message3)), - {Level, _Time4, Message4, _Metadata4} = pop(), + {Level, _Time4, Message4, _Metadata4} = pop(), ?assertEqual("hello world", lists:flatten(Message4)), - {Level, _Time5, Message5, _Metadata5} = pop(), + {Level, _Time5, Message5, _Metadata5} = pop(), ?assertEqual("hello world", lists:flatten(Message5)), - {Level, _Time6, Message6, Metadata6} = pop(), - ?assertMatch([{d, delta}, {g, gamma}|_], Metadata6), + {Level, _Time6, Message6, Metadata6} = pop(), + ?assertMatch([{d, delta}, {g, gamma} | _], Metadata6), ?assertEqual("format world", lists:flatten(Message6)), ok end @@ -561,8 +561,8 @@ lager_test_() -> lager:clear_all_traces(), lager:trace_console([{beta, '>', 2}, {meta, "data"}]), lager:trace_console([{beta, '>', 2}, {beta, '<', 2.12}]), - Reduced = {all,[{any,[{beta,'<',2.12},{meta,'=',"data"}]}, - {beta,'>',2}]}, + Reduced = {all, [{any, [{beta, '<', 2.12}, {meta, '=', "data"}]}, + {beta, '>', 2}]}, ?assertEqual(Reduced, ?DEFAULT_TRACER:info('query')), lager:clear_all_traces(), @@ -610,22 +610,22 @@ lager_test_() -> {_, T0} = lager_config:get({Sink, loglevel}), StartGlobal = lager_config:global_get(handlers), ?assertEqual([], T0), - {ok, TestTrace1} = lager:trace_file("/tmp/test", [{a,b}]), + {ok, TestTrace1} = lager:trace_file("/tmp/test", [{a, b}]), MidHandlers = gen_event:which_handlers(Sink), - {ok, TestTrace2} = lager:trace_file("/tmp/test", [{c,d}]), + {ok, TestTrace2} = lager:trace_file("/tmp/test", [{c, d}]), MidHandlers = gen_event:which_handlers(Sink), - ?assertEqual(length(StartHandlers)+1, length(MidHandlers)), + ?assertEqual(length(StartHandlers) + 1, length(MidHandlers)), MidGlobal = lager_config:global_get(handlers), - ?assertEqual(length(StartGlobal)+1, length(MidGlobal)), + ?assertEqual(length(StartGlobal) + 1, length(MidGlobal)), {_, T1} = lager_config:get({Sink, loglevel}), ?assertEqual(2, length(T1)), ok = lager:stop_trace(TestTrace1), {_, T2} = lager_config:get({Sink, loglevel}), ?assertEqual(1, length(T2)), - ?assertEqual(length(StartHandlers)+1, length( + ?assertEqual(length(StartHandlers) + 1, length( gen_event:which_handlers(Sink))), - ?assertEqual(length(StartGlobal)+1, length(lager_config:global_get(handlers))), + ?assertEqual(length(StartGlobal) + 1, length(lager_config:global_get(handlers))), ok = lager:stop_trace(TestTrace2), EndHandlers = gen_event:which_handlers(Sink), EndGlobal = lager_config:global_get(handlers), @@ -639,17 +639,17 @@ lager_test_() -> {"record printing works", fun() -> print_state(), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(info)), {mask, Mask} = lager_util:config_to_mask(info), - ?assertEqual("State #state{level={mask,"++integer_to_list(Mask)++"},buffer=[],ignored=[]}", lists:flatten(Message)), + ?assertEqual("State #state{level={mask," ++ integer_to_list(Mask) ++ "},buffer=[],ignored=[]}", lists:flatten(Message)), ok end }, {"record printing fails gracefully", fun() -> print_bad_state(), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(info)), ?assertEqual("State {state,1}", lists:flatten(Message)), ok @@ -659,7 +659,7 @@ lager_test_() -> fun() -> spawn(fun() -> lager:info("State ~p", [lager:pr({state, 1}, lager)]) end), timer:sleep(100), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(info)), ?assertEqual("State {state,1}", lists:flatten(Message)), ok @@ -669,7 +669,7 @@ lager_test_() -> fun() -> spawn(fun() -> lager:info("State ~p", [lager:pr(ok, lager)]) end), timer:sleep(100), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(info)), ?assertEqual("State ok", lists:flatten(Message)), ok @@ -679,7 +679,7 @@ lager_test_() -> fun() -> spawn(fun() -> lager:info("State ~p", [lager:pr({state, 1}, not_a_module)]) end), timer:sleep(1000), - {Level, _Time, Message, _Metadata} = pop(), + {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(info)), ?assertEqual("State {state,1}", lists:flatten(Message)), ok @@ -697,14 +697,14 @@ lager_test_() -> fun() -> lager:md([{platypus, gravid}, {sloth, hirsute}, {duck, erroneous}]), lager:info("I sing the animal kingdom electric!"), - {_Level, _Time, _Message, Metadata} = pop(), + {_Level, _Time, _Message, Metadata} = pop(), ?assertEqual(gravid, proplists:get_value(platypus, Metadata)), ?assertEqual(hirsute, proplists:get_value(sloth, Metadata)), ?assertEqual(erroneous, proplists:get_value(duck, Metadata)), ?assertEqual(undefined, proplists:get_value(eagle, Metadata)), lager:md([{platypus, gravid}, {sloth, hirsute}, {eagle, superincumbent}]), lager:info("I sing the animal kingdom dielectric!"), - {_Level2, _Time2, _Message2, Metadata2} = pop(), + {_Level2, _Time2, _Message2, Metadata2} = pop(), ?assertEqual(gravid, proplists:get_value(platypus, Metadata2)), ?assertEqual(hirsute, proplists:get_value(sloth, Metadata2)), ?assertEqual(undefined, proplists:get_value(duck, Metadata2)), @@ -715,7 +715,7 @@ lager_test_() -> {"unsafe messages really are not truncated", fun() -> lager:info_unsafe("doom, doom has come upon you all ~p", [string:copies("doom", 1500)]), - {_, _, Msg,_Metadata} = pop(), + {_, _, Msg, _Metadata} = pop(), ?assert(length(lists:flatten(Msg)) == 6035) end }, @@ -731,7 +731,7 @@ lager_test_() -> fun() -> lager:warning("so long, and thanks for all the fish"), ?assertEqual(1, count()), - {_Level, {_Date, Time}, _Message, _Metadata} = pop(), + {_Level, {_Date, Time}, _Message, _Metadata} = pop(), ?assertEqual(nomatch, binary:match(iolist_to_binary(Time), <<"UTC">>)), ok end @@ -742,7 +742,7 @@ lager_test_() -> lager:warning("so long, and thanks for all the fish"), application:set_env(sasl, utc_log, false), ?assertEqual(1, count()), - {_Level, {_Date, Time}, _Message, _Metadata} = pop(), + {_Level, {_Date, Time}, _Message, _Metadata} = pop(), ?assertNotEqual(nomatch, binary:match(iolist_to_binary(Time), <<"UTC">>)), ok end @@ -765,7 +765,7 @@ extra_sinks_test_() -> fun() -> ?TEST_SINK_NAME:warning("test message"), ?assertEqual(1, count(?TEST_SINK_EVENT)), - {Level, _Time, Message, _Metadata} = pop(?TEST_SINK_EVENT), + {Level, _Time, Message, _Metadata} = pop(?TEST_SINK_EVENT), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual("test message", Message), ok @@ -775,7 +775,7 @@ extra_sinks_test_() -> fun() -> ?TEST_SINK_NAME:warning("test message ~p", [self()]), ?assertEqual(1, count(?TEST_SINK_EVENT)), - {Level, _Time, Message,_Metadata} = pop(?TEST_SINK_EVENT), + {Level, _Time, Message, _Metadata} = pop(?TEST_SINK_EVENT), ?assertMatch(Level, lager_util:level_to_num(warning)), ?assertEqual(lists:flatten(io_lib:format("test message ~p", [self()])), lists:flatten(Message)), ok @@ -794,19 +794,19 @@ extra_sinks_test_() -> ?TEST_SINK_NAME:info(Attr, "hello ~p", Args), ?TEST_SINK_NAME:info([{d, delta}, {g, gamma}], Fmt, Args), ?assertEqual(6, count(?TEST_SINK_EVENT)), - {Level, _Time, Message, Metadata} = pop(?TEST_SINK_EVENT), - ?assertMatch([{a, alpha}, {b, beta}|_], Metadata), + {Level, _Time, Message, Metadata} = pop(?TEST_SINK_EVENT), + ?assertMatch([{a, alpha}, {b, beta} | _], Metadata), ?assertEqual("hello", lists:flatten(Message)), - {Level, _Time2, Message2, _Metadata2} = pop(?TEST_SINK_EVENT), + {Level, _Time2, Message2, _Metadata2} = pop(?TEST_SINK_EVENT), ?assertEqual("hello world", lists:flatten(Message2)), - {Level, _Time3, Message3, _Metadata3} = pop(?TEST_SINK_EVENT), + {Level, _Time3, Message3, _Metadata3} = pop(?TEST_SINK_EVENT), ?assertEqual("format world", lists:flatten(Message3)), - {Level, _Time4, Message4, _Metadata4} = pop(?TEST_SINK_EVENT), + {Level, _Time4, Message4, _Metadata4} = pop(?TEST_SINK_EVENT), ?assertEqual("hello world", lists:flatten(Message4)), - {Level, _Time5, Message5, _Metadata5} = pop(?TEST_SINK_EVENT), + {Level, _Time5, Message5, _Metadata5} = pop(?TEST_SINK_EVENT), ?assertEqual("hello world", lists:flatten(Message5)), - {Level, _Time6, Message6, Metadata6} = pop(?TEST_SINK_EVENT), - ?assertMatch([{d, delta}, {g, gamma}|_], Metadata6), + {Level, _Time6, Message6, Metadata6} = pop(?TEST_SINK_EVENT), + ?assertMatch([{d, delta}, {g, gamma} | _], Metadata6), ?assertEqual("format world", lists:flatten(Message6)), ok end @@ -818,22 +818,22 @@ extra_sinks_test_() -> {_, T0} = lager_config:get({Sink, loglevel}), StartGlobal = lager_config:global_get(handlers), ?assertEqual([], T0), - {ok, TestTrace1} = lager:trace_file("/tmp/test", [{sink, Sink}, {a,b}]), + {ok, TestTrace1} = lager:trace_file("/tmp/test", [{sink, Sink}, {a, b}]), MidHandlers = gen_event:which_handlers(Sink), - {ok, TestTrace2} = lager:trace_file("/tmp/test", [{sink, Sink}, {c,d}]), + {ok, TestTrace2} = lager:trace_file("/tmp/test", [{sink, Sink}, {c, d}]), MidHandlers = gen_event:which_handlers(Sink), - ?assertEqual(length(StartHandlers)+1, length(MidHandlers)), + ?assertEqual(length(StartHandlers) + 1, length(MidHandlers)), MidGlobal = lager_config:global_get(handlers), - ?assertEqual(length(StartGlobal)+1, length(MidGlobal)), + ?assertEqual(length(StartGlobal) + 1, length(MidGlobal)), {_, T1} = lager_config:get({Sink, loglevel}), ?assertEqual(2, length(T1)), ok = lager:stop_trace(TestTrace1), {_, T2} = lager_config:get({Sink, loglevel}), ?assertEqual(1, length(T2)), - ?assertEqual(length(StartHandlers)+1, length( + ?assertEqual(length(StartHandlers) + 1, length( gen_event:which_handlers(Sink))), - ?assertEqual(length(StartGlobal)+1, length(lager_config:global_get(handlers))), + ?assertEqual(length(StartGlobal) + 1, length(lager_config:global_get(handlers))), ok = lager:stop_trace(TestTrace2), EndHandlers = gen_event:which_handlers(Sink), EndGlobal = lager_config:global_get(handlers), @@ -1077,7 +1077,7 @@ crash_fsm_test_() -> Tests}} ]}. --if(?OTP_RELEASE < 23). +- if (?OTP_RELEASE < 23). test_body_gen_fsm_crash(TestBody) -> [TestBody("gen_fsm crash", crash_fsm, crash, [], "gen_fsm crash_fsm in state state1 terminated with reason: call to undefined function crash_fsm:state1/3 from gen_fsm:handle_msg/")]. -else. @@ -1086,20 +1086,20 @@ test_body_gen_fsm_crash(_TestBody) -> -endif. error_logger_redirect_crash_test_() -> - TestBody=fun(Name,CrashReason,Expected) -> + TestBody = fun(Name, CrashReason, Expected) -> fun(Sink) -> {Name, fun() -> Pid = whereis(crash), crash(CrashReason), - {Level, _, Msg,Metadata} = pop(Sink), + {Level, _, Msg, Metadata} = pop(Sink), test_body(Expected, lists:flatten(Msg)), - ?assertEqual(Pid,proplists:get_value(pid,Metadata)), - ?assertEqual(lager_util:level_to_num(error),Level) + ?assertEqual(Pid, proplists:get_value(pid, Metadata)), + ?assertEqual(lager_util:level_to_num(error), Level) end } end - end, + end, Tests = [ fun(Sink) -> {"again, there is nothing up my sleeve", @@ -1110,24 +1110,24 @@ error_logger_redirect_crash_test_() -> } end, - TestBody("bad return value",bad_return,"gen_server crash terminated with reason: bad return value: bleh"), - TestBody("bad return value with string",bad_return_string,"gen_server crash terminated with reason: bad return value: {tuple,{tuple,\"string\"}}"), - TestBody("bad return uncaught throw",throw,"gen_server crash terminated with reason: bad return value: a_ball"), - TestBody("case clause",case_clause,"gen_server crash terminated with reason: no case clause matching {} in crash:handle_call/3"), - TestBody("case clause string",case_clause_string,"gen_server crash terminated with reason: no case clause matching \"crash\" in crash:handle_call/3"), - TestBody("function clause",function_clause,"gen_server crash terminated with reason: no function clause matching crash:function({})"), - TestBody("if clause",if_clause,"gen_server crash terminated with reason: no true branch found while evaluating if expression in crash:handle_call/3"), - TestBody("try clause",try_clause,"gen_server crash terminated with reason: no try clause matching [] in crash:handle_call/3"), - TestBody("undefined function",undef,"gen_server crash terminated with reason: call to undefined function crash:booger/0 from crash:handle_call/3"), - TestBody("bad math",badarith,"gen_server crash terminated with reason: bad arithmetic expression in crash:handle_call/3"), - TestBody("bad match",badmatch,"gen_server crash terminated with reason: no match of right hand value {} in crash:handle_call/3"), - TestBody("bad arity",badarity,"gen_server crash terminated with reason: fun called with wrong arity of 1 instead of 3 in crash:handle_call/3"), - TestBody("bad arg1",badarg1,"gen_server crash terminated with reason: bad argument in crash:handle_call/3"), - TestBody("bad arg2",badarg2,"gen_server crash terminated with reason: bad argument in call to erlang:iolist_to_binary([\"foo\",bar]) in crash:handle_call/3"), - TestBody("bad record",badrecord,"gen_server crash terminated with reason: bad record state in crash:handle_call/3"), - TestBody("noproc",noproc,"gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz)"), - TestBody("noproc_proc_lib",noproc_proc_lib,"gen_server crash terminated with reason: no such process or port in call to proc_lib:stop/3"), - TestBody("badfun",badfun,"gen_server crash terminated with reason: bad function booger in crash:handle_call/3") + TestBody("bad return value", bad_return, "gen_server crash terminated with reason: bad return value: bleh"), + TestBody("bad return value with string", bad_return_string, "gen_server crash terminated with reason: bad return value: {tuple,{tuple,\"string\"}}"), + TestBody("bad return uncaught throw", throw, "gen_server crash terminated with reason: bad return value: a_ball"), + TestBody("case clause", case_clause, "gen_server crash terminated with reason: no case clause matching {} in crash:handle_call/3"), + TestBody("case clause string", case_clause_string, "gen_server crash terminated with reason: no case clause matching \"crash\" in crash:handle_call/3"), + TestBody("function clause", function_clause, "gen_server crash terminated with reason: no function clause matching crash:function({})"), + TestBody("if clause", if_clause, "gen_server crash terminated with reason: no true branch found while evaluating if expression in crash:handle_call/3"), + TestBody("try clause", try_clause, "gen_server crash terminated with reason: no try clause matching [] in crash:handle_call/3"), + TestBody("undefined function", undef, "gen_server crash terminated with reason: call to undefined function crash:booger/0 from crash:handle_call/3"), + TestBody("bad math", badarith, "gen_server crash terminated with reason: bad arithmetic expression in crash:handle_call/3"), + TestBody("bad match", badmatch, "gen_server crash terminated with reason: no match of right hand value {} in crash:handle_call/3"), + TestBody("bad arity", badarity, "gen_server crash terminated with reason: fun called with wrong arity of 1 instead of 3 in crash:handle_call/3"), + TestBody("bad arg1", badarg1, "gen_server crash terminated with reason: bad argument in crash:handle_call/3"), + TestBody("bad arg2", badarg2, "gen_server crash terminated with reason: bad argument in call to erlang:iolist_to_binary([\"foo\",bar]) in crash:handle_call/3"), + TestBody("bad record", badrecord, "gen_server crash terminated with reason: bad record state in crash:handle_call/3"), + TestBody("noproc", noproc, "gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz)"), + TestBody("noproc_proc_lib", noproc_proc_lib, "gen_server crash terminated with reason: no such process or port in call to proc_lib:stop/3"), + TestBody("badfun", badfun, "gen_server crash terminated with reason: bad function booger in crash:handle_call/3") ], {"Error logger redirect crash", [ {"Redirect to default sink", @@ -1184,9 +1184,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report([{this, is}, a, {silly, format}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = "this: is, a, silly: format", ?assertEqual(Expected, lists:flatten(Msg)) @@ -1196,9 +1196,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report("this is less silly"), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = "this is less silly", ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1207,9 +1207,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_msg("doom, doom has come upon you all"), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = "doom, doom has come upon you all", ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1218,9 +1218,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_msg("~ts", ["Привет!"]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Привет!", lists:flatten(Msg)) end }, @@ -1228,7 +1228,7 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]), _ = gen_event:which_handlers(error_logger), - {_, _, Msg,_Metadata} = pop(Sink), + {_, _, Msg, _Metadata} = pop(Sink), ?assert(length(lists:flatten(Msg)) < 5100) end }, @@ -1237,9 +1237,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report([{this, is}, a, {silly, format}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = "this: is, a, silly: format", ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1248,9 +1248,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report([[{this, is}, a, {silly, format}] || _ <- lists:seq(0, 600)]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assert(length(lists:flatten(Msg)) < 5000) end }, @@ -1258,9 +1258,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report({foolish, bees}), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("{foolish,bees}", lists:flatten(Msg)) end }, @@ -1268,9 +1268,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report({foolish, bees}), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("{foolish,bees}", lists:flatten(Msg)) end }, @@ -1278,9 +1278,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report("this is less silly"), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("this is less silly", lists:flatten(Msg)) end }, @@ -1288,9 +1288,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report(string:copies("this is less silly", 1000)), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assert(length(lists:flatten(Msg)) < 5100) end }, @@ -1298,9 +1298,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report(["this is less silly", {than, "this"}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("\"this is less silly\", than: \"this\"", lists:flatten(Msg)) end }, @@ -1308,9 +1308,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_msg("doom, doom has come upon you all"), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("doom, doom has come upon you all", lists:flatten(Msg)) end }, @@ -1318,9 +1318,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assert(length(lists:flatten(Msg)) < 5100) end }, @@ -1328,9 +1328,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_msg("~ts", ["Привет!"]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Привет!", lists:flatten(Msg)) end }, @@ -1357,9 +1357,9 @@ error_logger_redirect_test_() -> put(warning_map, Lvl), sync_error_logger:warning_msg("~ts", ["Привет!"]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Lvl),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(Lvl), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Привет!", lists:flatten(Msg)) end }, @@ -1369,9 +1369,9 @@ error_logger_redirect_test_() -> put(warning_map, Lvl), sync_error_logger:warning_msg("doom, doom has come upon you all"), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Lvl),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(Lvl), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("doom, doom has come upon you all", lists:flatten(Msg)) end }, @@ -1381,9 +1381,9 @@ error_logger_redirect_test_() -> put(warning_map, Lvl), sync_error_logger:warning_report([{i, like}, pie]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Lvl),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(Lvl), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("i: like, pie", lists:flatten(Msg)) end }, @@ -1393,9 +1393,9 @@ error_logger_redirect_test_() -> put(warning_map, Lvl), sync_error_logger:warning_report({foolish, bees}), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Lvl),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(Lvl), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("{foolish,bees}", lists:flatten(Msg)) end }, @@ -1403,9 +1403,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report([{application, foo}, {exited, quittin_time}, {type, lazy}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Application foo exited with reason: quittin_time", lists:flatten(Msg)) end }, @@ -1413,30 +1413,30 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{name, mini_steve}, {mfargs, {a, b, [c]}}, {pid, bleh}]}, {reason, fired}, {supervisor, {local, steve}}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Supervisor steve had child mini_steve started with a:b(c) at bleh exit with reason fired in context france", lists:flatten(Msg)) end }, {"supervisor reports with real error", fun(Sink) -> - sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{name, mini_steve}, {mfargs, {a, b, [c]}}, {pid, bleh}]}, {reason, {function_clause,[{crash,handle_info,[foo]}]}}, {supervisor, {local, steve}}]), + sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{name, mini_steve}, {mfargs, {a, b, [c]}}, {pid, bleh}]}, {reason, {function_clause, [{crash, handle_info, [foo]}]}}, {supervisor, {local, steve}}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Supervisor steve had child mini_steve started with a:b(c) at bleh exit with reason no function clause matching crash:handle_info(foo) in context france", lists:flatten(Msg)) end }, {"supervisor reports with real error and pid", fun(Sink) -> - sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{name, mini_steve}, {mfargs, {a, b, [c]}}, {pid, bleh}]}, {reason, {function_clause,[{crash,handle_info,[foo]}]}}, {supervisor, somepid}]), + sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{name, mini_steve}, {mfargs, {a, b, [c]}}, {pid, bleh}]}, {reason, {function_clause, [{crash, handle_info, [foo]}]}}, {supervisor, somepid}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Supervisor somepid had child mini_steve started with a:b(c) at bleh exit with reason no function clause matching crash:handle_info(foo) in context france", lists:flatten(Msg)) end }, @@ -1445,9 +1445,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{mod, mini_steve}, {pid, bleh}]}, {reason, fired}, {supervisor, {local, steve}}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Supervisor steve had child at module mini_steve at bleh exit with reason fired in context france", lists:flatten(Msg)) end }, @@ -1455,9 +1455,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:info_report(progress, [{application, foo}, {started_at, node()}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(info),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(info), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("Application foo started on node ~w", [node()])), ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1468,9 +1468,9 @@ error_logger_redirect_test_() -> ?assertEqual({?DEBUG bor ?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get({Sink, loglevel})), sync_error_logger:info_report(progress, [{supervisor, {local, foo}}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(debug),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(debug), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Supervisor foo started foo:bar/1 at pid baz", lists:flatten(Msg)) end }, @@ -1480,9 +1480,9 @@ error_logger_redirect_test_() -> ?assertEqual({?DEBUG bor ?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get({Sink, loglevel})), sync_error_logger:info_report(progress, [{supervisor, somepid}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(debug),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(debug), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Supervisor somepid started foo:bar/1 at pid baz", lists:flatten(Msg)) end }, @@ -1490,9 +1490,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, emfile, [{stack, trace, 1}]}}], []]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("CRASH REPORT Process ~w with 0 neighbours crashed with reason: maximum number of file descriptors exhausted, check ulimit -n", [self()])), ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1501,9 +1501,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, system_limit, [{erlang, spawn, 1}]}}], []]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of processes exceeded", [self()])), ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1512,9 +1512,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, system_limit, [{erlang, spawn_opt, 1}]}}], []]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of processes exceeded", [self()])), ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1523,9 +1523,9 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, system_limit, [{erlang, open_port, 1}]}}], []]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of ports exceeded", [self()])), ?assertEqual(Expected, lists:flatten(Msg)) end @@ -1534,29 +1534,29 @@ error_logger_redirect_test_() -> fun(Sink) -> sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, system_limit, [{erlang, list_to_atom, 1}]}}], []]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: tried to create an atom larger than 255, or maximum atom count exceeded", [self()])), ?assertEqual(Expected, lists:flatten(Msg)) end }, {"crash report for system ets table limit", fun(Sink) -> - sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, test}, {error_info, {error, system_limit, [{ets,new,[segment_offsets,[ordered_set,public]]},{mi_segment,open_write,1},{mi_buffer_converter,handle_cast,2},{gen_server,handle_msg,5},{proc_lib,init_p_do_apply,3}]}}], []]), + sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, test}, {error_info, {error, system_limit, [{ets, new, [segment_offsets, [ordered_set, public]]}, {mi_segment, open_write, 1}, {mi_buffer_converter, handle_cast, 2}, {gen_server, handle_msg, 5}, {proc_lib, init_p_do_apply, 3}]}}], []]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), Expected = lists:flatten(io_lib:format("CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of ETS tables exceeded", [test])), ?assertEqual(Expected, lists:flatten(Msg)) end }, {"crash report for unknown system limit should be truncated at 500 characters", fun(Sink) -> - sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, system_limit, [{wtf,boom,[string:copies("aaaa", 4096)]}]}}], []]), + sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, system_limit, [{wtf, boom, [string:copies("aaaa", 4096)]}]}}], []]), _ = gen_event:which_handlers(error_logger), - {_, _, Msg,_Metadata} = pop(Sink), + {_, _, Msg, _Metadata} = pop(Sink), ?assert(length(lists:flatten(Msg)) > 550), ?assert(length(lists:flatten(Msg)) < 600) end @@ -1616,22 +1616,22 @@ error_logger_redirect_test_() -> {"webmachine error reports", fun(Sink) -> Path = "/cgi-bin/phpmyadmin", - Reason = {error,{error,{badmatch,{error,timeout}}, - [{myapp,dostuff,2,[{file,"src/myapp.erl"},{line,123}]}, - {webmachine_resource,resource_call,3,[{file,"src/webmachine_resource.erl"},{line,169}]}]}}, + Reason = {error, {error, {badmatch, {error, timeout}}, + [{myapp, dostuff, 2, [{file, "src/myapp.erl"}, {line, 123}]}, + {webmachine_resource, resource_call, 3, [{file, "src/webmachine_resource.erl"}, {line, 169}]}]}}, sync_error_logger:error_msg("webmachine error: path=~p~n~p~n", [Path, Reason]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Webmachine error at path \"/cgi-bin/phpmyadmin\" : no match of right hand value {error,timeout} in myapp:dostuff/2 line 123", lists:flatten(Msg)) end }, {"Cowboy error reports, 8 arg version", fun(Sink) -> - Stack = [{my_handler,init, 3,[{file,"src/my_handler.erl"},{line,123}]}, - {cowboy_handler,handler_init,4,[{file,"src/cowboy_handler.erl"},{line,169}]}], + Stack = [{my_handler, init, 3, [{file, "src/my_handler.erl"}, {line, 123}]}, + {cowboy_handler, handler_init, 4, [{file, "src/cowboy_handler.erl"}, {line, 169}]}], sync_error_logger:error_msg( "** Cowboy handler ~p terminating in ~p/~p~n" @@ -1642,16 +1642,16 @@ error_logger_redirect_test_() -> [my_handler, init, 3, error, {badmatch, {error, timeout}}, [], "Request", Stack]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Cowboy handler my_handler terminated in my_handler:init/3 with reason: no match of right hand value {error,timeout} in my_handler:init/3 line 123", lists:flatten(Msg)) end }, {"Cowboy error reports, 10 arg version", fun(Sink) -> - Stack = [{my_handler,somecallback, 3,[{file,"src/my_handler.erl"},{line,123}]}, - {cowboy_handler,handler_init,4,[{file,"src/cowboy_handler.erl"},{line,169}]}], + Stack = [{my_handler, somecallback, 3, [{file, "src/my_handler.erl"}, {line, 123}]}, + {cowboy_handler, handler_init, 4, [{file, "src/cowboy_handler.erl"}, {line, 169}]}], sync_error_logger:error_msg( "** Cowboy handler ~p terminating in ~p/~p~n" " for the reason ~p:~p~n** Message was ~p~n" @@ -1661,9 +1661,9 @@ error_logger_redirect_test_() -> {}, "Request", Stack]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Cowboy handler my_handler terminated in my_handler:somecallback/3 with reason: no match of right hand value {error,timeout} in my_handler:somecallback/3 line 123", lists:flatten(Msg)) end }, @@ -1675,15 +1675,15 @@ error_logger_redirect_test_() -> "** Request was ~p~n** State was ~p~n~n", [my_handler, to_json, 2, "Request", {}]), _ = gen_event:which_handlers(error_logger), - {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(error),Level), - ?assertEqual(self(),proplists:get_value(pid,Metadata)), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), ?assertEqual("Cowboy handler my_handler terminated with reason: call to undefined function my_handler:to_json/2", lists:flatten(Msg)) end }, {"Cowboy error reports, 6 arg version", fun(Sink) -> - Stack = [{app_http, init, 2, [{file, "app_http.erl"}, {line,9}]}, + Stack = [{app_http, init, 2, [{file, "app_http.erl"}, {line, 9}]}, {cowboy_handler, execute, 2, [{file, "cowboy_handler.erl"}, {line, 41}]}], ConnectionPid = list_to_pid("<0.82.0>"), sync_error_logger:error_msg( @@ -1795,9 +1795,9 @@ async_threshold_test_() -> %% put a ton of things in the queue WorkCnt = erlang:max(10, (erlang:system_info(schedulers) * 2)), - OtpVsn = lager_util:otp_version(), + OtpVsn = lager_util:otp_version(), % newer OTPs *may* handle the messages faster, so we'll send more - MsgCnt = ((OtpVsn * OtpVsn) div 2), + MsgCnt = ((OtpVsn * OtpVsn) div 2), Workers = spawn_stuffers(WorkCnt, [MsgCnt, info, "hello world"], []), %% serialize on mailbox @@ -1861,10 +1861,10 @@ collect_workers([Ref | Refs]) -> end. produce_n_error_logger_msgs(N) -> - lists:foreach(fun (K) -> + lists:foreach(fun(K) -> error_logger:error_msg("Foo ~p!", [K]) end, - lists:seq(0, N-1) + lists:seq(0, N - 1) ). high_watermark_test_() -> @@ -1883,7 +1883,7 @@ high_watermark_test_() -> end, [ {"Nothing dropped when error_logger high watermark is undefined", - fun () -> + fun() -> ok = error_logger_lager_h:set_high_water(undefined), timer:sleep(100), produce_n_error_logger_msgs(10), @@ -1892,7 +1892,7 @@ high_watermark_test_() -> end }, {"Mostly dropped according to error_logger high watermark", - fun () -> + fun() -> ok = error_logger_lager_h:set_high_water(5), timer:sleep(100), produce_n_error_logger_msgs(50), @@ -1901,10 +1901,10 @@ high_watermark_test_() -> end }, {"Non-notifications are not dropped", - fun () -> + fun() -> ok = error_logger_lager_h:set_high_water(2), timer:sleep(100), - spawn(fun () -> produce_n_error_logger_msgs(300) end), + spawn(fun() -> produce_n_error_logger_msgs(300) end), timer:sleep(50), %% if everything were dropped, this call would be dropped %% too, so lets hope it's not