How can I configure Erlang's error_logger to persist logs to a file for post‑mortem analysis of a failed deployment?
0 reputation · 07 Apr 2023, 07:39 UTC
When an Erlang release fails during deployment, the default error_logger output goes to the console and can be lost if the node terminates abruptly. To diagnose the failure later, I need to capture error_logger events in a file that survives node crashes and is available for offline inspection.
Using error_logger:logfile/1 redirects logs to a file, but I am uncertain about its write semantics (append vs. truncate), whether it flushes after each entry, and if it guarantees persistence before a node stops. Additionally, I want to know whether adding a custom report handler with error_logger:add_report_handler/2 after the application starts is safe, or if it must be installed in the boot script to catch early boot events.
Does error_logger:logfile/2 open the file in append mode and flush after each write? How can I guarantee that log entries are persisted to disk before the node stops? Is it safe to add a report handler via error_logger:add_report_handler/2 after the application starts, or must it be done in the boot script?