Class: Google::Cloud::Logging::Logger
- Inherits:
-
Object
- Object
- Google::Cloud::Logging::Logger
- Defined in:
- lib/google/cloud/logging/logger.rb
Overview
Logger
A (mostly) API-compatible logger for ruby's Logger.
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil) { ... } ⇒ Object
(also: #log)
Log a message if the given severity is high enough.
-
#debug(message = nil) { ... } ⇒ Object
Log a
DEBUG
entry. -
#debug? ⇒ Boolean
Returns
true
if the current severity level allows for sendingDEBUG
messages. -
#error(message = nil) { ... } ⇒ Object
Log an
ERROR
entry. -
#error? ⇒ Boolean
Returns
true
if the current severity level allows for sendingERROR
messages. -
#fatal(message = nil) { ... } ⇒ Object
Log a
FATAL
entry. -
#fatal? ⇒ Boolean
Returns
true
if the current severity level allows for sendingFATAL
messages. -
#info(message = nil) { ... } ⇒ Object
Log an
INFO
entry. -
#info? ⇒ Boolean
Returns
true
if the current severity level allows for sendingINFO
messages. -
#level=(severity) ⇒ Object
(also: #sev_threshold=)
Sets the logging severity level.
-
#unknown(message = nil) { ... } ⇒ Object
Log an
UNKNOWN
entry. -
#warn(message = nil) { ... } ⇒ Object
Log a
WARN
entry. -
#warn? ⇒ Boolean
Returns
true
if the current severity level allows for sendingWARN
messages.
Instance Method Details
#add(severity, message = nil, progname = nil) { ... } ⇒ Object Also known as: log
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/google/cloud/logging/logger.rb', line 187 def add severity, = nil, progname = nil severity = derive_severity(severity) || 5 # 5 is UNKNOWN/DEFAULT return true if severity < @level if .nil? if block_given? = yield else = progname # progname = nil # TODO: Figure out what to do with the progname end end write_entry severity, end |
#debug(message = nil) { ... } ⇒ Object
Log a DEBUG
entry.
74 75 76 77 78 79 80 |
# File 'lib/google/cloud/logging/logger.rb', line 74 def debug = nil, &block if block_given? add 0, nil, , &block else add 0, , nil, &block end end |
#debug? ⇒ Boolean
Returns true
if the current severity level allows for sending
DEBUG
messages.
207 208 209 |
# File 'lib/google/cloud/logging/logger.rb', line 207 def debug? @level <= 0 end |
#error(message = nil) { ... } ⇒ Object
Log an ERROR
entry.
128 129 130 131 132 133 134 |
# File 'lib/google/cloud/logging/logger.rb', line 128 def error = nil, &block if block_given? add 3, nil, , &block else add 3, , nil, &block end end |
#error? ⇒ Boolean
Returns true
if the current severity level allows for sending
ERROR
messages.
228 229 230 |
# File 'lib/google/cloud/logging/logger.rb', line 228 def error? @level <= 3 end |
#fatal(message = nil) { ... } ⇒ Object
Log a FATAL
entry.
146 147 148 149 150 151 152 |
# File 'lib/google/cloud/logging/logger.rb', line 146 def fatal = nil, &block if block_given? add 4, nil, , &block else add 4, , nil, &block end end |
#fatal? ⇒ Boolean
Returns true
if the current severity level allows for sending
FATAL
messages.
235 236 237 |
# File 'lib/google/cloud/logging/logger.rb', line 235 def fatal? @level <= 4 end |
#info(message = nil) { ... } ⇒ Object
Log an INFO
entry.
92 93 94 95 96 97 98 |
# File 'lib/google/cloud/logging/logger.rb', line 92 def info = nil, &block if block_given? add 1, nil, , &block else add 1, , nil, &block end end |
#info? ⇒ Boolean
Returns true
if the current severity level allows for sending INFO
messages.
214 215 216 |
# File 'lib/google/cloud/logging/logger.rb', line 214 def info? @level <= 1 end |
#level=(severity) ⇒ Object Also known as: sev_threshold=
Sets the logging severity level.
260 261 262 263 264 |
# File 'lib/google/cloud/logging/logger.rb', line 260 def level= severity new_level = derive_severity severity fail ArgumentError, "invalid log level: #{severity}" if new_level.nil? @level = new_level end |
#unknown(message = nil) { ... } ⇒ Object
Log an UNKNOWN
entry. This will be printed no matter what the
logger's current severity level is.
165 166 167 168 169 170 171 |
# File 'lib/google/cloud/logging/logger.rb', line 165 def unknown = nil, &block if block_given? add 5, nil, , &block else add 5, , nil, &block end end |
#warn(message = nil) { ... } ⇒ Object
Log a WARN
entry.
110 111 112 113 114 115 116 |
# File 'lib/google/cloud/logging/logger.rb', line 110 def warn = nil, &block if block_given? add 2, nil, , &block else add 2, , nil, &block end end |
#warn? ⇒ Boolean
Returns true
if the current severity level allows for sending WARN
messages.
221 222 223 |
# File 'lib/google/cloud/logging/logger.rb', line 221 def warn? @level <= 2 end |