google-cloud-logging 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/google/cloud/logging/async_writer.rb +76 -175
- data/lib/google/cloud/logging/logger.rb +85 -26
- data/lib/google/cloud/logging/v2/config_service_v2_client_config.json +1 -3
- data/lib/google/cloud/logging/v2/logging_service_v2_client_config.json +1 -3
- data/lib/google/cloud/logging/v2/metrics_service_v2_client_config.json +1 -3
- data/lib/google/cloud/logging/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2040c01767882892eec9ab8951ae42563a026a48
|
4
|
+
data.tar.gz: 5024c4eae693b2e0822d5928da4a305837ffcac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 394d202895b1719f155846ea0b38423aabc9b8c173f39283348a12a3ec69d915a3e6e17d1193dc7dcd7f251f3560f6d78b4338a3be44eb53978319cecaebcada
|
7
|
+
data.tar.gz: 8274d6c0f7686057113cb07a5cf5e89cd0302b3861fc3095ee96adacc134fdd9b4b05b810a8ac982ec5389915c162e5be0f6d7de3e813290f72aafe0c9c13812
|
@@ -12,8 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require "set"
|
16
15
|
|
16
|
+
require "set"
|
17
|
+
require "stackdriver/core/async_actor"
|
17
18
|
|
18
19
|
module Google
|
19
20
|
module Cloud
|
@@ -53,12 +54,11 @@ module Google
|
|
53
54
|
# labels: labels
|
54
55
|
#
|
55
56
|
class AsyncWriter
|
56
|
-
|
57
|
-
CLEANUP_TIMEOUT = 10.0
|
58
|
-
WAIT_INTERVAL = 1.0
|
57
|
+
include Stackdriver::Core::AsyncActor
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
DEFAULT_MAX_QUEUE_SIZE = 10000
|
60
|
+
CLEANUP_TIMEOUT = Stackdriver::Core::AsyncActor::CLEANUP_TIMEOUT
|
61
|
+
WAIT_INTERVAL = Stackdriver::Core::AsyncActor::WAIT_INTERVAL
|
62
62
|
|
63
63
|
##
|
64
64
|
# @private Item in the log entries queue.
|
@@ -85,7 +85,9 @@ module Google
|
|
85
85
|
|
86
86
|
##
|
87
87
|
# The current state. Either :running, :suspended, :stopping, or :stopped
|
88
|
-
|
88
|
+
#
|
89
|
+
# DEPRECATED. Use #async_state instead.
|
90
|
+
alias_method :state, :async_state
|
89
91
|
|
90
92
|
##
|
91
93
|
# The last exception thrown by the background thread, or nil if nothing
|
@@ -95,11 +97,13 @@ module Google
|
|
95
97
|
##
|
96
98
|
# @private Creates a new AsyncWriter instance.
|
97
99
|
def initialize logging, max_queue_size = DEFAULT_MAX_QUEUE_SIZE
|
100
|
+
super()
|
101
|
+
|
98
102
|
@logging = logging
|
99
103
|
@max_queue_size = max_queue_size
|
100
|
-
@
|
101
|
-
@
|
102
|
-
@
|
104
|
+
@queue_resource = new_cond
|
105
|
+
@queue = []
|
106
|
+
@queue_size = 0
|
103
107
|
end
|
104
108
|
|
105
109
|
##
|
@@ -145,16 +149,16 @@ module Google
|
|
145
149
|
def write_entries entries, log_name: nil, resource: nil, labels: nil
|
146
150
|
ensure_thread
|
147
151
|
entries = Array(entries)
|
148
|
-
|
152
|
+
synchronize do
|
149
153
|
fail "AsyncWriter has been stopped" unless writable?
|
150
154
|
queue_item = QueueItem.new entries, log_name, resource, labels
|
151
155
|
if @queue.empty? || !@queue.last.try_combine(queue_item)
|
152
156
|
@queue.push queue_item
|
153
157
|
end
|
154
158
|
@queue_size += entries.size
|
155
|
-
@
|
159
|
+
@queue_resource.broadcast
|
156
160
|
while @max_queue_size && @queue_size > @max_queue_size
|
157
|
-
@
|
161
|
+
@queue_resource.wait
|
158
162
|
end
|
159
163
|
end
|
160
164
|
self
|
@@ -202,21 +206,12 @@ module Google
|
|
202
206
|
# issued writes will complete. Once any existing backlog has been
|
203
207
|
# cleared, the state will change to :stopped.
|
204
208
|
#
|
209
|
+
# DEPRECATED. Use #async_stop instead.
|
210
|
+
#
|
205
211
|
# @return [Boolean] Returns true if the writer was running, or false
|
206
212
|
# if the writer had already been stopped.
|
207
213
|
#
|
208
|
-
|
209
|
-
ensure_thread
|
210
|
-
@lock.synchronize do
|
211
|
-
if state != :stopped
|
212
|
-
@state = :stopping
|
213
|
-
@lock_cond.broadcast
|
214
|
-
true
|
215
|
-
else
|
216
|
-
false
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
214
|
+
alias_method :stop, :async_stop
|
220
215
|
|
221
216
|
##
|
222
217
|
# Suspends this asynchronous writer.
|
@@ -224,21 +219,12 @@ module Google
|
|
224
219
|
# After this call succeeds, the state will change to :suspended, and
|
225
220
|
# the writer will stop sending RPCs until resumed.
|
226
221
|
#
|
222
|
+
# DEPRECATED. Use #async_suspend instead.
|
223
|
+
#
|
227
224
|
# @return [Boolean] Returns true if the writer had been running and was
|
228
225
|
# suspended, otherwise false.
|
229
226
|
#
|
230
|
-
|
231
|
-
ensure_thread
|
232
|
-
@lock.synchronize do
|
233
|
-
if state == :running
|
234
|
-
@state = :suspended
|
235
|
-
@lock_cond.broadcast
|
236
|
-
true
|
237
|
-
else
|
238
|
-
false
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
227
|
+
alias_method :suspend, :async_suspend
|
242
228
|
|
243
229
|
##
|
244
230
|
# Resumes this suspended asynchronous writer.
|
@@ -246,99 +232,69 @@ module Google
|
|
246
232
|
# After this call succeeds, the state will change to :running, and
|
247
233
|
# the writer will resume sending RPCs.
|
248
234
|
#
|
235
|
+
# DEPRECATED. Use #async_resume instead.
|
236
|
+
#
|
249
237
|
# @return [Boolean] Returns true if the writer had been suspended and
|
250
238
|
# is now running, otherwise false.
|
251
239
|
#
|
252
|
-
|
253
|
-
ensure_thread
|
254
|
-
@lock.synchronize do
|
255
|
-
if state == :suspended
|
256
|
-
@state = :running
|
257
|
-
@lock_cond.broadcast
|
258
|
-
true
|
259
|
-
else
|
260
|
-
false
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
240
|
+
alias_method :resume, :async_resume
|
264
241
|
|
265
242
|
##
|
266
243
|
# Returns true if this writer is running.
|
267
244
|
#
|
245
|
+
# DEPRECATED. Use #async_running? instead.
|
246
|
+
#
|
268
247
|
# @return [Boolean] Returns true if the writer is currently running.
|
269
248
|
#
|
270
|
-
|
271
|
-
ensure_thread
|
272
|
-
@lock.synchronize do
|
273
|
-
state == :running
|
274
|
-
end
|
275
|
-
end
|
249
|
+
alias_method :running?, :async_running?
|
276
250
|
|
277
251
|
##
|
278
252
|
# Returns true if this writer is suspended.
|
279
253
|
#
|
254
|
+
# DEPRECATED. Use #async_suspended? instead.
|
255
|
+
#
|
280
256
|
# @return [Boolean] Returns true if the writer is currently suspended.
|
281
257
|
#
|
282
|
-
|
283
|
-
ensure_thread
|
284
|
-
@lock.synchronize do
|
285
|
-
state == :suspended
|
286
|
-
end
|
287
|
-
end
|
258
|
+
alias_method :suspended?, :async_suspended?
|
288
259
|
|
289
260
|
##
|
290
261
|
# Returns true if this writer is still accepting writes. This means
|
291
262
|
# it is either running or suspended.
|
292
263
|
#
|
264
|
+
# DEPRECATED. Use #async_working? instead.
|
265
|
+
#
|
293
266
|
# @return [Boolean] Returns true if the writer is accepting writes.
|
294
267
|
#
|
295
|
-
|
296
|
-
ensure_thread
|
297
|
-
@lock.synchronize do
|
298
|
-
state == :suspended || state == :running
|
299
|
-
end
|
300
|
-
end
|
268
|
+
alias_method :writable?, :async_working?
|
301
269
|
|
302
270
|
##
|
303
271
|
# Returns true if this writer is fully stopped.
|
304
272
|
#
|
273
|
+
# DEPRECATED. Use #async_stopped? instead.
|
274
|
+
#
|
305
275
|
# @return [Boolean] Returns true if the writer is fully stopped.
|
306
276
|
#
|
307
|
-
|
308
|
-
ensure_thread
|
309
|
-
@lock.synchronize do
|
310
|
-
state == :stopped
|
311
|
-
end
|
312
|
-
end
|
277
|
+
alias_method :stopped?, :async_stopped?
|
313
278
|
|
314
279
|
##
|
315
280
|
# Blocks until this asynchronous writer has been stopped, or the given
|
316
281
|
# timeout (if present) has elapsed.
|
317
282
|
#
|
283
|
+
# DEPRECATED. Use #wait_until_async_stopped instead.
|
284
|
+
#
|
318
285
|
# @param [Number, nil] timeout Timeout in seconds, or `nil` for no
|
319
286
|
# timeout.
|
320
287
|
#
|
321
288
|
# @return [Boolean] Returns true if the writer is stopped, or false
|
322
289
|
# if the timeout expired.
|
323
290
|
#
|
324
|
-
|
325
|
-
ensure_thread
|
326
|
-
deadline = timeout ? ::Time.new.to_f + timeout : nil
|
327
|
-
@lock.synchronize do
|
328
|
-
until state == :stopped
|
329
|
-
cur_time = ::Time.new.to_f
|
330
|
-
return false if deadline && cur_time >= deadline
|
331
|
-
interval = deadline ? deadline - cur_time : WAIT_INTERVAL
|
332
|
-
interval = WAIT_INTERVAL if interval > WAIT_INTERVAL
|
333
|
-
@lock_cond.wait interval
|
334
|
-
end
|
335
|
-
end
|
336
|
-
true
|
337
|
-
end
|
291
|
+
alias_method :wait_until_stopped, :wait_until_async_stopped
|
338
292
|
|
339
293
|
##
|
340
294
|
# Stop this asynchronous writer and block until it has been stopped.
|
341
295
|
#
|
296
|
+
# DEPRECATED. Use #async_stop! instead.
|
297
|
+
#
|
342
298
|
# @param [Number] timeout Timeout in seconds.
|
343
299
|
# @param [Boolean] force If set to true, and the writer hasn't stopped
|
344
300
|
# within the given timeout, kill it forcibly by terminating the
|
@@ -351,63 +307,41 @@ module Google
|
|
351
307
|
# after the timeout, or `:forced` if it was forcibly killed.
|
352
308
|
#
|
353
309
|
def stop! timeout, force: false
|
354
|
-
|
355
|
-
|
356
|
-
return :timeout unless force
|
357
|
-
@thread.kill
|
358
|
-
@thread.join
|
359
|
-
:forced
|
360
|
-
end
|
310
|
+
@cleanup_options[:timeout] = timeout unless timeout.nil?
|
311
|
+
@cleanup_options[:force] = force unless force.nil?
|
361
312
|
|
362
|
-
|
313
|
+
async_stop!
|
314
|
+
end
|
363
315
|
|
364
316
|
##
|
365
|
-
# @private
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
#
|
370
|
-
def ensure_thread
|
371
|
-
@startup_lock.synchronize do
|
372
|
-
if (@thread.nil? || !@thread.alive?) && @state != :stopped
|
373
|
-
@queue_size = 0
|
374
|
-
@queue = []
|
375
|
-
@lock = Monitor.new
|
376
|
-
@lock_cond = @lock.new_cond
|
377
|
-
AsyncWriter.register_for_cleanup self
|
378
|
-
@thread = Thread.new do
|
379
|
-
run_backgrounder
|
380
|
-
AsyncWriter.unregister_for_cleanup self
|
381
|
-
end
|
382
|
-
end
|
317
|
+
# @private Callback function when the async actor thread state changes
|
318
|
+
def on_async_state_change
|
319
|
+
synchronize do
|
320
|
+
@queue_resource.broadcast
|
383
321
|
end
|
384
322
|
end
|
385
323
|
|
324
|
+
protected
|
325
|
+
|
386
326
|
##
|
387
327
|
# @private The background thread implementation, which continuously
|
388
328
|
# waits for and performs work, and returns only when fully stopped.
|
389
329
|
#
|
390
330
|
def run_backgrounder
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
@last_exception = e
|
405
|
-
end
|
331
|
+
queue_item = wait_next_item
|
332
|
+
return unless queue_item
|
333
|
+
begin
|
334
|
+
logging.write_entries(
|
335
|
+
queue_item.entries,
|
336
|
+
log_name: queue_item.log_name,
|
337
|
+
resource: queue_item.resource,
|
338
|
+
labels: queue_item.labels
|
339
|
+
)
|
340
|
+
rescue => e
|
341
|
+
# Ignore any exceptions thrown from the background thread, but
|
342
|
+
# keep running to ensure its state behavior remains consistent.
|
343
|
+
@last_exception = e
|
406
344
|
end
|
407
|
-
ensure
|
408
|
-
# If something drastic happened like the thread was killed, make
|
409
|
-
# sure the state is consistent.
|
410
|
-
@state = :stopped
|
411
345
|
end
|
412
346
|
|
413
347
|
##
|
@@ -418,61 +352,28 @@ module Google
|
|
418
352
|
# queue, returns `nil`.
|
419
353
|
#
|
420
354
|
def wait_next_item
|
421
|
-
|
355
|
+
synchronize do
|
422
356
|
while state == :suspended ||
|
423
357
|
(state == :running && @queue.empty?)
|
424
|
-
@
|
358
|
+
@queue_resource.wait
|
425
359
|
end
|
426
360
|
queue_item = nil
|
427
|
-
|
428
|
-
@state = :stopped
|
429
|
-
else
|
361
|
+
unless @queue.empty?
|
430
362
|
queue_item = @queue.shift
|
431
363
|
@queue_size -= queue_item.entries.size
|
432
364
|
end
|
433
|
-
@
|
365
|
+
@queue_resource.broadcast
|
434
366
|
queue_item
|
435
367
|
end
|
436
368
|
end
|
437
369
|
|
438
370
|
##
|
439
|
-
#
|
440
|
-
#
|
441
|
-
#
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
unless @cleanup_list
|
446
|
-
@cleanup_list = ::Set.new
|
447
|
-
at_exit { AsyncWriter.run_cleanup }
|
448
|
-
end
|
449
|
-
@cleanup_list.add async
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
##
|
454
|
-
# Unregister the given AsyncWriter for cleanup on VM exit.
|
455
|
-
#
|
456
|
-
# @private
|
457
|
-
#
|
458
|
-
def self.unregister_for_cleanup async
|
459
|
-
@exit_lock.synchronize do
|
460
|
-
@cleanup_list.delete async if @cleanup_list
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
##
|
465
|
-
# Exit hook that cleans up any running AsyncWriters.
|
466
|
-
#
|
467
|
-
# @private
|
468
|
-
#
|
469
|
-
def self.run_cleanup
|
470
|
-
@exit_lock.synchronize do
|
471
|
-
if @cleanup_list
|
472
|
-
@cleanup_list.each do |async|
|
473
|
-
async.stop! CLEANUP_TIMEOUT, force: true
|
474
|
-
end
|
475
|
-
end
|
371
|
+
# @private Override the #backgrounder_stoppable? method from AsyncActor
|
372
|
+
# module. The actor can be gracefully stopped when queue is
|
373
|
+
# empty.
|
374
|
+
def backgrounder_stoppable?
|
375
|
+
synchronize do
|
376
|
+
@queue.empty?
|
476
377
|
end
|
477
378
|
end
|
478
379
|
end
|
@@ -71,6 +71,12 @@ module Google
|
|
71
71
|
# The logging severity threshold (e.g. `Logger::INFO`)
|
72
72
|
attr_reader :level
|
73
73
|
alias_method :sev_threshold, :level
|
74
|
+
alias_method :local_level, :level
|
75
|
+
|
76
|
+
##
|
77
|
+
# Boolean flag that indicates whether this logger can be silenced or
|
78
|
+
# not.
|
79
|
+
attr_accessor :silencer
|
74
80
|
|
75
81
|
##
|
76
82
|
# This logger does not use a formatter, but it provides a default
|
@@ -144,13 +150,14 @@ module Google
|
|
144
150
|
@writer = writer
|
145
151
|
@log_name = log_name
|
146
152
|
@resource = resource
|
147
|
-
@labels = labels
|
153
|
+
@labels = labels || {}
|
148
154
|
@level = 0 # DEBUG is the default behavior
|
149
155
|
@request_info = {}
|
150
156
|
@closed = false
|
151
157
|
# Unused, but present for API compatibility
|
152
158
|
@formatter = ::Logger::Formatter.new
|
153
159
|
@datetime_format = ""
|
160
|
+
@silencer = true
|
154
161
|
|
155
162
|
# The writer is usually a Project or AsyncWriter.
|
156
163
|
logging = @writer.respond_to?(:logging) ? @writer.logging : @writer
|
@@ -169,9 +176,9 @@ module Google
|
|
169
176
|
#
|
170
177
|
def debug message = nil, &block
|
171
178
|
if block_given?
|
172
|
-
add
|
179
|
+
add ::Logger::DEBUG, nil, message, &block
|
173
180
|
else
|
174
|
-
add
|
181
|
+
add ::Logger::DEBUG, message
|
175
182
|
end
|
176
183
|
end
|
177
184
|
|
@@ -187,9 +194,9 @@ module Google
|
|
187
194
|
#
|
188
195
|
def info message = nil, &block
|
189
196
|
if block_given?
|
190
|
-
add
|
197
|
+
add ::Logger::INFO, nil, message, &block
|
191
198
|
else
|
192
|
-
add
|
199
|
+
add ::Logger::INFO, message
|
193
200
|
end
|
194
201
|
end
|
195
202
|
|
@@ -205,9 +212,9 @@ module Google
|
|
205
212
|
#
|
206
213
|
def warn message = nil, &block
|
207
214
|
if block_given?
|
208
|
-
add
|
215
|
+
add ::Logger::WARN, nil, message, &block
|
209
216
|
else
|
210
|
-
add
|
217
|
+
add ::Logger::WARN, message
|
211
218
|
end
|
212
219
|
end
|
213
220
|
|
@@ -223,9 +230,9 @@ module Google
|
|
223
230
|
#
|
224
231
|
def error message = nil, &block
|
225
232
|
if block_given?
|
226
|
-
add
|
233
|
+
add ::Logger::ERROR, nil, message, &block
|
227
234
|
else
|
228
|
-
add
|
235
|
+
add ::Logger::ERROR, message
|
229
236
|
end
|
230
237
|
end
|
231
238
|
|
@@ -241,9 +248,9 @@ module Google
|
|
241
248
|
#
|
242
249
|
def fatal message = nil, &block
|
243
250
|
if block_given?
|
244
|
-
add
|
251
|
+
add ::Logger::FATAL, nil, message, &block
|
245
252
|
else
|
246
|
-
add
|
253
|
+
add ::Logger::FATAL, message
|
247
254
|
end
|
248
255
|
end
|
249
256
|
|
@@ -260,9 +267,9 @@ module Google
|
|
260
267
|
#
|
261
268
|
def unknown message = nil, &block
|
262
269
|
if block_given?
|
263
|
-
add
|
270
|
+
add ::Logger::UNKNOWN, nil, message, &block
|
264
271
|
else
|
265
|
-
add
|
272
|
+
add ::Logger::UNKNOWN, message
|
266
273
|
end
|
267
274
|
end
|
268
275
|
|
@@ -281,7 +288,7 @@ module Google
|
|
281
288
|
# called when the logger is configured to show them.
|
282
289
|
#
|
283
290
|
def add severity, message = nil, progname = nil
|
284
|
-
severity = derive_severity(severity) ||
|
291
|
+
severity = derive_severity(severity) || ::Logger::UNKNOWN
|
285
292
|
return true if severity < @level
|
286
293
|
|
287
294
|
if message.nil?
|
@@ -312,35 +319,42 @@ module Google
|
|
312
319
|
# Returns `true` if the current severity level allows for sending
|
313
320
|
# `DEBUG` messages.
|
314
321
|
def debug?
|
315
|
-
@level <=
|
322
|
+
@level <= ::Logger::DEBUG
|
316
323
|
end
|
317
324
|
|
318
325
|
##
|
319
326
|
# Returns `true` if the current severity level allows for sending `INFO`
|
320
327
|
# messages.
|
321
328
|
def info?
|
322
|
-
@level <=
|
329
|
+
@level <= ::Logger::INFO
|
323
330
|
end
|
324
331
|
|
325
332
|
##
|
326
333
|
# Returns `true` if the current severity level allows for sending `WARN`
|
327
334
|
# messages.
|
328
335
|
def warn?
|
329
|
-
@level <=
|
336
|
+
@level <= ::Logger::WARN
|
330
337
|
end
|
331
338
|
|
332
339
|
##
|
333
340
|
# Returns `true` if the current severity level allows for sending
|
334
341
|
# `ERROR` messages.
|
335
342
|
def error?
|
336
|
-
@level <=
|
343
|
+
@level <= ::Logger::ERROR
|
337
344
|
end
|
338
345
|
|
339
346
|
##
|
340
347
|
# Returns `true` if the current severity level allows for sending
|
341
348
|
# `FATAL` messages.
|
342
349
|
def fatal?
|
343
|
-
@level <=
|
350
|
+
@level <= ::Logger::FATAL
|
351
|
+
end
|
352
|
+
|
353
|
+
##
|
354
|
+
# Returns `true` if the current severity level allows for sending
|
355
|
+
# `UNKNOWN` messages.
|
356
|
+
def unknown?
|
357
|
+
@level <= ::Logger::UNKNOWN
|
344
358
|
end
|
345
359
|
|
346
360
|
##
|
@@ -369,6 +383,7 @@ module Google
|
|
369
383
|
@level = new_level
|
370
384
|
end
|
371
385
|
alias_method :sev_threshold=, :level=
|
386
|
+
alias_method :local_level=, :level=
|
372
387
|
|
373
388
|
##
|
374
389
|
# Close the logging "device". This effectively disables logging from
|
@@ -452,6 +467,50 @@ module Google
|
|
452
467
|
# @deprecated Use delete_request_info
|
453
468
|
alias_method :delete_trace_id, :delete_request_info
|
454
469
|
|
470
|
+
##
|
471
|
+
# No-op method. Created to match the spec of ActiveSupport::Logger#flush
|
472
|
+
# method when used in Rails application.
|
473
|
+
def flush
|
474
|
+
self
|
475
|
+
end
|
476
|
+
|
477
|
+
##
|
478
|
+
# Filter out low severity messages within block.
|
479
|
+
#
|
480
|
+
# @param [Integer] temp_level Severity threshold to filter within the
|
481
|
+
# block. Messages with lower severity will be blocked. Default
|
482
|
+
# ::Logger::ERROR
|
483
|
+
#
|
484
|
+
# @example
|
485
|
+
# require "google/cloud/logging"
|
486
|
+
#
|
487
|
+
# logging = Google::Cloud::Logging.new
|
488
|
+
#
|
489
|
+
# resource = logging.resource "gae_app",
|
490
|
+
# module_id: "1",
|
491
|
+
# version_id: "20150925t173233"
|
492
|
+
#
|
493
|
+
# logger = logging.logger "my_app_log", resource, env: :production
|
494
|
+
#
|
495
|
+
# logger.silence do
|
496
|
+
# logger.info "Info message" # No log entry written
|
497
|
+
# logger.error "Error message" # Log entry written
|
498
|
+
# end
|
499
|
+
def silence temp_level = ::Logger::ERROR
|
500
|
+
if silencer
|
501
|
+
begin
|
502
|
+
old_level = level
|
503
|
+
self.level = temp_level
|
504
|
+
|
505
|
+
yield self
|
506
|
+
ensure
|
507
|
+
self.level = old_level
|
508
|
+
end
|
509
|
+
else
|
510
|
+
yield self
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
455
514
|
protected
|
456
515
|
|
457
516
|
##
|
@@ -490,7 +549,7 @@ module Google
|
|
490
549
|
end
|
491
550
|
end
|
492
551
|
|
493
|
-
labels.
|
552
|
+
labels.merge(merged_labels)
|
494
553
|
end
|
495
554
|
|
496
555
|
##
|
@@ -500,12 +559,12 @@ module Google
|
|
500
559
|
|
501
560
|
downcase_severity = severity.to_s.downcase
|
502
561
|
case downcase_severity
|
503
|
-
when "debug".freeze then
|
504
|
-
when "info".freeze then
|
505
|
-
when "warn".freeze then
|
506
|
-
when "error".freeze then
|
507
|
-
when "fatal".freeze then
|
508
|
-
when "unknown".freeze then
|
562
|
+
when "debug".freeze then ::Logger::DEBUG
|
563
|
+
when "info".freeze then ::Logger::INFO
|
564
|
+
when "warn".freeze then ::Logger::WARN
|
565
|
+
when "error".freeze then ::Logger::ERROR
|
566
|
+
when "fatal".freeze then ::Logger::FATAL
|
567
|
+
when "unknown".freeze then ::Logger::UNKNOWN
|
509
568
|
else nil
|
510
569
|
end
|
511
570
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '1.
|
34
|
+
version: '1.2'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.2'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: google-gax
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|