|
| 1 | +/* |
| 2 | + * Copyright 2016 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * A client to Stackdriver Logging. |
| 19 | + * |
| 20 | + * <p>Here's a simple usage example for using gcloud-java from Compute Engine/App Engine Flexible. |
| 21 | + * This example shows how to write and list log entries. For the complete source code see |
| 22 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java"> |
| 23 | + * WriteAndListLogEntries.java</a>. |
| 24 | + * <pre> {@code |
| 25 | + * LoggingOptions options = LoggingOptions.defaultInstance(); |
| 26 | + * try(Logging logging = options.service()) { |
| 27 | + * |
| 28 | + * LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) |
| 29 | + * .logName("test-log") |
| 30 | + * .resource(MonitoredResource.builder("global") |
| 31 | + * .addLabel("project_id", options.projectId()) |
| 32 | + * .build()) |
| 33 | + * .build(); |
| 34 | + * logging.write(Collections.singleton(firstEntry)); |
| 35 | + * |
| 36 | + * Page<LogEntry> entries = logging.listLogEntries( |
| 37 | + * EntryListOption.filter("logName=projects/" + options.projectId() + "/logs/test-log")); |
| 38 | + * Iterator<LogEntry> entryIterator = entries.iterateAll(); |
| 39 | + * while (entryIterator.hasNext()) { |
| 40 | + * System.out.println(entryIterator.next()); |
| 41 | + * } |
| 42 | + * }}</pre> |
| 43 | + * |
| 44 | + * <p>This second example shows how to use a {@link java.util.logging.Logger} to write log entries |
| 45 | + * to Stackdriver Logging. The snippet installs a Stackdriver Logging handler using |
| 46 | + * {@code LoggingHandler.addHandler(Logger, LoggingHandler)}. Notice that this could also be done |
| 47 | + * through the {@code logging.properties} file, adding the following line: |
| 48 | + * <pre> |
| 49 | + * {@code com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler} |
| 50 | + * </pre> |
| 51 | + * For the complete source code see |
| 52 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/logging/snippets/AddLoggingHandler.java"> |
| 53 | + * AddLoggingHandler.java</a>. |
| 54 | + * <pre> {@code |
| 55 | + * Logger logger = Logger.getLogger(AddLoggingHandler.class.getName()); |
| 56 | + * LoggingHandler.addHandler(logger, new LoggingHandler()); |
| 57 | + * logger.warning("test warning"); |
| 58 | + * }</pre> |
| 59 | + * |
| 60 | + * @see <a href="https://cloud.google.com/logging/">Stackdriver Logging</a> |
| 61 | + */ |
| 62 | +package com.google.cloud.logging; |
0 commit comments