Senke abrufen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Veranschaulicht das Abrufen der Metadaten für eine Cloud Logging-Senke
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[],[],null,["# Get a sink\n\nDemonstrates how to retrieve the metadata for a Cloud Logging Sink.\n\nCode sample\n-----------\n\n### Go\n\n\nTo learn how to install and use the client library for Logging, see\n[Logging client libraries](/logging/docs/reference/libraries).\n\n\nTo authenticate to Logging, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \t\"cloud.google.com/go/logging/logadmin\"\n )\n\n // getSink retrieves the metadata for a Cloud Logging Sink.\n func getSink(w io.Writer, projectID, sinkName string) error {\n \tctx := context.Background()\n\n \tclient, err := logadmin.https://cloud.google.com/go/docs/reference/cloud.google.com/go/logging/latest/logadmin.html#cloud_google_com_go_logging_logadmin_Client_NewClient(ctx, projectID)\n \tif err != nil {\n \t\treturn err\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/logging/latest/logadmin.html#cloud_google_com_go_logging_logadmin_Client_Close()\n\n \tsink, err := client.Sink(ctx, sinkName)\n \tif err != nil {\n \t\treturn err\n \t}\n \tfmt.Fprintf(w, \"%v\\n\", sink)\n \treturn nil\n }\n\n### Java\n\n\nTo learn how to install and use the client library for Logging, see\n[Logging client libraries](/logging/docs/reference/libraries).\n\n\nTo authenticate to Logging, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.logging.https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Logging.html;\n import com.google.cloud.logging.https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LoggingOptions.html;\n import com.google.cloud.logging.https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Sink.html;\n\n /** Retrieve Cloud Logging Sink metadata. */\n public class GetSinkMetadata {\n public static void main(String[] args) throws Exception {\n // TODO(developer): Replace these variables before running the sample.\n // The Name of your sink\n String sinkName = \"sink-name\"; // i.e my-sink\n\n getSinkMetadata(sinkName);\n }\n\n public static void getSinkMetadata(String sinkName) throws Exception {\n // Instantiates a logging client\n try (https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Logging.html logging = https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LoggingOptions.html.https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LoggingOptions.html#com_google_cloud_logging_LoggingOptions_getDefaultInstance__().getService()) {\n\n https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Sink.html sink = logging.getSink(sinkName);\n\n // print sink metadata\n System.out.println(\"Name:\" + sink.getName());\n System.out.println(\"Version Format:\" + sink.https://cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.SinkInfo.html#com_google_cloud_logging_SinkInfo_getVersionFormat__());\n System.out.println(\"Filter:\" + sink.getFilter());\n System.out.println(\"Destination:\" + sink.getDestination());\n }\n }\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Logging, see\n[Logging client libraries](/logging/docs/reference/libraries).\n\n\nTo authenticate to Logging, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud client library\n const {Logging} = require('https://cloud.google.com/nodejs/docs/reference/logging/latest/overview.html');\n\n // Creates a client\n const logging = new https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/logging.html();\n\n /**\n * TODO(developer): Uncomment the following line to run the code.\n */\n // const sinkName = 'Name of your sink, e.g. my-sink';\n\n const sink = logging.sink(sinkName);\n\n async function printSinkMetadata() {\n // See https://googleapis.dev/nodejs/logging/latest/Sink.html#getMetadata\n const [metadata] = await sink.https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/sink.html();\n console.log(`Name: ${metadata.name}`);\n console.log(`Destination: ${metadata.destination}`);\n console.log(`Filter: ${metadata.filter}`);\n }\n printSinkMetadata();\n\n### Python\n\n\nTo learn how to install and use the client library for Logging, see\n[Logging client libraries](/logging/docs/reference/libraries).\n\n\nTo authenticate to Logging, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from typing import List\n from google.cloud import logging\n\n\n def get_sink(project_id: str, sink_name: str) -\u003e logging.Sink:\n \"\"\"Retrieves the metadata for a Cloud Logging Sink.\n\n Args:\n project_id: the ID of the project\n sink_name: the name of the sink\n\n Returns:\n A Cloud Logging Sink.\n \"\"\"\n client = logging.Client(project=project_id)\n sink = client.sink(sink_name)\n sink.reload()\n print(f\"Name: {sink.name}\")\n print(f\"Destination: {sink.destination}\")\n print(f\"Filter: {sink.filter_}\")\n return sink\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=logging)."]]