Class: SemanticLogger::Appender::Base

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

Direct Known Subclasses

File, MongoDB, Wrapper

Instance Attribute Summary collapse

Attributes inherited from Base

#level, #name

Instance Method Summary collapse

Methods inherited from Base

default_level, default_level=, #payload, #tags, #with_payload, #with_tags

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



12
13
14
# File 'lib/semantic_logger/appender/base.rb', line 12

def formatter
  @formatter
end

Instance Method Details

#default_formatterObject

Default log formatter

Replace this formatter by supplying a Block to the initializer
Generates logs of the form:
  2011-07-19 14:36:15.660 D [1149:ScriptThreadProcess] Rails -- Hello World


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/semantic_logger/appender/base.rb', line 18

def default_formatter
  Proc.new do |log|
    tags = log.tags.collect { |tag| "[#{tag}]" }.join(" ") + " " if log.tags && (log.tags.size > 0)

    message = log.message.to_s
    message << " -- " << log.payload.inspect if log.payload
    message << " -- " << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception

    duration_str = log.duration ? "(#{'%.1f' % log.duration}ms) " : ''

    "#{SemanticLogger::Appender::Base.formatted_time(log.time)} #{log.level.to_s[0..0].upcase} [#{$$}:#{log.thread_name}] #{tags}#{duration_str}#{log.name} -- #{message}"
  end
end