싱크 가져오기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Cloud Logging 싱크의 메타데이터를 검색하는 방법을 보여줍니다.
코드 샘플
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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)."]]