By an unhappy accident, OTP21 added functionality for 'named' trace
functions. This has a pattern match that matches the old trace function
(a 2 tuple where the second element is itself a 2 tuple):
https://github.com/erlang/otp/pull/1781
This patch changes to using a versioned record (so we can extend the
tracing later if needed) and adds 3 more options to tracing; count,
timeout and format string.
Additionally, tracing an OTP process via start_link arguments is now
documented.
Prior to this change, lager would simply rename all the files and leave
the 'base' filename empty until a log event came into create it. This
caused confusion with users and tooling.
The fix, as suggested by Shamis Shukoor, is to not delete/rename the
base file, but simply try to open it in write only mode. This will
create the file if it does not exist and truncate it if it does.
Co-authored-by: Shamis Shukoor <shamis657@gmail.com>
To support tracing to a console that is not the erlang node's *direct*
console introduce 2 additional options to the console backend:
`group_leader` and `id`. Group leader allows to use io:put_chars to send
the console output to a remote pid (eg. the group leader on a node
created by nodetool) and the ID allows multiple console backends to
exist simultaneously (for example {lager_console_backend, NodeName}).
Additionally, to support ephemeral console backends with associated
traces, if the console handler explicitly removes itself from the event
handler, remove any traces for that id.
To facilitate this, a new function has been added to the lager module:
`lager:clear_trace_by_destination/1`.
To support OTP 21 we manually start error_logger if it is not present
(and lager is configured to install an error_logger handler) and we add
error_logger as a logger handler.
Longer term we should switch to installing our own logger handler, but
that is a larger task as we'd have to redo all the event parsing, if
that is even possible.