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

#initialize(filename = STDOUT) ⇒ SiteFuelLogger



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

#debug_countObject (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

#error_countObject (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

#fatal_countObject (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

#info_countObject (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

#log_styleObject

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

#warn_countObject (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

#debug(*args) ⇒ Object



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

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

#error(*args) ⇒ Object



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

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

#fatal(*args) ⇒ Object



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

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

#format_message(severity, date_time, program_name, msg) ⇒ Object

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

#info(*args) ⇒ Object



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

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

#warn(*args) ⇒ Object



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

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