lib/semantic_logger/formatters/base.rb in semantic_logger-4.5.0 vs lib/semantic_logger/formatters/base.rb in semantic_logger-4.6.0.beta1
- old
+ new
@@ -1,14 +1,14 @@
require 'time'
module SemanticLogger
module Formatters
class Base
- attr_accessor :time_format, :log_host, :log_application, :precision
+ attr_accessor :time_format, :log_host, :log_application, :log_environment, :precision
# Time precision varies by Ruby interpreter
# JRuby 9.1.8.0 supports microseconds
- PRECISION =
+ PRECISION =
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
@@ -32,24 +32,28 @@
# Whether or not to include application name in logs
# Default: true
# precision: [Integer]
# How many fractional digits to log times with.
# Default: PRECISION (6, except on older JRuby, where 3)
- def initialize(time_format: nil, log_host: true, log_application: true,
+ 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
# Return default time format string
#
# Parameters
# precision: [Integer]
# How many fractional digits to log times with.
# Default: PRECISION (6, except on older JRuby, where 3)
- def self.build_time_format(precision=PRECISION)
+ def self.build_time_format(precision = PRECISION)
"%Y-%m-%d %H:%M:%S.%#{precision}N"
end
# Date & time
def time