ExLoggerMock v1.1.1 ExLoggerMock.Backend View Source
A logging backend for unit testing.
Configure in your config/test.exs
to replace the default :console
backend:
config :logger,
backends: [{ExLoggerMock.Backend, :ex_logger_mock}]
This will suppress all log output on the console during mix test
.
It's simple to assert a certain log message happened in your unit test assertions:
assert_receive {:ex_logger_mock, {:info, "test log message", _timestamp, _metadata}}
Link to this section Summary
Functions
ignore any 'call' notification, including :configure
Handle the log 'event'.
intialise from configuration, but we have no config
Link to this section Functions
ignore any 'call' notification, including :configure
Handle the log 'event'.
Send a message to the original process that created the log event. This is particularly useful in testing scenarios when testing code like:
Logger.warn("test warning message")
You can verify that call happened with test code like:
assert_receive {:ex_logger_mock, {:warn, "test warning message", _timestamp, _metadata}}
NOTE: use assert_receive
, not assert_received
because logging happens asynchronously across
processes; need to give the test response message a short time to arrive.
The third element in the tuple (timestamp) is probably useless in a testing scenario.
The fourth element (metadata) is pulled, untouched, from the incoming log data.
Do nothing if this process is not the 'group leader'.
Do nothing if the event is not a log event.
intialise from configuration, but we have no config