Class: SemanticLogger::Formatters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_logger/formatters/base.rb

Direct Known Subclasses

Default, Signalfx

Constant Summary collapse

PRECISION =

Time precision varies by Ruby interpreter JRuby 9.1.8.0 supports microseconds

if defined?(JRuby)
  if JRUBY_VERSION.to_f >= 9.1
    maint = JRUBY_VERSION.match(/\A\d+\.\d+\.(\d+)\./)[1].to_i
    (maint >= 8) || (JRUBY_VERSION.to_f > 9.1) ? 6 : 3
  else
    3
  end
else
  6
end
TIME_FORMAT =
"%Y-%m-%d %H:%M:%S.%#{PRECISION}N".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time_format: TIME_FORMAT, log_host: true, log_application: true) ⇒ Base

Parameters

time_format: [String|Symbol|nil]
  See Time#strftime for the format of this string.
  :iso_8601 Outputs an ISO8601 Formatted timestamp.
  :ms       Output in miliseconds since epoch.
  nil:      Returns Empty string for time ( no time is output ).
  Default: '%Y-%m-%d %H:%M:%S.%6N'


29
30
31
32
33
# File 'lib/semantic_logger/formatters/base.rb', line 29

def initialize(time_format: TIME_FORMAT, log_host: true, log_application: true)
  @time_format     = time_format
  @log_host        = log_host
  @log_application = log_application
end

Instance Attribute Details

#log_applicationObject

Returns the value of attribute log_application.



5
6
7
# File 'lib/semantic_logger/formatters/base.rb', line 5

def log_application
  @log_application
end

#log_hostObject

Returns the value of attribute log_host.



5
6
7
# File 'lib/semantic_logger/formatters/base.rb', line 5

def log_host
  @log_host
end

#time_formatObject

Returns the value of attribute time_format.



5
6
7
# File 'lib/semantic_logger/formatters/base.rb', line 5

def time_format
  @time_format
end

Instance Method Details

#timeObject

Date & time



36
37
38
# File 'lib/semantic_logger/formatters/base.rb', line 36

def time
  format_time(log.time) if time_format
end