Class: SemanticLogger::Formatters::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/semantic_logger/formatters/default.rb

Overview

Default non-colored text log output

Direct Known Subclasses

Color, OneLine, Syslog

Constant Summary

Constants inherited from Base

Base::PRECISION, Base::TIME_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Base

#log_application, #log_host, #time_format

Instance Method Summary collapse

Methods inherited from Base

#initialize, #time

Constructor Details

This class inherits a constructor from SemanticLogger::Formatters::Base

Instance Attribute Details

#logObject

Returns the value of attribute log.



5
6
7
# File 'lib/semantic_logger/formatters/default.rb', line 5

def log
  @log
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/semantic_logger/formatters/default.rb', line 5

def logger
  @logger
end

Instance Method Details

#call(log, logger) ⇒ Object

Default text log format

Generates logs of the form:
  2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World


64
65
66
67
68
69
# File 'lib/semantic_logger/formatters/default.rb', line 64

def call(log, logger)
  self.log    = log
  self.logger = logger

  [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(' ')
end

#durationObject

Duration



35
36
37
# File 'lib/semantic_logger/formatters/default.rb', line 35

def duration
  "(#{log.duration_human})" if log.duration
end

#exceptionObject

Exception



57
58
59
# File 'lib/semantic_logger/formatters/default.rb', line 57

def exception
  "-- Exception: #{log.exception.class}: #{log.exception.message}\n#{log.backtrace_to_s}" if log.exception
end

#levelObject

Log level



11
12
13
# File 'lib/semantic_logger/formatters/default.rb', line 11

def level
  log.level_to_s
end

#messageObject

Log message



45
46
47
# File 'lib/semantic_logger/formatters/default.rb', line 45

def message
  "-- #{log.message}" if log.message
end

#nameObject

Class / app name



40
41
42
# File 'lib/semantic_logger/formatters/default.rb', line 40

def name
  log.name
end

#named_tagsObject

Named Tags



26
27
28
29
30
31
32
# File 'lib/semantic_logger/formatters/default.rb', line 26

def named_tags
  if (named_tags = log.named_tags) && !named_tags.empty?
    list = []
    named_tags.each_pair { |name, value| list << "#{name}: #{value}" }
    "{#{list.join(', ')}}"
  end
end

#payloadObject

Payload



50
51
52
53
54
# File 'lib/semantic_logger/formatters/default.rb', line 50

def payload
  if pl = log.payload_to_s
    "-- #{pl}"
  end
end

#process_infoObject

Process info



16
17
18
# File 'lib/semantic_logger/formatters/default.rb', line 16

def process_info
  "[#{log.process_info}]"
end

#tagsObject

Tags



21
22
23
# File 'lib/semantic_logger/formatters/default.rb', line 21

def tags
  "[#{log.tags.join('] [')}]" if log.tags && !log.tags.empty?
end