取得接收器
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
示範如何擷取 Cloud Logging 接收器的中繼資料。
程式碼範例
Go
如要瞭解如何安裝及使用 Logging 的用戶端程式庫,請參閱這篇文章。
如要向 Logging 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Logging 的用戶端程式庫,請參閱這篇文章。
如要向 Logging 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Logging 的用戶端程式庫,請參閱這篇文章。
如要向 Logging 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Logging 的用戶端程式庫,請參閱這篇文章。
如要向 Logging 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","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)."]]