io.aviso.logging.capture
added in 0.3.0
Capture logged events for in-process debugging and testing.
logged-events
(logged-events)
Returns a snapshot, as a vector, of all events logged since the last clear of the log (the start of the current test).
Event maps have the following keys:
- :level
- :trace, :debug, etc.
- :logger
- The name of the logger, as a keyword
- :data
- A map of the data parsed as EDN from the event message. If the EDN data can’t be parsed, then this will be a map of
:message
and the message string. - :timestamp
- System time (milliseconds since epoch) of the event.
- :thread-name
- Name of thread on which the event was logged.
- :ex
- The exception associated with the event. This is a map with keys :message and :class-name, and optionally :cause.
Returns a lazy seq of events. However, note that the seq is based on a mutable list that will be unstable if further logging takes place.
logged-events-fixture
(logged-events-fixture f)
Using the expected logback configuration, installs an appender that captures logged EDN data into the *log-data atom.
The appender is removed at the end of the test BUT the captured log data is kept until the start of the next test.
NOTE: When using io.aviso.logging/install-pretty-logging
, the :ex
data will always be nil (install-pretty-logging
overrides the message with a pretty-formatted exception, which results in the exception data seen by the appender being nil.