Class: Onering::Logger
- Inherits:
-
Object
- Object
- Onering::Logger
- Defined in:
- lib/onering/logger.rb
Class Method Summary collapse
- ._get_level(severity) ⇒ Object
- .debug(message, source = nil) ⇒ Object
- .debug2(message, source = nil) ⇒ Object
- .debug3(message, source = nil) ⇒ Object
- .error(message, source = nil) ⇒ Object
- .fatal(message, source = nil, raise_error = false) ⇒ Object
- .fatal!(message, source = nil) ⇒ Object
- .info(message, source = nil) ⇒ Object
- .level=(severity) ⇒ Object
- .log(severity, message, source = nil, verbosity = 1) ⇒ Object
- .logger ⇒ Object
- .output(message, source = nil) ⇒ Object
- .setup(options = {}) ⇒ Object
- .warn(message, source = nil) ⇒ Object
Class Method Details
._get_level(severity) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/onering/logger.rb', line 126 def self._get_level(severity) case severity.to_sym when :fatal return ::Logger::FATAL when :error return ::Logger::ERROR when :warn return ::Logger::WARN when :info return ::Logger::INFO else return ::Logger::DEBUG end end |
.debug(message, source = nil) ⇒ Object
110 111 112 |
# File 'lib/onering/logger.rb', line 110 def self.debug(, source=nil) self.log(:debug, , source) end |
.debug2(message, source = nil) ⇒ Object
114 115 116 |
# File 'lib/onering/logger.rb', line 114 def self.debug2(, source=nil) self.log(:debug, , source, 2) end |
.debug3(message, source = nil) ⇒ Object
118 119 120 |
# File 'lib/onering/logger.rb', line 118 def self.debug3(, source=nil) self.log(:debug, , source, 3) end |
.error(message, source = nil) ⇒ Object
98 99 100 |
# File 'lib/onering/logger.rb', line 98 def self.error(, source=nil) self.log(:error, , source) end |
.fatal(message, source = nil, raise_error = false) ⇒ Object
89 90 91 92 |
# File 'lib/onering/logger.rb', line 89 def self.fatal(, source=nil, raise_error=false) self.log(:fatal, , source) raise Onering::Client::FatalError.new() if raise_error === true end |
.fatal!(message, source = nil) ⇒ Object
94 95 96 |
# File 'lib/onering/logger.rb', line 94 def self.fatal!(, source=nil) self.fatal(, source, true) end |
.info(message, source = nil) ⇒ Object
106 107 108 |
# File 'lib/onering/logger.rb', line 106 def self.info(, source=nil) self.log(:info, , source) end |
.level=(severity) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/onering/logger.rb', line 70 def self.level=(severity) @_logger.sev_threshold = _get_level(severity) @_verbosity = (Integer(severity.to_s[-1]) rescue 1) @_logger.sev_threshold end |
.log(severity, message, source = nil, verbosity = 1) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/onering/logger.rb', line 78 def self.log(severity, , source=nil, verbosity=1) if defined?(@_logger) if @_verbosity >= verbosity @_logger.add(_get_level(severity), , source) return true end end return false end |
.logger ⇒ Object
66 67 68 |
# File 'lib/onering/logger.rb', line 66 def self.logger() return @_logger end |
.output(message, source = nil) ⇒ Object
122 123 124 |
# File 'lib/onering/logger.rb', line 122 def self.output(, source=nil) self.log(:output, , source) end |
.setup(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/onering/logger.rb', line 7 def self.setup(={}) outputfn = [:destination] @_verbosity = 1 if [:destination] == /STDOUT/i [:destination] = STDOUT elsif [:destination] == /STDERR/i or [:destination].nil? [:destination] = STDERR elsif File.writable?([:destination]) [:destination] = File.open([:destination], 'a') else [:destination] = STDERR end @_logger = ::Logger.new([:destination]) @_logger.formatter = ([:formatter] || proc{|severity, datetime, source, msg| case severity.downcase.to_sym when :fatal then sevtag = '!!' when :error then sevtag = 'EE' when :warn then sevtag = 'WW' when :info then sevtag = 'II' when :debug then sevtag = 'DD' when :output then sevtag = '' else sevtag = '??' end if [:sevtag] == false logline = [(source.nil? ? nil : "[#{source}]"), msg].compact.join(' ') else logline = ["#{sevtag} ", (source.nil? ? nil : "[#{source}]"), msg].compact.join(' ') end if [:destination] === STDOUT or [:destination] === STDERR case severity.downcase.to_sym when :fatal, :error logline = logline.foreground(:red) when :warn logline = logline.foreground(:yellow) when :info logline = logline.foreground(:green) when :debug, :debug2, :debug3 logline = logline.foreground(:blue) end end [:destination].puts(logline) }) self.level = ([:threshold] || :info) self.debug("onering-client v#{Onering::Client::VERSION} started") if defined?(Onering::FULL_CLIENT) self.debug("Logger is initialized. Output is #{outputfn || 'stderr'}, threshold: #{[:threshold]} or worse", ([:name] || "Onering::Logger")) end |
.warn(message, source = nil) ⇒ Object
102 103 104 |
# File 'lib/onering/logger.rb', line 102 def self.warn(, source=nil) self.log(:warn, , source) end |