Class: Gcloud::Logging::Logger
- Inherits:
-
Object
- Object
- Gcloud::Logging::Logger
- Defined in:
- lib/gcloud/logging/logger.rb
Overview
# Logger
A (mostly) API-compatible logger for ruby’s Logger.
Instance Attribute Summary collapse
- #labels ⇒ Object readonly
- #log_name ⇒ Object readonly
- #logging ⇒ Object
- #resource ⇒ Object readonly
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 sending `DEBUG` messages.
-
#error(message = nil) { ... } ⇒ Object
Log an ‘ERROR` entry.
-
#error? ⇒ Boolean
Returns ‘true` if the current severity level allows for sending `ERROR` messages.
-
#fatal(message = nil) { ... } ⇒ Object
Log a ‘FATAL` entry.
-
#fatal? ⇒ Boolean
Returns ‘true` if the current severity level allows for sending `FATAL` messages.
-
#info(message = nil) { ... } ⇒ Object
Log an ‘INFO` entry.
-
#info? ⇒ Boolean
Returns ‘true` if the current severity level allows for sending `INFO` messages.
-
#initialize(logging, log_name, resource, labels = nil) ⇒ Logger
constructor
A new instance of Logger.
-
#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 sending `WARN` messages.
Constructor Details
#initialize(logging, log_name, resource, labels = nil) ⇒ Logger
Returns a new instance of Logger.
55 56 57 58 59 60 61 |
# File 'lib/gcloud/logging/logger.rb', line 55 def initialize logging, log_name, resource, labels = nil @logging = logging @log_name = log_name @resource = resource @labels = labels @level = 0 # DEBUG is the default behavior end |
Instance Attribute Details
#labels ⇒ Object (readonly)
51 52 53 |
# File 'lib/gcloud/logging/logger.rb', line 51 def labels @labels end |
#log_name ⇒ Object (readonly)
43 44 45 |
# File 'lib/gcloud/logging/logger.rb', line 43 def log_name @log_name end |
#logging ⇒ Object
39 40 41 |
# File 'lib/gcloud/logging/logger.rb', line 39 def logging @logging end |
#resource ⇒ Object (readonly)
47 48 49 |
# File 'lib/gcloud/logging/logger.rb', line 47 def resource @resource end |
Instance Method Details
#add(severity, message = nil, progname = nil) { ... } ⇒ Object Also known as: log
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/gcloud/logging/logger.rb', line 186 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.
73 74 75 76 77 78 79 |
# File 'lib/gcloud/logging/logger.rb', line 73 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.
206 207 208 |
# File 'lib/gcloud/logging/logger.rb', line 206 def debug? @level <= 0 end |
#error(message = nil) { ... } ⇒ Object
Log an ‘ERROR` entry.
127 128 129 130 131 132 133 |
# File 'lib/gcloud/logging/logger.rb', line 127 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.
227 228 229 |
# File 'lib/gcloud/logging/logger.rb', line 227 def error? @level <= 3 end |
#fatal(message = nil) { ... } ⇒ Object
Log a ‘FATAL` entry.
145 146 147 148 149 150 151 |
# File 'lib/gcloud/logging/logger.rb', line 145 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.
234 235 236 |
# File 'lib/gcloud/logging/logger.rb', line 234 def fatal? @level <= 4 end |
#info(message = nil) { ... } ⇒ Object
Log an ‘INFO` entry.
91 92 93 94 95 96 97 |
# File 'lib/gcloud/logging/logger.rb', line 91 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.
213 214 215 |
# File 'lib/gcloud/logging/logger.rb', line 213 def info? @level <= 1 end |
#level=(severity) ⇒ Object Also known as: sev_threshold=
Sets the logging severity level.
259 260 261 262 263 |
# File 'lib/gcloud/logging/logger.rb', line 259 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.
164 165 166 167 168 169 170 |
# File 'lib/gcloud/logging/logger.rb', line 164 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.
109 110 111 112 113 114 115 |
# File 'lib/gcloud/logging/logger.rb', line 109 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.
220 221 222 |
# File 'lib/gcloud/logging/logger.rb', line 220 def warn? @level <= 2 end |