class SemanticLogger::Formatters::Base
def self.build_time_format(precision = PRECISION)
How many fractional digits to log times with.
precision: [Integer]
Parameters
Return default time format string
def self.build_time_format(precision = PRECISION) "%Y-%m-%d %H:%M:%S.%#{precision}N" end
def format_time(time)
def format_time(time) time = time.dup case time_format when :rfc_3339 time.utc.to_datetime.rfc3339 when :iso_8601 time.utc.iso8601(precision) when :ms (time.to_f * 1_000).to_i when :none time when :seconds time.to_f when :notime "" else time.strftime(time_format) end end
def initialize(time_format: nil,
How many fractional digits to log times with.
precision: [Integer]
Default: true
Whether or not to include application name in logs
log_application: [Boolean]
Default: true
Whether or not to include hostname in logs
log_host: [Boolean]
Default: '%Y-%m-%d %H:%M:%S.%
:notime Returns an empty string for time ( no time is output ).
:ms Output in miliseconds since epoch.
:iso_8601 Outputs an ISO8601 Formatted timestamp.
See Time#strftime for the format of this string.
time_format: [String|Symbol|nil]
Parameters
def initialize(time_format: nil, log_host: true, log_application: true, log_environment: true, precision: PRECISION) @time_format = time_format || self.class.build_time_format(precision) @log_host = log_host @log_application = log_application @log_environment = log_environment @precision = precision end
def pid
def pid $$ end
def time
def time format_time(log.time) if time_format end