lib/ougai/formatters/base.rb in ougai-1.5.0 vs lib/ougai/formatters/base.rb in ougai-1.5.2

- old
+ new

@@ -1,6 +1,5 @@ -require 'logger' require 'time' require 'socket' module Ougai module Formatters @@ -11,12 +10,17 @@ def initialize(app_name = nil, hostname = nil) @app_name = app_name || File.basename($0, ".rb") @hostname = hostname || Socket.gethostname.force_encoding('UTF-8') @trace_indent = 2 @trace_max_lines = 100 + self.datetime_format = nil end + def datetime_format=(value) + @datetime_format = value || default_datetime_format + end + def serialize_exc(ex) err = { name: ex.class.name, message: ex.to_s } @@ -27,9 +31,22 @@ end def serialize_trace(trace) sp = "\n" + ' ' * @trace_indent trace.slice(0, @trace_max_lines).join(sp) + end + + private + + def format_datetime(time) + time.strftime(@datetime_format) + end + + def default_datetime_format + t = Time.new + f = '%FT%T.%3N' + f << (t.utc? ? 'Z' : '%:z') + f.freeze end end end end