Répertorier les récepteurs
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Explique comment répertorier les récepteurs Cloud Logging.
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],[],[],[],null,["# List sinks\n\nDemonstrates how to list Cloud Logging Sinks.\n\nCode sample\n-----------\n\n### C#\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 private void ListSinks()\n {\n var sinkClient = ConfigServiceV2Client.Create();\n ProjectName projectName = new ProjectName(s_projectId);\n var listOfSinks = sinkClient.ListSinks(projectName, callSettings: _retryAWhile);\n foreach (var sink in listOfSinks)\n {\n Console.WriteLine($\"{sink.Name} {sink.ToString()}\");\n }\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\"log\"\n\n \t\"google.golang.org/api/iterator\"\n\n \t\"cloud.google.com/go/logging/logadmin\"\n )\n\n func listSinks(projectID string) ([]string, error) {\n \tctx := context.Background()\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\tlog.Fatalf(\"logadmin.NewClient: %v\", 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 \tvar sinks []string\n \tit := client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/logging/latest/logadmin.html#cloud_google_com_go_logging_logadmin_Client_Sinks(ctx)\n \tfor {\n \t\tsink, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn nil, err\n \t\t}\n \t\tsinks = append(sinks, sink.ID)\n \t}\n \treturn sinks, 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 Page\u003cSink\u003e sinks = logging.listSinks(ListOption.pageSize(100));\n for (Sink sink : sinks.iterateAll()) {\n // do something with the sink\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 async function printSinkMetadata() {\n // See https://googleapis.dev/nodejs/logging/latest/Logging.html#getSinks\n const [sinks] = await logging.https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/logging.html();\n console.log('Sinks:');\n sinks.forEach(sink =\u003e {\n console.log(sink.name);\n console.log(` Destination: ${sink.metadata.destination}`);\n console.log(` Filter: ${sink.metadata.filter}`);\n });\n }\n printSinkMetadata();\n\n### PHP\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 use Google\\Cloud\\Logging\\LoggingClient;\n\n /**\n * List log sinks.\n *\n * @param string $projectId\n */\n function list_sinks($projectId)\n {\n $logging = new LoggingClient(['projectId' =\u003e $projectId]);\n $sinks = $logging-\u003esinks();\n foreach ($sinks as $sink) {\n /* @var $sink \\Google\\Cloud\\Logging\\Sink */\n foreach ($sink-\u003einfo() as $key =\u003e $value) {\n printf('%s:%s' . PHP_EOL,\n $key,\n is_string($value) ? $value : var_export($value, true)\n );\n }\n print PHP_EOL;\n }\n }\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 def list_sinks():\n \"\"\"Lists all sinks.\"\"\"\n logging_client = logging.Client()\n\n sinks = list(logging_client.list_sinks())\n\n if not sinks:\n print(\"No sinks.\")\n\n for sink in sinks:\n print(\"{}: {} -\u003e {}\".format(sink.name, sink.filter_, sink.destination))\n\n### Ruby\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 require \"google/cloud/logging\"\n\n logging = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-service_control-v1/latest/Google-Cloud-Logging.html.https://cloud.google.com/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging.html\n\n logging.sinks.each do |sink|\n puts \"#{sink.name}: #{sink.filter} -\u003e #{sink.destination}\"\n end\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)."]]