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


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

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



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

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

#exceptionObject

Exception



59
60
61
# File 'lib/semantic_logger/formatters/default.rb', line 59

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



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

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

#nameObject

Class / app name



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

def name
  log.name
end

#named_tagsObject

Named Tags



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

def named_tags
  named_tags = log.named_tags
  return if named_tags.nil? || named_tags.empty?

  list = []
  named_tags.each_pair { |name, value| list << "#{name}: #{value}" }
  "{#{list.join(', ')}}"
end

#payloadObject

Payload



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

def payload
  pl = log.payload_to_s
  return unless pl

  "-- #{pl}"
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