You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: describe authorization required for service object (#582)
* fix: adds authorization description Adds description of the authorization requirements for a service object. Fixes markdown warnings in the document. Fixes#570 * Improve description and update autogen template fix the wording for "creating an authorized service object" section update the readme template so the next autgen event will keep changes in * make authorization section match synthool template update the authorization section to make it more generic following other blocks in the synthool template.
These credentials are automatically inferred from your environment, so you only need the following
8
-
code to create your service object:
9
-
3
+
4
+
To make requests to Cloud Logging, you must create a service object with valid credentials.
5
+
You can then make API calls by calling methods on the Logging service object.
6
+
You can obtain credentials by using [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
7
+
Or you can use a [Service Account](https://cloud.google.com/iam/docs/service-accounts) which is a recommended way to obtain credentials.
8
+
The credentials can be automatically inferred from your [environment](https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable).
9
+
Then you only need the following code to create your service object:
For other options, see the [Authentication](https://github.com/googleapis/google-cloud-java#authentication) page.
22
+
The service object should be granted permissions to make API calls.
23
+
Each API call describes the permissions under Authorized Scopes section.
24
+
See [Logging API](https://cloud.google.com/logging/docs/reference/v2/rest) to find the required list of permissions or consult with [Access control guide](https://cloud.google.com/logging/docs/access-control) for predefined IAM roles that can be granted to the Logging service object.
22
25
23
26
#### Creating a metric
24
27
With Logging you can create logs-based metrics. Logs-based metrics allow to keep track of the number
@@ -28,6 +31,7 @@ custom_content: |
28
31
import com.google.cloud.logging.Metric;
29
32
import com.google.cloud.logging.MetricInfo;
30
33
```
34
+
31
35
Then, to create the metric, use the following code:
32
36
33
37
```java
@@ -38,8 +42,10 @@ custom_content: |
38
42
```
39
43
40
44
#### Writing log entries
45
+
41
46
With Logging you can also write custom log entries. Add the following imports at the top of your
42
47
file:
48
+
43
49
```java
44
50
import com.google.cloud.MonitoredResource;
45
51
import com.google.cloud.logging.LogEntry;
@@ -48,7 +54,9 @@ custom_content: |
48
54
49
55
import java.util.Collections;
50
56
```
57
+
51
58
Then, to write the log entries, use the following code:
See the [Authentication][authentication] section in the base directory's README.
66
71
72
+
## Authorization
73
+
74
+
A GCP account credentials that are used in API calls should be granted [Authorization Scopes](https://developers.google.com/identity/protocols/oauth2/scopes) to call these APIs. You can also review existing [predefined IAM roles](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles) that can be granted to GCP account which is used for authentication.
75
+
67
76
## Getting Started
68
77
69
78
### Prerequisites
@@ -81,20 +90,19 @@ to add `google-cloud-logging` as a dependency in your code.
81
90
82
91
## About Cloud Logging
83
92
84
-
85
93
[Cloud Logging][product-docs] allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud and Amazon Web Services. Using the BindPlane service, you can also collect this data from over 150 common application components, on-premises systems, and hybrid cloud systems. BindPlane is included with your Google Cloud project at no additional cost.
86
94
87
95
See the [Cloud Logging client library docs][javadocs] to learn how to
88
96
use this Cloud Logging Client Library.
89
97
90
-
91
98
#### Creating an authorized service object
92
-
To make authenticated requests to Cloud Logging, you must create a service object with
93
-
credentials. You can then make API calls by calling methods on the Logging service object. The
These credentials are automatically inferred from your environment, so you only need the following
97
-
code to create your service object:
99
+
100
+
To make requests to Cloud Logging, you must create a service object with valid credentials.
101
+
You can then make API calls by calling methods on the Logging service object.
102
+
You can obtain credentials by using [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
103
+
Or you can use a [Service Account](https://cloud.google.com/iam/docs/service-accounts) which is a recommended way to obtain credentials.
104
+
The credentials can be automatically inferred from your [environment](https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable).
105
+
Then you only need the following code to create your service object:
For other options, see the [Authentication](https://github.com/googleapis/google-cloud-java#authentication) page.
118
+
The service object should be granted permissions to make API calls.
119
+
Each API call describes the permissions under Authorized Scopes section.
120
+
See [Logging API](https://cloud.google.com/logging/docs/reference/v2/rest) to find the required list of permissions or consult with [Access control guide](https://cloud.google.com/logging/docs/access-control) for predefined IAM roles that can be granted to the Logging service object.
111
121
112
122
#### Creating a metric
123
+
113
124
With Logging you can create logs-based metrics. Logs-based metrics allow to keep track of the number
114
125
of log messages associated to specific events. Add the following imports at the top of your file:
115
126
116
127
```java
117
128
importcom.google.cloud.logging.Metric;
118
129
importcom.google.cloud.logging.MetricInfo;
119
130
```
131
+
120
132
Then, to create the metric, use the following code:
121
133
122
134
```java
@@ -127,8 +139,10 @@ logging.create(metricInfo);
127
139
```
128
140
129
141
#### Writing log entries
142
+
130
143
With Logging you can also write custom log entries. Add the following imports at the top of your
we put together all the code shown above into three programs. The programs assume that you are
195
221
running on Compute Engine or from your own desktop.
196
222
197
-
198
-
199
223
## Samples
200
224
201
225
Samples are in the [`samples/`](https://github.com/googleapis/java-logging/tree/master/samples) directory. The samples' `README.md`
@@ -210,8 +234,6 @@ has instructions for running the samples.
210
234
| Quickstart |[source code](https://github.com/googleapis/java-logging/blob/master/samples/snippets/src/main/java/com/example/logging/jul/Quickstart.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-logging&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/logging/jul/Quickstart.java)|
211
235
| Example Enhancer |[source code](https://github.com/googleapis/java-logging/blob/master/samples/snippets/src/main/java/com/example/logging/jul/enhancers/ExampleEnhancer.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-logging&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/logging/jul/enhancers/ExampleEnhancer.java)|
212
236
213
-
214
-
215
237
## Troubleshooting
216
238
217
239
To get help, follow the instructions in the [shared Troubleshooting document][troubleshooting].
@@ -266,13 +288,10 @@ and on [google-cloud-java][g-c-j].
266
288
267
289
## Versioning
268
290
269
-
270
291
This library follows [Semantic Versioning](http://semver.org/).
271
292
272
-
273
293
## Contributing
274
294
275
-
276
295
Contributions to this library are always welcome and highly encouraged.
277
296
278
297
See [CONTRIBUTING][contributing] for more information how to get started.
0 commit comments