To create a custom log formatter in Ougai, you must inherit from Ougai::Formatters::Base and override the _call method. The call method is the public entrypoint that handles data normalization (ensuring data is a Hash), while _call is where you implement your specific formatting logic.
_call expects the following arguments:
severity: The log level (e.g., INFO, ERROR).time: The timestamp of the log event.progname: The program name.data: A Hash containing the log message and any custom metadata.
class MyCustomFormatter < Ougai::Formatters::Base
def _call(severity, time, progname, data)
# Implement custom formatting logic here
# data is guaranteed to be a Hash
end
end