google-cloud-logging 1.4.0 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d899de8995824e5d52fb7ffba65090f37d604a54a3d136626477d46d768692c
4
- data.tar.gz: 709f297752a5d4c0fca09f13c4c6164eb7b621b59813603d901cd1616d93bbbb
3
+ metadata.gz: f630302c8714555f32d66a9a19a5da340c6bbd840b1a1ed9c7da1798b42254df
4
+ data.tar.gz: d0fb2056868a23c282082339be24ddd1aeca4c4ff9cc4659b1fd3091b5364596
5
5
  SHA512:
6
- metadata.gz: c4306cec1afeb1628d201bc1a109f9bd6f00296dceac7402e4c157347ae0b48ff5d0bd9beacc6961a2b3a7060d20025036ddeb1926b834780330d30e32788d51
7
- data.tar.gz: e1117dfeede218f6954a0ab15e0d0e50a08cab0cfee4b7c90c41060fcfe531957255649527335dd813220fe16a0c881cdb5239ea798b5dcf39a6b6df00de9390
6
+ metadata.gz: 484774d516102279b6197436dc1daee472eabd055d24f0d9e4a7460144aec2255cce2ad33bfa176b76713f5e252e72aa05014da53952587c15de9fc7e01688c0
7
+ data.tar.gz: 051e5a2e070aa2a2fbef148971fbf1d5e02d05c211720442682775591254803548a31745b359aee8a48be2eb4bd5a2d86671b6dc9ed150070fa550958e7181f3
data/README.md CHANGED
@@ -28,7 +28,7 @@ gem "google-cloud-logging"
28
28
  $ bundle install
29
29
  ```
30
30
 
31
- Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
31
+ Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
32
32
  the `google-cloud-logging` gem.
33
33
 
34
34
  ## Logging using client library
@@ -61,13 +61,13 @@ logging.write_entries entry
61
61
 
62
62
  ## Using Stackdriver Logging in frameworks
63
63
 
64
- The `google-cloud-logging` library provides framework integration for popular
65
- Rack-based frameworks, such as Ruby on Rails and Sinatra, which sets the default
64
+ The `google-cloud-logging` library provides framework integration for popular
65
+ Rack-based frameworks, such as Ruby on Rails and Sinatra, which sets the default
66
66
  Rack logger to an instance of the Stackdriver Logging logger.
67
67
 
68
68
  ### With Ruby on Rails
69
69
 
70
- You can load the Railtie that comes with the library into your Ruby
70
+ You can load the Railtie that comes with the library into your Ruby
71
71
  on Rails application by explicitly requiring it during the application startup:
72
72
 
73
73
  ```ruby
@@ -75,7 +75,7 @@ on Rails application by explicitly requiring it during the application startup:
75
75
  require "google/cloud/logging/rails"
76
76
  ```
77
77
 
78
- If you're using the `stackdriver` gem, it automatically loads the Railtie into
78
+ If you're using the `stackdriver` gem, it automatically loads the Railtie into
79
79
  your application when it starts.
80
80
 
81
81
  You'll be able to use Stackdriver logger through the standard Rails logger:
@@ -88,7 +88,7 @@ logger.warn "Hola Mundo"
88
88
 
89
89
  ### With other Rack-based frameworks
90
90
 
91
- Other Rack-based applications can use the Rack Middleware to replace the Rack
91
+ Other Rack-based applications can use the Rack Middleware to replace the Rack
92
92
  logger with the Stackdriver Logging logger:
93
93
 
94
94
  ```ruby
@@ -96,8 +96,8 @@ require "google/cloud/logging"
96
96
  use Google::Cloud::Logging::Middleware
97
97
  ```
98
98
 
99
- Once the Rack logger is set, some Rack-based frameworks, such as Ruby on Rails
100
- and Sinatra, automatically initialize the default application logger to use the
99
+ Once the Rack logger is set, some Rack-based frameworks, such as Ruby on Rails
100
+ and Sinatra, automatically initialize the default application logger to use the
101
101
  Rack logger:
102
102
 
103
103
  ```ruby
@@ -106,26 +106,26 @@ logger.warn "Hola Mundo"
106
106
  logger.error "Bonjour Monde"
107
107
  ```
108
108
 
109
- For other frameworks, consult the documentations on how to utilize the Rack
109
+ For other frameworks, consult the documentations on how to utilize the Rack
110
110
  logger.
111
111
 
112
112
  ### Configuring the framework integration
113
113
 
114
- You can customize the behavior of the Stackdriver Logging framework integration
115
- for Ruby. See the [configuration guide](../stackdriver/configuration.md) for a
114
+ You can customize the behavior of the Stackdriver Logging framework integration
115
+ for Ruby. See the [configuration guide](../stackdriver/configuration.md) for a
116
116
  list of possible configuration options.
117
117
 
118
118
  ## Authentication
119
119
 
120
- This library uses Service Account credentials to connect to Google Cloud
121
- services. When running on Compute Engine the credentials will be discovered
122
- automatically. When running on other environments the Service Account
120
+ This library uses Service Account credentials to connect to Google Cloud
121
+ services. When running on Compute Engine the credentials will be discovered
122
+ automatically. When running on other environments the Service Account
123
123
  credentials can be specified by providing in several ways.
124
124
 
125
- If you're using Ruby on Rails and the library's Rails integration feature, you
126
- can provide the authentication parameters through the Rails configuration
125
+ If you're using Ruby on Rails and the library's Rails integration feature, you
126
+ can provide the authentication parameters through the Rails configuration
127
127
  interface:
128
-
128
+
129
129
  ```ruby
130
130
  # Add this to config/environments/*.rb
131
131
  Rails.application.configure do |config|
@@ -137,7 +137,7 @@ Rails.application.configure do |config|
137
137
  config.google_cloud.logging.keyfile = "/path/to/key.json"
138
138
  end
139
139
  ```
140
- Other Rack-based applications that are loading the Rack Middleware directly can
140
+ Other Rack-based applications that are loading the Rack Middleware directly can
141
141
  use the configration interface:
142
142
 
143
143
  ```ruby
@@ -152,7 +152,7 @@ Google::Cloud.configure do |config|
152
152
  end
153
153
  ```
154
154
 
155
- See the [Authentication
155
+ See the [Authentication
156
156
  Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/guides/authentication).
157
157
  for more ways to authenticate the client library.
158
158
 
@@ -20,6 +20,8 @@
20
20
 
21
21
  gem "google-cloud-core"
22
22
  require "google/cloud"
23
+ require "google/cloud/config"
24
+ require "googleauth"
23
25
 
24
26
  module Google
25
27
  module Cloud
@@ -38,6 +40,7 @@ module Google
38
40
  # The default scope is:
39
41
  #
40
42
  # * `https://www.googleapis.com/auth/logging.admin`
43
+ #
41
44
  # @param [Integer] timeout Default timeout to use in requests. Optional.
42
45
  # @param [Hash] client_config A hash of values to override the default
43
46
  # behavior of the API client. Optional.
@@ -89,6 +92,7 @@ module Google
89
92
  # The default scope is:
90
93
  #
91
94
  # * `https://www.googleapis.com/auth/logging.admin`
95
+ #
92
96
  # @param [Integer] timeout Default timeout to use in requests. Optional.
93
97
  # @param [Hash] client_config A hash of values to override the default
94
98
  # behavior of the API client. Optional.
@@ -115,3 +119,40 @@ module Google
115
119
  end
116
120
  end
117
121
  end
122
+
123
+ # Add logging to top-level configuration
124
+ Google::Cloud.configure do |config|
125
+ unless config.field? :use_logging
126
+ config.add_field! :use_logging, nil, enum: [true, false]
127
+ end
128
+ end
129
+
130
+ # Set the default logging configuration
131
+ Google::Cloud.configure.add_config! :logging do |config|
132
+ default_project = Google::Cloud::Config.deferred do
133
+ ENV["LOGGING_PROJECT"]
134
+ end
135
+ default_creds = Google::Cloud::Config.deferred do
136
+ Google::Cloud::Config.credentials_from_env(
137
+ "LOGGING_CREDENTIALS", "LOGGING_CREDENTIALS_JSON",
138
+ "LOGGING_KEYFILE", "LOGGING_KEYFILE_JSON"
139
+ )
140
+ end
141
+
142
+ config.add_field! :project_id, default_project, match: String, allow_nil: true
143
+ config.add_alias! :project, :project_id
144
+ config.add_field! :credentials, default_creds,
145
+ match: [String, Hash, Google::Auth::Credentials],
146
+ allow_nil: true
147
+ config.add_alias! :keyfile, :credentials
148
+ config.add_field! :scope, nil, match: [String, Array]
149
+ config.add_field! :timeout, nil, match: Integer
150
+ config.add_field! :client_config, nil, match: Hash
151
+ config.add_field! :log_name, nil, match: String
152
+ config.add_field! :log_name_map, nil, match: Hash
153
+ config.add_field! :labels, nil, match: Hash
154
+ config.add_config! :monitored_resource do |mrconfig|
155
+ mrconfig.add_field! :type, nil, match: String
156
+ mrconfig.add_field! :labels, nil, match: Hash
157
+ end
158
+ end
@@ -15,6 +15,8 @@
15
15
 
16
16
  require "google-cloud-logging"
17
17
  require "google/cloud/logging/project"
18
+ require "google/cloud/config"
19
+ require "google/cloud/env"
18
20
  require "stackdriver/core"
19
21
 
20
22
  module Google
@@ -38,11 +40,12 @@ module Google
38
40
  # Logging Documentation](https://cloud.google.com/logging/docs/).
39
41
  #
40
42
  # The goal of google-cloud is to provide an API that is comfortable to
41
- # Rubyists. Authentication is handled by {Google::Cloud#logging}. You can
42
- # provide the project and credential information to connect to the
43
- # Stackdriver Logging service, or if you are running on Google Compute
44
- # Engine this configuration is taken care of for you. You can read more
45
- # about the options for connecting in the [Authentication
43
+ # Rubyists. Your authentication credentials are detected automatically in
44
+ # Google Cloud Platform environments such as Google Compute Engine, Google
45
+ # App Engine and Google Kubernetes Engine. In other environments you can
46
+ # configure authentication easily, either directly in your code or via
47
+ # environment variables. Read more about the options for connecting in the
48
+ # [Authentication
46
49
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
47
50
  #
48
51
  # If you just want to write your application's logs to the Stackdriver
@@ -347,12 +350,6 @@ module Google
347
350
  # ```
348
351
  #
349
352
  module Logging
350
- # Initialize :error_reporting as a nested Configuration under
351
- # Google::Cloud if haven't already
352
- unless Google::Cloud.configure.option? :logging
353
- Google::Cloud.configure.add_options logging: :monitored_resource
354
- end
355
-
356
353
  ##
357
354
  # Creates a new object for connecting to the Stackdriver Logging service.
358
355
  # Each call creates a new connection.
@@ -375,6 +372,7 @@ module Google
375
372
  # The default scope is:
376
373
  #
377
374
  # * `https://www.googleapis.com/auth/logging.admin`
375
+ #
378
376
  # @param [Integer] timeout Default timeout to use in requests. Optional.
379
377
  # @param [Hash] client_config A hash of values to override the default
380
378
  # behavior of the API client. Optional.
@@ -396,11 +394,15 @@ module Google
396
394
  #
397
395
  def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
398
396
  client_config: nil, project: nil, keyfile: nil
399
- project_id ||= (project || Logging::Project.default_project_id)
397
+ project_id ||= (project || default_project_id)
400
398
  project_id = project_id.to_s # Always cast to a string
401
- fail ArgumentError, "project_id is missing" if project_id.empty?
399
+ raise ArgumentError, "project_id is missing" if project_id.empty?
400
+
401
+ scope ||= configure.scope
402
+ timeout ||= configure.timeout
403
+ client_config ||= configure.client_config
402
404
 
403
- credentials ||= (keyfile || Logging::Credentials.default(scope: scope))
405
+ credentials ||= (keyfile || default_credentials(scope: scope))
404
406
  unless credentials.is_a? Google::Auth::Credentials
405
407
  credentials = Logging::Credentials.new credentials, scope: scope
406
408
  end
@@ -408,18 +410,49 @@ module Google
408
410
  Logging::Project.new(
409
411
  Logging::Service.new(
410
412
  project_id, credentials, timeout: timeout,
411
- client_config: client_config))
413
+ client_config: client_config
414
+ )
415
+ )
412
416
  end
413
417
 
414
418
  ##
415
419
  # Configure the Google::Cloud::Logging::Middleware when used in a
416
420
  # Rack-based application.
417
421
  #
422
+ # The following Stackdriver Logging configuration parameters are
423
+ # supported:
424
+ #
425
+ # * `project_id` - (String) Project identifier for the Stackdriver
426
+ # Logging service you are connecting to. (The parameter `project` is
427
+ # considered deprecated, but may also be used.)
428
+ # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
429
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
430
+ # Google::Auth::Credentials object. (See {Logging::Credentials}) (The
431
+ # parameter `keyfile` is considered deprecated, but may also be used.)
432
+ # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
433
+ # the set of resources and operations that the connection can access.
434
+ # * `timeout` - (Integer) Default timeout to use in requests.
435
+ # * `client_config` - (Hash) A hash of values to override the default
436
+ # behavior of the API client.
437
+ # * `log_name` - (String) Name of the application log file. Default:
438
+ # `"ruby_app_log"`
439
+ # * `log_name_map` - (Hash) Map specific request routes to other log.
440
+ # Default: `{ "/_ah/health" => "ruby_health_check_log" }`
441
+ # * `monitored_resource.type` (String) Resource type name. See [full
442
+ # list](https://cloud.google.com/logging/docs/api/v2/resource-list).
443
+ # Self discovered on GCP.
444
+ # * `monitored_resource.labels` -(Hash) Resource labels. See [full
445
+ # list](https://cloud.google.com/logging/docs/api/v2/resource-list).
446
+ # Self discovered on GCP.
447
+ # * `labels` - (Hash) User defined labels. A `Hash` of label names to
448
+ # string label values or callables/`Proc` which are functions of the
449
+ # Rack environment.
450
+ #
418
451
  # See the [Configuration
419
452
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/stackdriver/guides/instrumentation_configuration)
420
453
  # for full configuration parameters.
421
454
  #
422
- # @return [Stackdriver::Core::Configuration] The configuration object
455
+ # @return [Google::Cloud::Config] The configuration object
423
456
  # the Google::Cloud::Logging module uses.
424
457
  #
425
458
  def self.configure
@@ -427,6 +460,22 @@ module Google
427
460
 
428
461
  Google::Cloud.configure.logging
429
462
  end
463
+
464
+ ##
465
+ # @private Default project.
466
+ def self.default_project_id
467
+ Google::Cloud.configure.logging.project_id ||
468
+ Google::Cloud.configure.project_id ||
469
+ Google::Cloud.env.project_id
470
+ end
471
+
472
+ ##
473
+ # @private Default credentials.
474
+ def self.default_credentials scope: nil
475
+ Google::Cloud.configure.logging.credentials ||
476
+ Google::Cloud.configure.credentials ||
477
+ Logging::Credentials.default(scope: scope)
478
+ end
430
479
  end
431
480
  end
432
481
  end
@@ -87,7 +87,7 @@ module Google
87
87
  # The current state. Either :running, :suspended, :stopping, or :stopped
88
88
  #
89
89
  # DEPRECATED. Use #async_state instead.
90
- alias_method :state, :async_state
90
+ alias state async_state
91
91
 
92
92
  ##
93
93
  # The last exception thrown by the background thread, or nil if nothing
@@ -152,7 +152,7 @@ module Google
152
152
  ensure_thread
153
153
  entries = Array(entries)
154
154
  synchronize do
155
- fail "AsyncWriter has been stopped" unless writable?
155
+ raise "AsyncWriter has been stopped" unless writable?
156
156
  queue_item = QueueItem.new entries, log_name, resource, labels
157
157
  if @queue.empty? || !@queue.last.try_combine(queue_item)
158
158
  @queue.push queue_item
@@ -213,7 +213,7 @@ module Google
213
213
  # @return [Boolean] Returns true if the writer was running, or false
214
214
  # if the writer had already been stopped.
215
215
  #
216
- alias_method :stop, :async_stop
216
+ alias stop async_stop
217
217
 
218
218
  ##
219
219
  # Suspends this asynchronous writer.
@@ -226,7 +226,7 @@ module Google
226
226
  # @return [Boolean] Returns true if the writer had been running and was
227
227
  # suspended, otherwise false.
228
228
  #
229
- alias_method :suspend, :async_suspend
229
+ alias suspend async_suspend
230
230
 
231
231
  ##
232
232
  # Resumes this suspended asynchronous writer.
@@ -239,7 +239,7 @@ module Google
239
239
  # @return [Boolean] Returns true if the writer had been suspended and
240
240
  # is now running, otherwise false.
241
241
  #
242
- alias_method :resume, :async_resume
242
+ alias resume async_resume
243
243
 
244
244
  ##
245
245
  # Returns true if this writer is running.
@@ -248,7 +248,7 @@ module Google
248
248
  #
249
249
  # @return [Boolean] Returns true if the writer is currently running.
250
250
  #
251
- alias_method :running?, :async_running?
251
+ alias running? async_running?
252
252
 
253
253
  ##
254
254
  # Returns true if this writer is suspended.
@@ -257,7 +257,7 @@ module Google
257
257
  #
258
258
  # @return [Boolean] Returns true if the writer is currently suspended.
259
259
  #
260
- alias_method :suspended?, :async_suspended?
260
+ alias suspended? async_suspended?
261
261
 
262
262
  ##
263
263
  # Returns true if this writer is still accepting writes. This means
@@ -267,7 +267,7 @@ module Google
267
267
  #
268
268
  # @return [Boolean] Returns true if the writer is accepting writes.
269
269
  #
270
- alias_method :writable?, :async_working?
270
+ alias writable? async_working?
271
271
 
272
272
  ##
273
273
  # Returns true if this writer is fully stopped.
@@ -276,7 +276,7 @@ module Google
276
276
  #
277
277
  # @return [Boolean] Returns true if the writer is fully stopped.
278
278
  #
279
- alias_method :stopped?, :async_stopped?
279
+ alias stopped? async_stopped?
280
280
 
281
281
  ##
282
282
  # Blocks until this asynchronous writer has been stopped, or the given
@@ -290,7 +290,7 @@ module Google
290
290
  # @return [Boolean] Returns true if the writer is stopped, or false
291
291
  # if the timeout expired.
292
292
  #
293
- alias_method :wait_until_stopped, :wait_until_async_stopped
293
+ alias wait_until_stopped wait_until_async_stopped
294
294
 
295
295
  ##
296
296
  # Stop this asynchronous writer and block until it has been stopped.
@@ -340,7 +340,7 @@ module Google
340
340
  labels: queue_item.labels,
341
341
  partial_success: @partial_success
342
342
  )
343
- rescue => e
343
+ rescue StandardError => e
344
344
  # Ignore any exceptions thrown from the background thread, but
345
345
  # keep running to ensure its state behavior remains consistent.
346
346
  @last_exception = e
@@ -38,19 +38,19 @@ module Google
38
38
  # logging.project_id #=> "my-project"
39
39
  #
40
40
  class Credentials < Google::Auth::Credentials
41
- SCOPE = ["https://www.googleapis.com/auth/logging.admin"]
42
- PATH_ENV_VARS = %w(LOGGING_CREDENTIALS
41
+ SCOPE = ["https://www.googleapis.com/auth/logging.admin"].freeze
42
+ PATH_ENV_VARS = %w[LOGGING_CREDENTIALS
43
43
  LOGGING_KEYFILE
44
44
  GOOGLE_CLOUD_CREDENTIALS
45
45
  GOOGLE_CLOUD_KEYFILE
46
- GCLOUD_KEYFILE)
47
- JSON_ENV_VARS = %w(LOGGING_CREDENTIALS_JSON
46
+ GCLOUD_KEYFILE].freeze
47
+ JSON_ENV_VARS = %w[LOGGING_CREDENTIALS_JSON
48
48
  LOGGING_KEYFILE_JSON
49
49
  GOOGLE_CLOUD_CREDENTIALS_JSON
50
50
  GOOGLE_CLOUD_KEYFILE_JSON
51
- GCLOUD_KEYFILE_JSON)
51
+ GCLOUD_KEYFILE_JSON].freeze
52
52
  DEFAULT_PATHS = \
53
- ["~/.config/gcloud/application_default_credentials.json"]
53
+ ["~/.config/gcloud/application_default_credentials.json"].freeze
54
54
  end
55
55
  end
56
56
  end
@@ -27,8 +27,7 @@ module Google
27
27
  class HttpRequest
28
28
  ##
29
29
  # @private Create an empty HttpRequest object.
30
- def initialize
31
- end
30
+ def initialize; end
32
31
 
33
32
  ##
34
33
  # The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.