Update a sink
Stay organized with collections
Save and categorize content based on your preferences.
Demonstrates how to update a Cloud Logging Sink.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to update a Cloud Logging Sink.\n\nCode sample \n\nC#\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 UpdateSinkLog(string sinkId, string logId)\n {\n var sinkClient = ConfigServiceV2Client.Create();\n LogName logName = new LogName(s_projectId, logId);\n LogSinkName sinkName = new LogSinkName(s_projectId, sinkId);\n var sink = sinkClient.GetSink(sinkName, _retryAWhile);\n sink.Filter = $\"logName={logName.ToString()}AND severity\u003c=ERROR\";\n sinkClient.UpdateSink(sinkName, sink, _retryAWhile);\n Console.WriteLine($\"Updated {sinkId} to export logs from {logId}.\");\n }\n\nGo\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\"cloud.google.com/go/logging/logadmin\"\n )\n\n func updateSink(projectID string) (*logadmin.Sink, 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 \tsink, err := client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/logging/latest/logadmin.html#cloud_google_com_go_logging_logadmin_Client_UpdateSink(ctx, &logadmin.Sink{\n \t\tID: \"severe-errors-to-gcs\",\n \t\tDestination: \"storage.googleapis.com/logsinks-new-bucket\",\n \t\tFilter: \"severity \u003e= INFO\",\n \t})\n \treturn sink, err\n }\n\nJava\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 SinkInfo sinkInfo =\n SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))\n .setVersionFormat(SinkInfo.VersionFormat.V2)\n .setFilter(\"severity\u003e=ERROR\")\n .build();\n Sink sink = logging.update(sinkInfo);\n\nNode.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 lines to run the code.\n */\n // const sinkName = 'Name of sink to update, e.g. my-sink';\n // const filter = 'New filter for the sink, e.g. severity \u003e= WARNING';\n\n const sink = logging.sink(sinkName);\n\n /**\n * The filter determines which logs this sink matches and will be exported\n * to the destination. For example a filter of 'severity\u003e=INFO' will send\n * all logs that have a severity of INFO or greater to the destination.\n * See https://cloud.google.com/logging/docs/view/advanced_filters for more\n * filter information.\n */\n const metadataInfo = {\n filter: filter,\n };\n\n async function updateSink() {\n // See https://googleapis.dev/nodejs/logging/latest/Sink.html#setMetadata\n const [metadata] = await sink.https://cloud.google.com/nodejs/docs/reference/logging/latest/logging/sink.html(metadataInfo);\n console.log(`Sink ${sinkName} updated.`, metadata);\n }\n updateSink();\n\nPHP\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 * Update a log sink.\n *\n * @param string $projectId\n * @param string $sinkName\n * @param string $filterString\n */\n function update_sink($projectId, $sinkName, $filterString)\n {\n $logging = new LoggingClient(['projectId' =\u003e $projectId]);\n $sink = $logging-\u003esink($sinkName);\n $sink-\u003eupdate(['filter' =\u003e $filterString]);\n printf(\"Updated a sink '%s'.\" . PHP_EOL, $sinkName);\n }\n\nPython\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 update_sink(sink_name, filter_):\n \"\"\"Changes a sink's filter.\n\n The filter determines which logs this sink matches and will be exported\n to the destination. For example a filter of 'severity\u003e=INFO' will send\n all logs that have a severity of INFO or greater to the destination.\n See https://cloud.google.com/logging/docs/view/advanced_filters for more\n filter information.\n \"\"\"\n logging_client = logging.Client()\n sink = logging_client.sink(sink_name)\n\n sink.reload()\n\n sink.filter_ = filter_\n print(\"Updated sink {}\".format(sink.name))\n sink.update()\n\nRuby\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-logging-v2/latest/Google-Cloud-Logging.html.new\n storage = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage.html.new\n # bucket_name = \"name-of-my-storage-bucket\"\n bucket = storage.create_bucket bucket_name\n # sink_name = \"name-of-my-sink\"\n sink = logging.sink sink_name\n\n sink.destination = \"storage.googleapis.com/#{bucket.id}\"\n\n sink.save\n puts \"Updated sink destination for #{sink.name} to #{sink.destination}\"\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=logging)."]]