Delete a log
Stay organized with collections
Save and categorize content based on your preferences.
Deletes all the log entries in a log for the global `_Default` log bucket.
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,["# Delete a log\n\nDeletes all the log entries in a log for the global \\`_Default\\` log bucket.\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 DeleteLog(string logId)\n {\n var client = LoggingServiceV2Client.Create();\n LogName logName = new LogName(s_projectId, logId);\n client.DeleteLog(logName, _retryAWhile);\n Console.WriteLine($\"Deleted {logId}.\");\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\"cloud.google.com/go/logging/logadmin\"\n )\n\n func deleteLog(projectID string) error {\n \tctx := context.Background()\n \tadminClient, 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(\"Failed to create logadmin client: %v\", err)\n \t}\n \tdefer adminClient.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 \tconst name = \"log-example\"\n \tif err := adminClient.https://cloud.google.com/go/docs/reference/cloud.google.com/go/logging/latest/logadmin.html#cloud_google_com_go_logging_logadmin_Client_DeleteLog(ctx, name); err != nil {\n \t\treturn err\n \t}\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 boolean deleted = logging.deleteLog(logName);\n if (deleted) {\n // the log was deleted\n } else {\n // the log was not found\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 logName = 'Name of the log to delete, e.g. my-log';\n\n const log = logging.log(logName);\n\n async function deleteLog() {\n // Deletes a logger and all its entries.\n // Note that a deletion can take several minutes to take effect.\n // See https://googleapis.dev/nodejs/logging/latest/Log.html#delete\n await log.delete();\n console.log(`Deleted log: ${logName}`);\n }\n deleteLog();\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 /** Delete a logger and all its entries.\n *\n * @param string $projectId The Google project ID.\n * @param string $loggerName The name of the logger.\n */\n function delete_logger($projectId, $loggerName)\n {\n $logging = new LoggingClient(['projectId' =\u003e $projectId]);\n $logger = $logging-\u003elogger($loggerName);\n $logger-\u003edelete();\n printf(\"Deleted a logger '%s'.\" . PHP_EOL, $loggerName);\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 delete_logger(logger_name):\n \"\"\"Deletes a logger and all its entries.\n\n Note that a deletion can take several minutes to take effect.\n \"\"\"\n logging_client = logging.Client()\n logger = logging_client.logger(logger_name)\n\n logger.delete()\n\n print(\"Deleted all logging entries for {}\".format(logger.name))\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 # log_name = \"The name of the log\"\n logging.delete_log log_name\n puts \"Deleted log: #{log_name}\"\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)."]]