Class: ExtendedLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/extended_logger/factory.rb,
lib/extended_logger/formatter.rb,
lib/extended_logger/extended_logger.rb,
lib/extended_logger/colored_formatter.rb

Defined Under Namespace

Classes: ColoredFormatter, Factory, Formatter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(receiver, attribute_name = nil) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/extended_logger/extended_logger.rb', line 2

def self.configure receiver, attribute_name=nil
  attribute_name ||= 'logger'.freeze
  setter = "#{attribute_name}=".freeze

  logger = get receiver

  receiver.public_send setter, logger
end

.get(receiver) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/extended_logger/extended_logger.rb', line 11

def self.get receiver
  receiver_name =
    if receiver.is_a? Module
      receiver.name
    else
      receiver.class.name
    end

  logger = Factory.()

  logger.progname = "(#{receiver_name})"
  logger
end

.instanceObject



25
26
27
# File 'lib/extended_logger/extended_logger.rb', line 25

def self.instance
  @instance ||= Factory.()
end

.levelsObject



29
30
31
# File 'lib/extended_logger/extended_logger.rb', line 29

def self.levels
  (-5..6)
end

Instance Method Details

#data(*arguments, &block) ⇒ Object



33
34
35
# File 'lib/extended_logger/extended_logger.rb', line 33

def data *arguments, &block
  add -2, *arguments, &block
end

#focus(*arguments, &block) ⇒ Object



74
75
76
# File 'lib/extended_logger/extended_logger.rb', line 74

def focus *arguments, &block
  add 6, *arguments, &block
end

#format_severity(severity) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/extended_logger/extended_logger.rb', line 37

def format_severity severity
  unless self.class.levels.include? severity
    Kernel.warn "(extended-logger) Unknown log severity level #{severity.inspect}"
  end

  case severity
  when -5 then 'OBS_DATA'.freeze
  when -4 then 'OBS_TRACE'.freeze
  when -3 then 'OBS_DEBUG'.freeze
  when -2 then 'DATA'.freeze
  when -1 then 'TRACE'.freeze
  when 6 then 'FOCUS'.freeze
  else super
  end
end

#ioObject



53
54
55
56
# File 'lib/extended_logger/extended_logger.rb', line 53

def io
  return unless @logdev
  @logdev.dev
end

#obs_data(*arguments, &block) ⇒ Object



58
59
60
# File 'lib/extended_logger/extended_logger.rb', line 58

def obs_data *arguments, &block
  add -5, *arguments, &block
end

#obs_debug(*arguments, &block) ⇒ Object



62
63
64
# File 'lib/extended_logger/extended_logger.rb', line 62

def obs_debug *arguments, &block
  add -3, *arguments, &block
end

#obs_trace(*arguments, &block) ⇒ Object



66
67
68
# File 'lib/extended_logger/extended_logger.rb', line 66

def obs_trace *arguments, &block
  add -4, *arguments, &block
end

#trace(*arguments, &block) ⇒ Object



70
71
72
# File 'lib/extended_logger/extended_logger.rb', line 70

def trace *arguments, &block
  add -1, *arguments, &block
end