Class: SemanticLogger::Formatters::Base
- Inherits:
-
Object
- Object
- SemanticLogger::Formatters::Base
- Defined in:
- lib/semantic_logger/formatters/base.rb
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
Instance Attribute Summary collapse
-
#log_application ⇒ Object
Returns the value of attribute log_application.
-
#log_host ⇒ Object
Returns the value of attribute log_host.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#time_format ⇒ Object
Returns the value of attribute time_format.
Class Method Summary collapse
-
.build_time_format(precision = PRECISION) ⇒ Object
Return default time format string.
Instance Method Summary collapse
-
#initialize(time_format: nil, log_host: true, log_application: true, precision: PRECISION) ⇒ Base
constructor
Parameters time_format: [String|Symbol|nil] See Time#strftime for the format of this string.
-
#time ⇒ Object
Date & time.
Constructor Details
#initialize(time_format: nil, log_host: true, log_application: true, precision: PRECISION) ⇒ 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.%<precision>N'
log_host: [Boolean]
Whether or not to include hostname in logs
Default: true
log_application: [Boolean]
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)
37 38 39 40 41 42 43 |
# File 'lib/semantic_logger/formatters/base.rb', line 37 def initialize(time_format: nil, log_host: true, log_application: true, precision: PRECISION) @time_format = time_format || self.class.build_time_format(precision) @log_host = log_host @log_application = log_application @precision = precision end |
Instance Attribute Details
#log_application ⇒ Object
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_host ⇒ Object
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 |
#precision ⇒ Object
Returns the value of attribute precision.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def precision @precision end |
#time_format ⇒ Object
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 |
Class Method Details
.build_time_format(precision = PRECISION) ⇒ Object
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)
51 52 53 |
# File 'lib/semantic_logger/formatters/base.rb', line 51 def self.build_time_format(precision=PRECISION) "%Y-%m-%d %H:%M:%S.%#{precision}N" end |
Instance Method Details
#time ⇒ Object
Date & time
56 57 58 |
# File 'lib/semantic_logger/formatters/base.rb', line 56 def time format_time(log.time) if time_format end |