Class: Pyer::Logger
Overview
Logger class
Defined Under Namespace
Modules: Severity
Constant Summary collapse
- STRING =
-1
- @@default_level =
DEBUG
Constants included from Severity
Severity::COLOURED_LABELS, Severity::DEBUG, Severity::ERROR, Severity::INFO, Severity::NONE, Severity::SEVERITY_LABELS, Severity::WARN
Instance Attribute Summary collapse
-
#level ⇒ Object
Logging severity threshold (e.g.
Logger::INFO
). -
#prefix ⇒ Object
Prefix can be the class name.
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
Close the logging device.
-
#debug(message = nil, &block) ⇒ Object
Log a
DEBUG
message. -
#error(message = nil, &block) ⇒ Object
Log an
ERROR
message. -
#info(message = nil, &block) ⇒ Object
Log an
INFO
message. -
#initialize(logdev = STDOUT) ⇒ Logger
constructor
Create an instance.
- #string ⇒ Object
-
#warn(message = nil, &block) ⇒ Object
Log a
WARN
message.
Constructor Details
#initialize(logdev = STDOUT) ⇒ Logger
Create an instance. outputs log messages on STDOUT, STDERR, a file or a StringIO
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pyer/logger.rb', line 118 def initialize(logdev = STDOUT) @level = @@default_level @prefix = "" @logdev = $stdout @severity_label = COLOURED_LABELS if logdev == STDOUT @logdev = $stdout else if logdev == STDERR @logdev = $stderr else if logdev == STRING # no log device implies that messages are stored in a string @logdev = StringIO.new @severity_label = SEVERITY_LABELS else if logdev.is_a? String # the log device is a file name @logdev = File.new(logdev.to_s, 'a') @severity_label = SEVERITY_LABELS else # the default is no log @level = NONE @logdev = $stderr end end end end end |
Instance Attribute Details
#level ⇒ Object
Logging severity threshold (e.g. Logger::INFO
).
110 111 112 |
# File 'lib/pyer/logger.rb', line 110 def level @level end |
#prefix ⇒ Object
Prefix can be the class name
113 114 115 |
# File 'lib/pyer/logger.rb', line 113 def prefix @prefix end |
Class Method Details
.level ⇒ Object
105 106 107 |
# File 'lib/pyer/logger.rb', line 105 def self.level @@default_level end |
.level=(level) ⇒ Object
101 102 103 |
# File 'lib/pyer/logger.rb', line 101 def self.level=(level) @@default_level = level end |
Instance Method Details
#close ⇒ Object
Close the logging device.
153 154 155 |
# File 'lib/pyer/logger.rb', line 153 def close @logdev.close if @logdev.class == File end |
#debug(message = nil, &block) ⇒ Object
Log a DEBUG
message.
158 159 160 |
# File 'lib/pyer/logger.rb', line 158 def debug( = nil, &block) add(DEBUG, , &block) end |
#error(message = nil, &block) ⇒ Object
Log an ERROR
message.
173 174 175 |
# File 'lib/pyer/logger.rb', line 173 def error( = nil, &block) add(ERROR, , &block) end |
#info(message = nil, &block) ⇒ Object
Log an INFO
message.
163 164 165 |
# File 'lib/pyer/logger.rb', line 163 def info( = nil, &block) add(INFO, , &block) end |
#string ⇒ Object
148 149 150 |
# File 'lib/pyer/logger.rb', line 148 def string @logdev.class == StringIO ? @logdev.string : '' end |
#warn(message = nil, &block) ⇒ Object
Log a WARN
message.
168 169 170 |
# File 'lib/pyer/logger.rb', line 168 def warn( = nil, &block) add(WARN, , &block) end |