Class: SiteFuel::SiteFuelLogger

Inherits:
Logger
  • Object
show all
Includes:
Singleton
Defined in:
lib/sitefuel/SiteFuelLogger.rb

Overview

Singleton abstraction around the Logger

library, typically every processor

will hook into using this logger while letting us control it's placement and display globally

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SiteFuelLogger) initialize(filename = STDOUT)



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sitefuel/SiteFuelLogger.rb', line 44

def initialize(filename = STDOUT)
  super(filename)
  
  @fatal_count = 0
  @error_count = 0
  @warn_count = 0
  @info_count = 0
  @debug_count = 0

  self.level = WARN
  @log_style = :default
  @progname = 'SiteFuel'
end

Instance Attribute Details

- (Object) debug_count (readonly)

the number of debug messages logged so far (even if lower than #level)



35
36
37
# File 'lib/sitefuel/SiteFuelLogger.rb', line 35

def debug_count
  @debug_count
end

- (Object) error_count (readonly)

the number of error messages logged so far (even if lower than #level)



26
27
28
# File 'lib/sitefuel/SiteFuelLogger.rb', line 26

def error_count
  @error_count
end

- (Object) fatal_count (readonly)

the number of fatal messages logged so far (even if lower than #level)



23
24
25
# File 'lib/sitefuel/SiteFuelLogger.rb', line 23

def fatal_count
  @fatal_count
end

- (Object) info_count (readonly)

the number of info messages logged so far (even if lower than #level)



32
33
34
# File 'lib/sitefuel/SiteFuelLogger.rb', line 32

def info_count
  @info_count
end

- (Object) log_style

adjust the style of logging:

default

use the Logger logging style

clean

gives a clean logging output intended for human use



41
42
43
# File 'lib/sitefuel/SiteFuelLogger.rb', line 41

def log_style
  @log_style
end

- (Object) warn_count (readonly)

the number of warning messages logged so far (even if lower than #level)



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

def warn_count
  @warn_count
end

Instance Method Details

- (Object) debug(*args)



83
84
85
86
# File 'lib/sitefuel/SiteFuelLogger.rb', line 83

def debug(*args)
  @debug_count += 1
  super(*args)
end

- (Object) error(*args)



65
66
67
68
# File 'lib/sitefuel/SiteFuelLogger.rb', line 65

def error(*args)
  @error_count += 1
  super(*args)
end

- (Object) fatal(*args)



59
60
61
62
# File 'lib/sitefuel/SiteFuelLogger.rb', line 59

def fatal(*args)
  @fatal_count += 1
  super(*args)
end

- (Object) format_message(severity, date_time, program_name, msg)

implement our own #add so we can have cleaner logs



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sitefuel/SiteFuelLogger.rb', line 90

def format_message(severity, date_time, program_name, msg)
  case @log_style
    when :default
      super(severity, date_time, program_name, msg)

    when :clean
      string = "#{severity}: #{msg}\n"
      case severity
        when 'ERROR', 'FATAL'
          string = bold(red(string))

        when 'WARN'
          string = yellow(string)

        when 'INFO', 'DEBUG'
          string = dark(string)
      end
      string
  end
end

- (Object) info(*args)



77
78
79
80
# File 'lib/sitefuel/SiteFuelLogger.rb', line 77

def info(*args)
  @info_count += 1
  super(*args)
end

- (Object) warn(*args)



71
72
73
74
# File 'lib/sitefuel/SiteFuelLogger.rb', line 71

def warn(*args)
  @warn_count += 1
  super(*args)
end