Class: BetterLogFormatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/better_log_formatter.rb

Constant Summary collapse

VERSION =
"0.1.0".freeze
Format =
"%s%s[%d]%s%s -- %s: %s\n".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name) ⇒ BetterLogFormatter

Returns a new instance of BetterLogFormatter.



10
11
12
13
14
# File 'lib/better_log_formatter.rb', line 10

def initialize(app_name)
  @app_name = app_name
  @datetime = datetime_display
  super()
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



7
8
9
# File 'lib/better_log_formatter.rb', line 7

def app_name
  @app_name
end

#datetime_displayObject

Returns the value of attribute datetime_display.



8
9
10
# File 'lib/better_log_formatter.rb', line 8

def datetime_display
  @datetime_display
end

Instance Method Details

#call(severity, datetime, _, message) ⇒ Object



16
17
18
# File 'lib/better_log_formatter.rb', line 16

def call(severity, datetime, _, message)
  Format % [formatted_datetime(datetime), app_name, $$, custom_tags, sidekiq_tags, severity_label(severity), msg2str(message)]
end

#custom_tag(tag_name, &block) ⇒ Object



20
21
22
23
24
# File 'lib/better_log_formatter.rb', line 20

def custom_tag(tag_name, &block)
  @custom_tags ||= {}
  @custom_tags[tag_name] = block
  true
end