lib/ougai/formatters/base.rb in ougai-1.5.7 vs lib/ougai/formatters/base.rb in ougai-1.5.8

- old
+ new

@@ -2,10 +2,11 @@ require 'socket' module Ougai module Formatters # Base formatter + # Custom formatter must override `_call`. # @attr [Fixnum] trace_indent Specify exception backtrace indent (by default this is 2). # @attr [Fixnum] trace_max_lines Keep exception backtrace lines (by default this is 100). # @attr [Boolean] serialize_backtrace Whether exception should converts String (by default this is on). class Base < Logger::Formatter attr_accessor :trace_indent, :trace_max_lines @@ -17,9 +18,17 @@ @hostname = hostname || Socket.gethostname.force_encoding('UTF-8') @trace_indent = 2 @trace_max_lines = 100 @serialize_backtrace = true self.datetime_format = nil + end + + def call(severity, time, progname, data) + _call(severity, time, progname, data.is_a?(Hash) ? data : { msg: data.to_s }) + end + + def _call(severity, time, progname, data) + raise NotImplementedError, "_call must be implemented" end def datetime_format=(value) @datetime_format = value || default_datetime_format end