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 ⇒ Object
Returns the value of attribute log.
-
#log_application ⇒ Object
Returns the value of attribute log_application.
-
#log_environment ⇒ Object
Returns the value of attribute log_environment.
-
#log_host ⇒ Object
Returns the value of attribute log_host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#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, log_environment: true, precision: PRECISION) ⇒ Base
constructor
Parameters time_format: [String|Symbol|nil] See Time#strftime for the format of this string.
-
#pid ⇒ Object
Process ID.
-
#time ⇒ Object
Date & time.
Constructor Details
#initialize(time_format: nil, log_host: true, log_application: true, log_environment: 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 .
:ms Output in miliseconds since epoch.
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)
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/semantic_logger/formatters/base.rb', line 36 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 |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log @log end |
#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_environment ⇒ Object
Returns the value of attribute log_environment.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def log_environment @log_environment 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 |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/semantic_logger/formatters/base.rb', line 5 def logger @logger 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)
54 55 56 |
# File 'lib/semantic_logger/formatters/base.rb', line 54 def self.build_time_format(precision = PRECISION) "%Y-%m-%d %H:%M:%S.%#{precision}N" end |
Instance Method Details
#pid ⇒ Object
Process ID
64 65 66 |
# File 'lib/semantic_logger/formatters/base.rb', line 64 def pid $$ end |
#time ⇒ Object
Date & time
59 60 61 |
# File 'lib/semantic_logger/formatters/base.rb', line 59 def time format_time(log.time) if time_format end |