google-cloud-logging 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8b7a06296878a5094bc4de7d45d87b988297de5cec70e212c17b55639f07485
4
- data.tar.gz: '090cc3fe558e01f326240b6c7ba23cc9607e480454f39be71ec0da9844cefa0e'
3
+ metadata.gz: c186c4f38de2474a1a806259d215e3613ccea28d09011b3ad7b9c08421aae52f
4
+ data.tar.gz: d17ddc92fd9783853bb4efb7edba4be0aaa6bea9f45bb8d04147a17f6f8c191e
5
5
  SHA512:
6
- metadata.gz: fda5da167d780b2ad5dd119037291730e935927b57da558266168db82f587665608fc0e1df14b983dd8f87ac0d217b790a810ab037edaba2497b7558bdd19305
7
- data.tar.gz: bb7324f057ca44e027fcaf532360b66e5ec25a377ff32ae20f88accae7f0b2097117f61c626d966dac18e67998b9fe95ef8a55f8fe817a38fa248e842c17fa03
6
+ metadata.gz: 5e8c71b129fa26d8f3061fee8e7f66dca3942467cf844f650d47322f586d18c9a381251f7afd05767f22b87b81538182a8ae6cc82aa4003e98e0e7feee7d8ca6
7
+ data.tar.gz: e13b593778894c9df313fb513ef9c16496961243342ac36523a12d98192fc65a82c5bfa740e5ec597d304805cf829eb39452f386d1900d0a30ee28e813aa60a8
@@ -0,0 +1,179 @@
1
+ # Authentication
2
+
3
+ In general, the google-cloud-logging library uses [Service
4
+ Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
5
+ credentials to connect to Google Cloud services. When running on Compute Engine
6
+ the credentials will be discovered automatically. When running on other
7
+ environments, the Service Account credentials can be specified by providing the
8
+ path to the [JSON
9
+ keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
10
+ the account (or the JSON itself) in environment variables. Additionally, Cloud
11
+ SDK credentials can also be discovered automatically, but this is only
12
+ recommended during development.
13
+
14
+ ## Project and Credential Lookup
15
+
16
+ The google-cloud-logging library aims to make authentication as simple as
17
+ possible, and provides several mechanisms to configure your system without
18
+ providing **Project ID** and **Service Account Credentials** directly in code.
19
+
20
+ **Project ID** is discovered in the following order:
21
+
22
+ 1. Specify project ID in method arguments
23
+ 2. Specify project ID in configuration
24
+ 3. Discover project ID in environment variables
25
+ 4. Discover GCE project ID
26
+
27
+ **Credentials** are discovered in the following order:
28
+
29
+ 1. Specify credentials in method arguments
30
+ 2. Specify credentials in configuration
31
+ 3. Discover credentials path in environment variables
32
+ 4. Discover credentials JSON in environment variables
33
+ 5. Discover credentials file in the Cloud SDK's path
34
+ 6. Discover GCE credentials
35
+
36
+ ### Google Cloud Platform environments
37
+
38
+ While running on Google Cloud Platform environments such as Google Compute
39
+ Engine, Google App Engine and Google Kubernetes Engine, no extra work is needed.
40
+ The **Project ID** and **Credentials** and are discovered automatically. Code
41
+ should be written as if already authenticated. Just be sure when you [set up the
42
+ GCE instance][gce-how-to], you add the correct scopes for the APIs you want to
43
+ access. For example:
44
+
45
+ * **All APIs**
46
+ * `https://www.googleapis.com/auth/cloud-platform`
47
+ * `https://www.googleapis.com/auth/cloud-platform.read-only`
48
+ * **BigQuery**
49
+ * `https://www.googleapis.com/auth/bigquery`
50
+ * `https://www.googleapis.com/auth/bigquery.insertdata`
51
+ * **Compute Engine**
52
+ * `https://www.googleapis.com/auth/compute`
53
+ * **Datastore**
54
+ * `https://www.googleapis.com/auth/datastore`
55
+ * `https://www.googleapis.com/auth/userinfo.email`
56
+ * **DNS**
57
+ * `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
58
+ * **Pub/Sub**
59
+ * `https://www.googleapis.com/auth/pubsub`
60
+ * **Storage**
61
+ * `https://www.googleapis.com/auth/devstorage.full_control`
62
+ * `https://www.googleapis.com/auth/devstorage.read_only`
63
+ * `https://www.googleapis.com/auth/devstorage.read_write`
64
+
65
+ ### Environment Variables
66
+
67
+ The **Project ID** and **Credentials JSON** can be placed in environment
68
+ variables instead of declaring them directly in code. Each service has its own
69
+ environment variable, allowing for different service accounts to be used for
70
+ different services. (See the READMEs for the individual service gems for
71
+ details.) The path to the **Credentials JSON** file can be stored in the
72
+ environment variable, or the **Credentials JSON** itself can be stored for
73
+ environments such as Docker containers where writing files is difficult or not
74
+ encouraged.
75
+
76
+ The environment variables that Logging checks for project ID are:
77
+
78
+ 1. `LOGGING_PROJECT`
79
+ 2. `GOOGLE_CLOUD_PROJECT`
80
+
81
+ The environment variables that Logging checks for credentials are configured on
82
+ {Google::Cloud::Logging::V2::Credentials}:
83
+
84
+ 1. `LOGGING_CREDENTIALS` - Path to JSON file, or JSON contents
85
+ 2. `LOGGING_KEYFILE` - Path to JSON file, or JSON contents
86
+ 3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
87
+ 4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
88
+ 5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
89
+
90
+ ```ruby
91
+ require "google/cloud/logging"
92
+
93
+ ENV["LOGGING_PROJECT"] = "my-project-id"
94
+ ENV["LOGGING_CREDENTIALS"] = "path/to/keyfile.json"
95
+
96
+ logging = Google::Cloud::Logging.new
97
+ ```
98
+
99
+ ### Configuration
100
+
101
+ The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
102
+
103
+ ```ruby
104
+ require "google/cloud/logging"
105
+
106
+ Google::Cloud::Logging.configure do |config|
107
+ config.project_id = "my-project-id"
108
+ config.credentials = "path/to/keyfile.json"
109
+ end
110
+
111
+ logging = Google::Cloud::Logging.new
112
+ ```
113
+
114
+ ### Cloud SDK
115
+
116
+ This option allows for an easy way to authenticate during development. If
117
+ credentials are not provided in code or in environment variables, then Cloud SDK
118
+ credentials are discovered.
119
+
120
+ To configure your system for this, simply:
121
+
122
+ 1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
123
+ 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
124
+ 3. Write code as if already authenticated.
125
+
126
+ **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
127
+ *should* only be used during development.
128
+
129
+ [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
130
+ [dev-console]: https://console.cloud.google.com/project
131
+
132
+ [enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
133
+
134
+ [create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
135
+ [create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
136
+ [reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
137
+
138
+ ## Creating a Service Account
139
+
140
+ Google Cloud requires a **Project ID** and **Service Account Credentials** to
141
+ connect to the APIs. You will use the **Project ID** and **JSON key file** to
142
+ connect to most services with google-cloud-logging.
143
+
144
+ If you are not running this client on Google Compute Engine, you need a Google
145
+ Developers service account.
146
+
147
+ 1. Visit the [Google Developers Console][dev-console].
148
+ 1. Create a new project or click on an existing project.
149
+ 1. Activate the slide-out navigation tray and select **API Manager**. From
150
+ here, you will enable the APIs that your application requires.
151
+
152
+ ![Enable the APIs that your application requires][enable-apis]
153
+
154
+ *Note: You may need to enable billing in order to use these services.*
155
+
156
+ 1. Select **Credentials** from the side navigation.
157
+
158
+ You should see a screen like one of the following.
159
+
160
+ ![Create a new service account][create-new-service-account]
161
+
162
+ ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
163
+
164
+ Find the "Add credentials" drop down and select "Service account" to be
165
+ guided through downloading a new JSON key file.
166
+
167
+ If you want to re-use an existing service account, you can easily generate a
168
+ new key file. Just select the account you wish to re-use, and click "Generate
169
+ new JSON key":
170
+
171
+ ![Re-use an existing service account][reuse-service-account]
172
+
173
+ The key file you download will be used by this library to authenticate API
174
+ requests and should be stored in a secure location.
175
+
176
+ ## Troubleshooting
177
+
178
+ If you're having trouble authenticating you can ask for help by following the
179
+ {file:TROUBLESHOOTING.md Troubleshooting Guide}.
@@ -0,0 +1,153 @@
1
+ # Release History
2
+
3
+ ### 1.5.4 / 2018-09-12
4
+
5
+ * Add missing documentation files to package.
6
+
7
+ ### 1.5.3 / 2018-09-10
8
+
9
+ * Update documentation.
10
+
11
+ ### 1.5.2 / 2018-08-21
12
+
13
+ * Update documentation.
14
+
15
+ ### 1.5.1 / 2018-07-05
16
+
17
+ * Fix bug in List classes by propagating arguments needed for pagination calls.
18
+ * Fix issue when disabling Stackdriver components with Rails.env.production.
19
+ * Reduce string memory usage.
20
+ * Add documentation for enabling gRPC logging.
21
+
22
+ ### 1.5.0 / 2018-02-27
23
+
24
+ * Use Google Cloud Shared Configuration.
25
+ * Deprecated Logging Sink attributes.
26
+
27
+ ### 1.4.0 / 2017-12-19
28
+
29
+ * Update google-gax dependency to 1.0.
30
+
31
+ ### 1.3.2 / 2017-11-20
32
+
33
+ * Refresh GAPIC layer (low-level API) based on updates to Protobuf types.
34
+
35
+ ### 1.3.1 / 2017-11-15
36
+
37
+ * Fix credentials verification bug in Railtie.
38
+
39
+ ### 1.3.0 / 2017-11-14
40
+
41
+ * Add `Google::Cloud::Logging::Credentials` class.
42
+ * Rename constructor arguments to `project_id` and `credentials`.
43
+ (The previous arguments `project` and `keyfile` are still supported.)
44
+ * Document `Google::Auth::Credentials` as `credentials` value.
45
+ * Add `partial_success` optional argument to `Project#write_entries`.
46
+ * Deprecate `HttpRequest#method`, use `HttpRequest#request_method` instead.
47
+ * Update generated low level GAPIC code.
48
+ * Updated `google-gax` (`grpc`, `google-protobuf`), `googleauth` dependencies.
49
+
50
+ ### 1.2.3 / 2017-09-27
51
+
52
+ * Updated protobuf classes.
53
+ * Updated README.
54
+
55
+ ### 1.2.2 / 2017-09-08
56
+
57
+ * Add `labels` configuration option to `Google::Cloud::Logging::Middleware` for Rails and other Rack-based framework integrations.
58
+
59
+ ### 1.2.1 / 2017-07-11
60
+
61
+ * stackdriver-core 1.2.0 release
62
+
63
+ ### 1.2.0 / 2017-07-11
64
+
65
+ * Update `labels` parameter in `Google::Cloud::Logging::Logger#initialize` to default to empty hash.
66
+ * Update `Google::Cloud::Logging::Logger` to support the following `ActiveSupport::Logger` methods: `:local_level`, `:local_level=`, `:silence`, `:silencer`, and `:unknown?`.
67
+ * Update GAPIC configuration to exclude `UNAVAILABLE` errors from automatic retry.
68
+ * Update gem spec homepage links.
69
+
70
+ ### 1.1.0 / 2017-05-25
71
+
72
+ * Introduce new `Google::Cloud::Logging.configure` instrumentation configuration interface.
73
+ * Google::Cloud::Logger now sends extra trace context information in log entries.
74
+
75
+ ### 1.0.1 / 2017-04-21
76
+
77
+ * Middleware constructor can be called without an explicit logger. This should make integration in non-Rails applications simpler.
78
+ * If Rails integration fails due to an auth error, the notice is now printed to STDOUT rather than STDERR, which should make it a bit less scary when displayed in Docker output.
79
+
80
+ ### 1.0.0 / 2017-03-31
81
+
82
+ * Release 1.0
83
+ * Added `#trace` and `#source_location` to Entry
84
+ * Added listing of logs for the project
85
+ * Updated documentation
86
+ * Automatic retry on `UNAVAILABLE` errors
87
+
88
+ ### 0.24.2 / 2017-03-03
89
+
90
+ * No public API changes.
91
+ * Update GRPC header value sent to the Logging API.
92
+
93
+ ### 0.24.1 / 2017-03-01
94
+
95
+ * No public API changes.
96
+ * Update GRPC header value sent to the Logging API.
97
+ * Low level API adds new Protobuf types and GAPIC methods.
98
+
99
+ ### 0.24.0 / 2017-02-21
100
+
101
+ * Fix GRPC retry bug
102
+ * The client_config data structure has replaced retry_codes/retry_codes_def with retry_codes
103
+ * Update GRPC/Protobuf/GAX dependencies
104
+
105
+ ### 0.23.2 / 2016-12-27
106
+
107
+ * `Google::Cloud::Logging::Logger` depended on standard logger but didn't require it. Fixed.
108
+
109
+ ### 0.23.1 / 2016-12-22
110
+
111
+ * Use the `stackdriver-core` gem to obtain Trace ID, for compatibility with the `google-cloud-trace` gem.
112
+ * `Google::Cloud::Logging::Logger` now understands all remaining standard Logger methods.
113
+ * Clean up `AsyncWriter` threads on VM exit, to prevent gRPC from crashing if it's still in the middle of a call.
114
+ * Support setting log name by path, and direct App Engine health checks to a separate log by default.
115
+ * Minor improvements to warning messages.
116
+
117
+ ### 0.23.0 / 2016-12-8
118
+
119
+ * Add `resources` method argument to `Project#entries`
120
+ * Deprecate `projects` method argument from `Project#entries`
121
+ * Add `start_at`, `end_at`, and `writer_identity` attributes to `Sink`
122
+ * Add `start_at`, `end_at`, and `unique_writer_identity` parameters to `Project#create_sink`
123
+ * Add `unique_writer_identity` parameter to `Sink#save`
124
+ * Many documentation improvements
125
+ * Add documentation for Low Level API
126
+
127
+ ### 0.21.2 / 2016-11-15
128
+
129
+ * Fix issue with uninitialized VERSION (remi)
130
+
131
+ ### 0.21.1 / 2016-11-4
132
+
133
+ * Upgraded Google::Cloud::Logging::Railtie to use AsyncWriter
134
+ * Added Rails configuration for custom monitored resource
135
+
136
+ ### 0.21.0 / 2016-10-20
137
+
138
+ * New service constructor Google::Cloud::Logging.new
139
+ * New constructor argument client_config
140
+ * Logger is now asynchronous
141
+ * AsyncWriter added
142
+ * Rails and Rack integration added
143
+
144
+ ### 0.20.1 / 2016-09-02
145
+
146
+ * Fix an issue with the GRPC client and forked sub-processes
147
+
148
+ ### 0.20.0 / 2016-08-26
149
+
150
+ This gem contains the Stackdriver Logging service implementation for the `google-cloud` gem. The `google-cloud` gem replaces the old `gcloud` gem. Legacy code can continue to use the `gcloud` gem.
151
+
152
+ * Namespace is now `Google::Cloud`
153
+ * The `google-cloud` gem is now an umbrella package for individual gems
@@ -0,0 +1,40 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct.
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or reject
24
+ comments, commits, code, wiki edits, issues, and other contributions that are
25
+ not aligned to this Code of Conduct. By adopting this Code of Conduct, project
26
+ maintainers commit themselves to fairly and consistently applying these
27
+ principles to every aspect of managing this project. Project maintainers who do
28
+ not follow or enforce the Code of Conduct may be permanently removed from the
29
+ project team.
30
+
31
+ This code of conduct applies both within project spaces and in public spaces
32
+ when an individual is representing the project or its community.
33
+
34
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
+ reported by opening an issue or contacting one or more of the project
36
+ maintainers.
37
+
38
+ This Code of Conduct is adapted from the [Contributor
39
+ Covenant](http://contributor-covenant.org), version 1.2.0, available at
40
+ [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
@@ -0,0 +1,188 @@
1
+ # Contributing to Google Cloud Logging
2
+
3
+ 1. **Sign one of the contributor license agreements below.**
4
+ 2. Fork the repo, develop and test your code changes.
5
+ 3. Send a pull request.
6
+
7
+ ## Contributor License Agreements
8
+
9
+ Before we can accept your pull requests you'll need to sign a Contributor
10
+ License Agreement (CLA):
11
+
12
+ - **If you are an individual writing original source code** and **you own the
13
+ intellectual property**, then you'll need to sign an [individual
14
+ CLA](https://developers.google.com/open-source/cla/individual).
15
+ - **If you work for a company that wants to allow you to contribute your work**,
16
+ then you'll need to sign a [corporate
17
+ CLA](https://developers.google.com/open-source/cla/corporate).
18
+
19
+ You can sign these electronically (just scroll to the bottom). After that, we'll
20
+ be able to accept your pull requests.
21
+
22
+ ## Setup
23
+
24
+ In order to use the google-cloud-logging console and run the project's tests,
25
+ there is a small amount of setup:
26
+
27
+ 1. Install Ruby. google-cloud-logging requires Ruby 2.3+. You may choose to
28
+ manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
+ [rbenv](https://github.com/rbenv/rbenv), or
30
+ [chruby](https://github.com/postmodern/chruby).
31
+
32
+ 2. Install [Bundler](http://bundler.io/).
33
+
34
+ ```sh
35
+ $ gem install bundler
36
+ ```
37
+
38
+ 3. Install the top-level project dependencies.
39
+
40
+ ```sh
41
+ $ bundle install
42
+ ```
43
+
44
+ 4. Install the Logging dependencies.
45
+
46
+ ```sh
47
+ $ cd google-cloud-logging/
48
+ $ bundle exec rake bundleupdate
49
+ ```
50
+
51
+ ## Console
52
+
53
+ In order to run code interactively, you can automatically load
54
+ google-cloud-logging and its dependencies in IRB. This requires that your
55
+ developer environment has already been configured by following the steps
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
+ can be created with:
58
+
59
+ ```sh
60
+ $ cd google-cloud-logging/
61
+ $ bundle exec rake console
62
+ ```
63
+
64
+ ## Logging Tests
65
+
66
+ Tests are very important part of google-cloud-logging. All contributions
67
+ should include tests that ensure the contributed code behaves as expected.
68
+
69
+ To run the unit tests, documentation tests, and code style checks together for a
70
+ package:
71
+
72
+ ``` sh
73
+ $ cd google-cloud-logging/
74
+ $ bundle exec rake ci
75
+ ```
76
+
77
+ To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
78
+ its handy alias, `rake ci:a`.
79
+
80
+ ### Logging Unit Tests
81
+
82
+
83
+ The project uses the [minitest](https://github.com/seattlerb/minitest) library,
84
+ including [specs](https://github.com/seattlerb/minitest#specs),
85
+ [mocks](https://github.com/seattlerb/minitest#mocks) and
86
+ [minitest-autotest](https://github.com/seattlerb/minitest-autotest).
87
+
88
+ To run the Logging unit tests:
89
+
90
+ ``` sh
91
+ $ cd google-cloud-logging/
92
+ $ bundle exec rake test
93
+ ```
94
+
95
+ ### Logging Documentation Tests
96
+
97
+ The project tests the code examples in the gem's
98
+ [YARD](https://github.com/lsegal/yard)-based documentation.
99
+
100
+ The example testing functions in a way that is very similar to unit testing, and
101
+ in fact the library providing it,
102
+ [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
103
+ project's unit test library, [minitest](https://github.com/seattlerb/minitest).
104
+
105
+ To run the Logging documentation tests:
106
+
107
+ ``` sh
108
+ $ cd google-cloud-logging/
109
+ $ bundle exec rake doctest
110
+ ```
111
+
112
+ If you add, remove or modify documentation examples when working on a pull
113
+ request, you may need to update the setup for the tests. The stubs and mocks
114
+ required to run the tests are located in `support/doctest_helper.rb`. Please
115
+ note that much of the setup is matched by the title of the
116
+ [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
117
+ If you alter an example's title, you may encounter breaking tests.
118
+
119
+ ### Logging Acceptance Tests
120
+
121
+ The Logging acceptance tests interact with the live service API. Follow the
122
+ instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
123
+ the Logging API. Occasionally, some API features may not yet be generally
124
+ available, making it difficult for some contributors to successfully run the
125
+ entire acceptance test suite. However, please ensure that you do successfully
126
+ run acceptance tests for any code areas covered by your pull request.
127
+
128
+ To run the acceptance tests, first create and configure a project in the Google
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
+ guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
+ the KEYFILE location on your system.
132
+
133
+ Before you can run the Logging acceptance tests, you must first create indexes
134
+ used in the tests.
135
+
136
+ #### Running the Logging acceptance tests
137
+
138
+ To run the Logging acceptance tests:
139
+
140
+ ``` sh
141
+ $ cd google-cloud-logging/
142
+ $ bundle exec rake acceptance[\\{my-project-id},\\{/path/to/keyfile.json}]
143
+ ```
144
+
145
+ Or, if you prefer you can store the values in the `GCLOUD_TEST_PROJECT` and
146
+ `GCLOUD_TEST_KEYFILE` environment variables:
147
+
148
+ ``` sh
149
+ $ cd google-cloud-logging/
150
+ $ export GCLOUD_TEST_PROJECT=\\{my-project-id}
151
+ $ export GCLOUD_TEST_KEYFILE=\\{/path/to/keyfile.json}
152
+ $ bundle exec rake acceptance
153
+ ```
154
+
155
+ If you want to use a different project and credentials for acceptance tests, you
156
+ can use the more specific `LOGGING_TEST_PROJECT` and `LOGGING_TEST_KEYFILE`
157
+ environment variables:
158
+
159
+ ``` sh
160
+ $ cd google-cloud-logging/
161
+ $ export LOGGING_TEST_PROJECT=\\{my-project-id}
162
+ $ export LOGGING_TEST_KEYFILE=\\{/path/to/keyfile.json}
163
+ $ bundle exec rake acceptance
164
+ ```
165
+
166
+ ## Coding Style
167
+
168
+ Please follow the established coding style in the library. The style is is
169
+ largely based on [The Ruby Style
170
+ Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
171
+ on seattle-style:
172
+
173
+ * Avoid parenthesis when possible, including in method definitions.
174
+ * Always use double quotes strings. ([Option
175
+ B](https://github.com/bbatsov/ruby-style-guide#strings))
176
+
177
+ You can check your code against these rules by running Rubocop like so:
178
+
179
+ ```sh
180
+ $ cd google-cloud-logging/
181
+ $ bundle exec rake rubocop
182
+ ```
183
+
184
+ ## Code of Conduct
185
+
186
+ Please note that this project is released with a Contributor Code of Conduct. By
187
+ participating in this project you agree to abide by its terms. See
188
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
@@ -0,0 +1,71 @@
1
+ # Stackdriver Logging Instrumentation
2
+
3
+ Then google-cloud-logging gem provides a Rack Middleware class that can easily
4
+ integrate with Rack based application frameworks, such as Rails and Sinatra.
5
+ When enabled, it sets an instance of Google::Cloud::Logging::Logger as the
6
+ default Rack or Rails logger. Then all consequent log entries will be submitted
7
+ to the Stackdriver Logging service.
8
+
9
+ On top of that, the google-cloud-logging also implements a Railtie class that
10
+ automatically enables the Rack Middleware in Rails applications when used.
11
+
12
+ ## Configuration
13
+ The default configuration enables Stackdriver instrumentation features to run
14
+ on Google Cloud Platform. You can easily configure the instrumentation library
15
+ if you want to run on a non Google Cloud environment or you want to customize
16
+ the default behavior.
17
+
18
+ See the
19
+ [Configuration Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/stackdriver/guides/instrumentation_configuration)
20
+ for full configuration parameters.
21
+
22
+ ## Using instrumentation with Ruby on Rails
23
+
24
+ To install application instrumentation in your Ruby on Rails app, add this
25
+ gem, `google-cloud-logging`, to your Gemfile and update your bundle. Then
26
+ add the following line to your `config/application.rb` file:
27
+ ```ruby
28
+ require "google/cloud/logging/rails"
29
+ ```
30
+ This will load a Railtie that automatically integrates with the Rails
31
+ framework by injecting a Rack middleware.
32
+
33
+ ## Using instrumentation with Sinatra
34
+
35
+ To install application instrumentation in your Sinatra app, add this gem,
36
+ `google-cloud-logging`, to your Gemfile and update your bundle. Then add
37
+ the following lines to your main application Ruby file:
38
+
39
+ ```ruby
40
+ require "google/cloud/logging"
41
+ use Google::Cloud::Logging::Middleware
42
+ ```
43
+
44
+ This will install the logging middleware in your application.
45
+
46
+ ### Using instrumentation with other Rack-based frameworks
47
+
48
+ To install application instrumentation in an app using another Rack-based
49
+ web framework, add this gem, `google-cloud-logging`, to your Gemfile and
50
+ update your bundle. Then add install the logging middleware in your
51
+ middleware stack. In most cases, this means adding these lines to your
52
+ `config.ru` Rack configuration file:
53
+
54
+ ```ruby
55
+ require "google/cloud/logging"
56
+ use Google::Cloud::Logging::Middleware
57
+ ```
58
+
59
+ Some web frameworks have an alternate mechanism for modifying the
60
+ middleware stack. Consult your web framework's documentation for more
61
+ information.
62
+
63
+ ### The Stackdriver diagnostics suite
64
+
65
+ The google-cloud-logging library is part of the Stackdriver diagnostics suite,
66
+ which also includes error reporting, tracing analysis, and real-time debugger.
67
+ If you include the `stackdriver` gem in your Gemfile, this logging library will
68
+ be included automatically. In addition, if you include the `stackdriver`
69
+ gem in an application using Ruby On Rails, the Railties will be installed
70
+ automatically. See the documentation for the "stackdriver" gem
71
+ for more details.
@@ -0,0 +1,32 @@
1
+ # Enabling gRPC Logging
2
+
3
+ To enable logging for this library, set the logger for the underlying
4
+ [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
5
+ that you set may be a Ruby stdlib
6
+ [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
7
+ shown below, or a
8
+ [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger)
9
+ that will write logs to [Stackdriver
10
+ Logging](https://cloud.google.com/logging/). See
11
+ [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
12
+ and the gRPC
13
+ [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
14
+ for additional information.
15
+
16
+ Configuring a Ruby stdlib logger:
17
+
18
+ ```ruby
19
+ require "logger"
20
+
21
+ module MyLogger
22
+ LOGGER = Logger.new $stderr, level: Logger::WARN
23
+ def logger
24
+ LOGGER
25
+ end
26
+ end
27
+
28
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
29
+ module GRPC
30
+ extend MyLogger
31
+ end
32
+ ```
@@ -0,0 +1,321 @@
1
+ # Stackdriver Logging
2
+
3
+ The Stackdriver Logging service collects and stores logs from applications and
4
+ services on the Google Cloud Platform, giving you fine-grained, programmatic
5
+ control over your projects' logs. You can use the Stackdriver Logging API to:
6
+
7
+ * [Read and filter log entries](#listing-log-entries)
8
+ * [Export your log entries](#exporting-log-entries) to Cloud Storage,
9
+ BigQuery, or Cloud Pub/Sub
10
+ * [Create logs-based metrics](#creating-logs-based-metrics) for use in
11
+ Cloud Monitoring
12
+ * [Write log entries](#writing-log-entries)
13
+
14
+ For general information about Stackdriver Logging, read [Stackdriver Logging
15
+ Documentation](https://cloud.google.com/logging/docs/).
16
+
17
+ The goal of google-cloud is to provide an API that is comfortable to Rubyists.
18
+ Your authentication credentials are detected automatically in Google Cloud
19
+ Platform environments such as Google Compute Engine, Google App Engine and
20
+ Google Kubernetes Engine. In other environments you can configure authentication
21
+ easily, either directly in your code or via environment variables. Read more
22
+ about the options for connecting in the {file:AUTHENTICATION.md Authentication
23
+ Guide}.
24
+
25
+ ## Listing log entries
26
+
27
+ Stackdriver Logging gathers log entries from many services, including Google App
28
+ Engine and Google Compute Engine. (See the [List of Log
29
+ Types](https://cloud.google.com/logging/docs/view/logs_index).) In addition, you
30
+ can write your own log entries to the service.
31
+
32
+ {Google::Cloud::Logging::Project#entries Project#entries} returns the
33
+ {Google::Cloud::Logging::Entry Entry} records belonging to your project:
34
+
35
+ ```ruby
36
+ require "google/cloud/logging"
37
+
38
+ logging = Google::Cloud::Logging.new
39
+ entries = logging.entries
40
+ entries.each do |e|
41
+ puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
42
+ end
43
+ ```
44
+
45
+ You can narrow the results to a single log using an [advanced logs
46
+ filter](https://cloud.google.com/logging/docs/view/advanced_filters). A log is a
47
+ named collection of entries. Logs can be produced by Google Cloud Platform
48
+ services, by third-party services, or by your applications. For example, the log
49
+ `compute.googleapis.com/activity_log` is produced by Google Compute Engine. Logs
50
+ are simply referenced by name in google-cloud. There is no `Log` type in
51
+ google-cloud or `Log` resource in the Stackdriver Logging API.
52
+
53
+ ```ruby
54
+ require "google/cloud/logging"
55
+
56
+ logging = Google::Cloud::Logging.new
57
+ entries = logging.entries filter: "logName:syslog"
58
+ entries.each do |e|
59
+ puts "[#{e.timestamp}] #{e.payload.inspect}"
60
+ end
61
+ ```
62
+
63
+ You can also order the log entries by `timestamp`.
64
+
65
+ ```ruby
66
+ require "google/cloud/logging"
67
+
68
+ logging = Google::Cloud::Logging.new
69
+ entries = logging.entries order: "timestamp desc"
70
+ entries.each do |e|
71
+ puts "[#{e.timestamp}] #{e.log_name}"
72
+ end
73
+ ```
74
+
75
+ ## Exporting log entries
76
+
77
+ Stackdriver Logging lets you export log entries to destinations including Google
78
+ Cloud Storage buckets (for long term log storage), Google BigQuery datasets (for
79
+ log analysis), and Google Pub/Sub (for streaming to other applications).
80
+
81
+ ### Creating sinks
82
+
83
+ A {Google::Cloud::Logging::Sink Sink} is an object that lets you to specify a
84
+ set of log entries to export.
85
+
86
+ In addition to the name of the sink and the export destination,
87
+ {Google::Cloud::Logging::Project#create_sink Project#create_sink} accepts an
88
+ [advanced logs
89
+ filter](https://cloud.google.com/logging/docs/view/advanced_filters) to narrow
90
+ the collection.
91
+
92
+ Before creating the sink, ensure that you have granted `cloud-logs@google.com`
93
+ permission to write logs to the destination. See [Exporting Logs
94
+ (V2)](https://cloud.google.com/logging/docs/export/configure_export_v2).
95
+
96
+ ```ruby
97
+ require "google/cloud/storage"
98
+ require "google/cloud/logging"
99
+
100
+ storage = Google::Cloud::Storage.new
101
+
102
+ bucket = storage.create_bucket "my-logs-bucket"
103
+
104
+ # Grant owner permission to Stackdriver Logging service
105
+ email = "cloud-logs@google.com"
106
+ bucket.acl.add_owner "group-#{email}"
107
+
108
+ logging = Google::Cloud::Logging.new
109
+
110
+ sink = logging.create_sink "my-sink",
111
+ "storage.googleapis.com/#{bucket.id}"
112
+ ```
113
+
114
+ When you create a sink, only new log entries are exported. Stackdriver Logging
115
+ does not send previously-ingested log entries to the sink's destination.
116
+
117
+ ### Listing sinks
118
+
119
+ You can also list the sinks belonging to your project with
120
+ {Google::Cloud::Logging::Project#sinks Project#sinks}.
121
+
122
+ ```ruby
123
+ require "google/cloud/logging"
124
+
125
+ logging = Google::Cloud::Logging.new
126
+ sinks = logging.sinks
127
+ sinks.each do |s|
128
+ puts "#{s.name}: #{s.filter} -> #{s.destination}"
129
+ end
130
+ ```
131
+
132
+ ## Creating logs-based metrics
133
+
134
+ You can use log entries in your project as the basis for [Google Cloud
135
+ Monitoring](https://cloud.google.com/monitoring/docs) metrics. These metrics can
136
+ then be used to produce Cloud Monitoring reports and alerts.
137
+
138
+ ### Creating metrics
139
+
140
+ A metric is a measured value that can be used to assess a system. Use
141
+ {Google::Cloud::Logging::Project#create_metric Project#create_metric} to
142
+ configure a {Google::Cloud::Logging::Metric Metric} based on a collection of
143
+ log entries matching an [advanced logs
144
+ filter](https://cloud.google.com/logging/docs/view/advanced_filters).
145
+
146
+ ```ruby
147
+ require "google/cloud/logging"
148
+
149
+ logging = Google::Cloud::Logging.new
150
+ metric = logging.create_metric "errors", "severity>=ERROR"
151
+ ```
152
+
153
+ ### Listing metrics
154
+
155
+ You can also list the metrics belonging to your project with
156
+ {Google::Cloud::Logging::Project#metrics Project#metrics}.
157
+
158
+ ```ruby
159
+ require "google/cloud/logging"
160
+
161
+ logging = Google::Cloud::Logging.new
162
+ metrics = logging.metrics
163
+ metrics.each do |m|
164
+ puts "#{m.name}: #{m.filter}"
165
+ end
166
+ ```
167
+
168
+ ## Writing log entries
169
+
170
+ An {Google::Cloud::Logging::Entry} is composed of metadata and a payload. The
171
+ payload is traditionally a message string, but in Stackdriver Logging it can
172
+ also be a JSON or protocol buffer object. A single log can have entries with
173
+ different payload types. In addition to the payload, your argument(s) to
174
+ {Google::Cloud::Logging::Project#write_entries Project#write_entries} must also
175
+ contain a log name and a resource.
176
+
177
+ ```ruby
178
+ require "google/cloud/logging"
179
+
180
+ logging = Google::Cloud::Logging.new
181
+
182
+ entry = logging.entry
183
+ entry.payload = "Job started."
184
+ entry.log_name = "my_app_log"
185
+ entry.resource.type = "gae_app"
186
+ entry.resource.labels[:module_id] = "1"
187
+ entry.resource.labels[:version_id] = "20150925t173233"
188
+
189
+ logging.write_entries entry
190
+ ```
191
+
192
+ To write a JSON payload to the log, simply pass a hash argument:
193
+
194
+ ```ruby
195
+ require "google/cloud/logging"
196
+
197
+ logging = Google::Cloud::Logging.new
198
+
199
+ entry = logging.entry
200
+ entry.payload = { "stats" => { "a" => 8, "b" => 12.5} }
201
+ entry.log_name = "my_app_log"
202
+ entry.resource.type = "gae_app"
203
+ entry.resource.labels[:module_id] = "1"
204
+ entry.resource.labels[:version_id] = "20150925t173233"
205
+
206
+ logging.write_entries entry
207
+ ```
208
+
209
+ If you write a collection of log entries, you can provide the log name,
210
+ resource, and/or labels hash to be used for all of the entries, and omit these
211
+ values from the individual entries.
212
+
213
+ ```ruby
214
+ require "google/cloud/logging"
215
+
216
+ logging = Google::Cloud::Logging.new
217
+
218
+ entry1 = logging.entry
219
+ entry1.payload = "Job started."
220
+ entry2 = logging.entry
221
+ entry2.payload = "Job completed."
222
+ labels = { job_size: "large", job_code: "red" }
223
+
224
+ resource = logging.resource "gae_app",
225
+ "module_id" => "1",
226
+ "version_id" => "20150925t173233"
227
+
228
+ logging.write_entries [entry1, entry2],
229
+ log_name: "my_app_log",
230
+ resource: resource,
231
+ labels: labels
232
+ ```
233
+
234
+ Normally, writing log entries is done synchronously; the call to
235
+ {Google::Cloud::Logging::Project#write_entries Project#write_entries} will block
236
+ until it has either completed transmitting the data or encountered an error. To
237
+ "fire and forget" without blocking, use {Google::Cloud::Logging::AsyncWriter
238
+ AsyncWriter}; it spins up a background thread that writes log entries in
239
+ batches. Calls to {Google::Cloud::Logging::AsyncWriter#write_entries
240
+ AsyncWriter#write_entries} simply add entries to its work queue and return
241
+ immediately.
242
+
243
+ ```ruby
244
+ require "google/cloud/logging"
245
+
246
+ logging = Google::Cloud::Logging.new
247
+ async = logging.async_writer
248
+
249
+ entry1 = logging.entry
250
+ entry1.payload = "Job started."
251
+ entry2 = logging.entry
252
+ entry2.payload = "Job completed."
253
+ labels = { job_size: "large", job_code: "red" }
254
+
255
+ resource = logging.resource "gae_app",
256
+ "module_id" => "1",
257
+ "version_id" => "20150925t173233"
258
+
259
+ async.write_entries [entry1, entry2],
260
+ log_name: "my_app_log",
261
+ resource: resource,
262
+ labels: labels,
263
+ partial_success: true
264
+ ```
265
+
266
+ ### Creating a Ruby Logger implementation
267
+
268
+ If your environment requires a logger instance that is API-compatible with
269
+ Ruby's standard library [Logger](http://ruby-doc.org/stdlib/libdoc/logger/rdoc),
270
+ you can use {Google::Cloud::Logging::Project#logger Project#logger} to create
271
+ one.
272
+
273
+ ```ruby
274
+ require "google/cloud/logging"
275
+
276
+ logging = Google::Cloud::Logging.new
277
+
278
+ resource = logging.resource "gae_app",
279
+ module_id: "1",
280
+ version_id: "20150925t173233"
281
+
282
+ logger = logging.logger "my_app_log", resource, env: :production
283
+ logger.info "Job started."
284
+ ```
285
+
286
+ By default, the logger instance writes log entries asynchronously in a
287
+ background thread using an {Google::Cloud::Logging::AsyncWriter AsyncWriter}. If
288
+ you want to customize or disable asynchronous writing, you may call the Logger
289
+ constructor directly.
290
+
291
+ ```ruby
292
+ require "google/cloud/logging"
293
+
294
+ logging = Google::Cloud::Logging.new
295
+
296
+ resource = logging.resource "gae_app",
297
+ module_id: "1",
298
+ version_id: "20150925t173233"
299
+
300
+ logger = Google::Cloud::Logging::Logger.new logging,
301
+ "my_app_log",
302
+ resource,
303
+ {env: :production}
304
+ logger.info "Log entry written synchronously."
305
+ ```
306
+
307
+ ## Configuring timeout
308
+
309
+ You can configure the request `timeout` value in seconds.
310
+
311
+ ```ruby
312
+ require "google/cloud/logging"
313
+
314
+ logging = Google::Cloud::Logging.new timeout: 120
315
+ ```
316
+
317
+ ## Additional information
318
+
319
+ Stackdriver Logging can be configured to be used in Rack applications or to use
320
+ gRPC's logging. To learn more, see the {file:INSTRUMENTATION.md Instrumentation
321
+ Guide} and {file:LOGGING.md Logging guide}.
@@ -0,0 +1,37 @@
1
+ # Troubleshooting
2
+
3
+ ## Where can I get more help?
4
+
5
+ ### Ask the Community
6
+
7
+ If you have a question about how to use a Google Cloud client library in your
8
+ project or are stuck in the Developer's console and don't know where to turn,
9
+ it's possible your questions have already been addressed by the community.
10
+
11
+ First, check out the appropriate tags on StackOverflow:
12
+ - [`google-cloud-platform+ruby+logging`][so-ruby]
13
+
14
+ Next, try searching through the issues on GitHub:
15
+
16
+ - [`api:logging` issues][gh-search-ruby]
17
+
18
+ Still nothing?
19
+
20
+ ### Ask the Developers
21
+
22
+ If you're experiencing a bug with the code, or have an idea for how it can be
23
+ improved, *please* create a new issue on GitHub so we can talk about it.
24
+
25
+ - [New issue][gh-ruby]
26
+
27
+ Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
+ can use the "ruby" channel for general Ruby questions, or use the
29
+ "google-cloud-ruby" channel if you have questions about this gem in particular.
30
+
31
+ [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+logging
32
+
33
+ [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+logging%22
34
+
35
+ [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
36
+
37
+ [slack-ruby]: https://gcp-slack.appspot.com/
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Logging
19
- VERSION = "1.5.3".freeze
19
+ VERSION = "1.5.4".freeze
20
20
  end
21
21
  end
22
22
  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.5.3
4
+ version: 1.5.4
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: 2018-09-10 00:00:00.000000000 Z
12
+ date: 2018-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -244,8 +244,15 @@ extensions: []
244
244
  extra_rdoc_files: []
245
245
  files:
246
246
  - ".yardopts"
247
+ - AUTHENTICATION.md
248
+ - CHANGELOG.md
249
+ - CODE_OF_CONDUCT.md
250
+ - CONTRIBUTING.md
251
+ - INSTRUMENTATION.md
247
252
  - LICENSE
248
- - README.md
253
+ - LOGGING.md
254
+ - OVERVIEW.md
255
+ - TROUBLESHOOTING.md
249
256
  - lib/google-cloud-logging.rb
250
257
  - lib/google/cloud/logging.rb
251
258
  - lib/google/cloud/logging/async_writer.rb
data/README.md DELETED
@@ -1,220 +0,0 @@
1
- # google-cloud-logging
2
-
3
- [Stackdriver Logging](https://cloud.google.com/logging/) ([docs](https://cloud.google.com/logging/docs/)) allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS). It supports ingestion of any custom log data from any source. Stackdriver Logging is a fully-managed service that performs at scale and can ingest application and system log data from thousands of VMs. Even better, you can analyze all that log data in real-time.
4
-
5
- - [google-cloud-logging API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest)
6
- - [google-cloud-logging on RubyGems](https://rubygems.org/gems/google-cloud-logging)
7
- - [Stackdriver Logging documentation](https://cloud.google.com/logging/docs/)
8
-
9
- ## Quick Start
10
-
11
- Install the gem directly:
12
-
13
- ```sh
14
- $ gem install google-cloud-logging
15
- ```
16
-
17
- Or install through Bundler:
18
-
19
- 1. Add the `google-cloud-logging` gem to your Gemfile:
20
-
21
- ```ruby
22
- gem "google-cloud-logging"
23
- ```
24
-
25
- 2. Use Bundler to install the gem:
26
-
27
- ```sh
28
- $ bundle install
29
- ```
30
-
31
- Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
32
- the `google-cloud-logging` gem.
33
-
34
- ## Logging using client library
35
-
36
- You can directly read or write log entries through the client library:
37
-
38
- ```ruby
39
- require "google/cloud/logging"
40
-
41
- logging = Google::Cloud::Logging.new
42
-
43
- # List all log entries
44
- logging.entries.each do |e|
45
- puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
46
- end
47
-
48
- # List only entries from a single log
49
- entries = logging.entries filter: "log:syslog"
50
-
51
- # Write a log entry
52
- entry = logging.entry
53
- entry.payload = "Job started."
54
- entry.log_name = "my_app_log"
55
- entry.resource.type = "gae_app"
56
- entry.resource.labels[:module_id] = "1"
57
- entry.resource.labels[:version_id] = "20150925t173233"
58
-
59
- logging.write_entries entry
60
- ```
61
-
62
- ## Using Stackdriver Logging in frameworks
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
66
- Rack logger to an instance of the Stackdriver Logging logger.
67
-
68
- ### With Ruby on Rails
69
-
70
- You can load the Railtie that comes with the library into your Ruby
71
- on Rails application by explicitly requiring it during the application startup:
72
-
73
- ```ruby
74
- # In config/application.rb
75
- require "google/cloud/logging/rails"
76
- ```
77
-
78
- If you're using the `stackdriver` gem, it automatically loads the Railtie into
79
- your application when it starts.
80
-
81
- You'll be able to use Stackdriver logger through the standard Rails logger:
82
-
83
- ```ruby
84
- Rails.logger.info "Hello World"
85
- # Or just...
86
- logger.warn "Hola Mundo"
87
- ```
88
-
89
- ### With other Rack-based frameworks
90
-
91
- Other Rack-based applications can use the Rack Middleware to replace the Rack
92
- logger with the Stackdriver Logging logger:
93
-
94
- ```ruby
95
- require "google/cloud/logging"
96
- use Google::Cloud::Logging::Middleware
97
- ```
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
101
- Rack logger:
102
-
103
- ```ruby
104
- logger.info "Hello World"
105
- logger.warn "Hola Mundo"
106
- logger.error "Bonjour Monde"
107
- ```
108
-
109
- For other frameworks, consult the documentations on how to utilize the Rack
110
- logger.
111
-
112
- ### Configuring the framework integration
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
116
- list of possible configuration options.
117
-
118
- ## Authentication
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
123
- credentials can be specified by providing in several ways.
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
127
- interface:
128
-
129
- ```ruby
130
- # Add this to config/environments/*.rb
131
- Rails.application.configure do |config|
132
- # Shared parameters
133
- config.google_cloud.project_id = "your-project-id"
134
- config.google_cloud.keyfile = "/path/to/key.json"
135
- # Stackdriver Logging specific parameters
136
- config.google_cloud.logging.project_id = "your-project-id"
137
- config.google_cloud.logging.keyfile = "/path/to/key.json"
138
- end
139
- ```
140
- Other Rack-based applications that are loading the Rack Middleware directly can
141
- use the configration interface:
142
-
143
- ```ruby
144
- require "google/cloud/logging"
145
- Google::Cloud.configure do |config|
146
- # Shared parameters
147
- config.project_id = "your-project-id"
148
- config.keyfile = "/path/to/key.json"
149
- # Or Stackdriver logging specific parameters
150
- config.logging.project_id = "your-project-id"
151
- config.logging.keyfile = "/path/to/key.json"
152
- end
153
- ```
154
-
155
- See the [Authentication
156
- Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/file.AUTHENTICATION).
157
- for more ways to authenticate the client library.
158
-
159
- ## Enabling Logging
160
-
161
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
162
-
163
- Configuring a Ruby stdlib logger:
164
-
165
- ```ruby
166
- require "logger"
167
-
168
- module MyLogger
169
- LOGGER = Logger.new $stderr, level: Logger::WARN
170
- def logger
171
- LOGGER
172
- end
173
- end
174
-
175
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
176
- module GRPC
177
- extend MyLogger
178
- end
179
- ```
180
-
181
- ## Supported Ruby Versions
182
-
183
- This library is supported on Ruby 2.3+.
184
-
185
- Google provides official support for Ruby versions that are actively supported
186
- by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
187
- security maintenance, and not end of life. Currently, this means Ruby 2.3 and
188
- later. Older versions of Ruby _may_ still work, but are unsupported and not
189
- recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
190
- about the Ruby support schedule.
191
-
192
- ## Versioning
193
-
194
- This library follows [Semantic Versioning](http://semver.org/).
195
-
196
- ## Contributing
197
-
198
- Contributions to this library are always welcome and highly encouraged.
199
-
200
- See the [Contributing
201
- Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/file.CONTRIBUTING)
202
- for more information on how to get started.
203
-
204
- Please note that this project is released with a Contributor Code of Conduct. By
205
- participating in this project you agree to abide by its terms. See [Code of
206
- Conduct](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/file.CODE_OF_CONDUCT)
207
- for more information.
208
-
209
- ## License
210
-
211
- This library is licensed under Apache 2.0. Full license text is available in
212
- [LICENSE](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/file.LICENSE).
213
-
214
- ## Support
215
-
216
- Please [report bugs at the project on
217
- Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues). Don't
218
- hesitate to [ask
219
- questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
220
- about the client or APIs on [StackOverflow](http://stackoverflow.com).