forked from googleapis/google-cloud-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add complete README and package-info for logging (googleapis#1119)
- Loading branch information
Showing
2 changed files
with
208 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
gcloud-java-logging/src/main/java/com/google/cloud/logging/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* A client to Stackdriver Logging. | ||
* | ||
* <p>Here's a simple usage example for using gcloud-java from Compute Engine/App Engine Flexible. | ||
* This example shows how to write and list log entries. For the complete source code see | ||
* <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java"> | ||
* WriteAndListLogEntries.java</a>. | ||
* <pre> {@code | ||
* LoggingOptions options = LoggingOptions.defaultInstance(); | ||
* try(Logging logging = options.service()) { | ||
* | ||
* LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) | ||
* .logName("test-log") | ||
* .resource(MonitoredResource.builder("global") | ||
* .addLabel("project_id", options.projectId()) | ||
* .build()) | ||
* .build(); | ||
* logging.write(Collections.singleton(firstEntry)); | ||
* | ||
* Page<LogEntry> entries = logging.listLogEntries( | ||
* EntryListOption.filter("logName=projects/" + options.projectId() + "/logs/test-log")); | ||
* Iterator<LogEntry> entryIterator = entries.iterateAll(); | ||
* while (entryIterator.hasNext()) { | ||
* System.out.println(entryIterator.next()); | ||
* } | ||
* }}</pre> | ||
* | ||
* <p>This second example shows how to use a {@link java.util.logging.Logger} to write log entries | ||
* to Stackdriver Logging. The snippet installs a Stackdriver Logging handler using | ||
* {@code LoggingHandler.addHandler(Logger, LoggingHandler)}. Notice that this could also be done | ||
* through the {@code logging.properties} file, adding the following line: | ||
* <pre> | ||
* {@code com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler} | ||
* </pre> | ||
* For the complete source code see | ||
* <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/logging/snippets/AddLoggingHandler.java"> | ||
* AddLoggingHandler.java</a>. | ||
* <pre> {@code | ||
* Logger logger = Logger.getLogger(AddLoggingHandler.class.getName()); | ||
* LoggingHandler.addHandler(logger, new LoggingHandler()); | ||
* logger.warning("test warning"); | ||
* }</pre> | ||
* | ||
* @see <a href="https://cloud.google.com/logging/">Stackdriver Logging</a> | ||
*/ | ||
package com.google.cloud.logging; |