Delete a log
Deletes all the log entries in a log for the global `_Default` log bucket.
Code sample
C#
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
privatevoidDeleteLog(stringlogId)
{
varclient=LoggingServiceV2Client.Create();
LogNamelogName=newLogName(s_projectId,logId);
client.DeleteLog(logName,_retryAWhile);
Console.WriteLine($"Deleted {logId}.");
}
Go
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
import(
"context"
"log"
"cloud.google.com/go/logging/logadmin"
)
funcdeleteLog(projectIDstring)error{
ctx:=context.Background()
adminClient,err:=logadmin.NewClient (ctx,projectID)
iferr!=nil{
log.Fatalf("Failed to create logadmin client: %v",err)
}
deferadminClient.Close ()
constname="log-example"
iferr:=adminClient.DeleteLog (ctx,name);err!=nil{
returnerr
}
returnnil
}
Java
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
booleandeleted=logging.deleteLog(logName);
if(deleted){
// the log was deleted
}else{
// the log was not found
}Node.js
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
// Imports the Google Cloud client library
const{Logging}=require('@google-cloud/logging');
// Creates a client
constlogging=newLogging ();
/**
* TODO(developer): Uncomment the following line to run the code.
*/
// const logName = 'Name of the log to delete, e.g. my-log';
constlog=logging.log(logName);
asyncfunctiondeleteLog(){
// Deletes a logger and all its entries.
// Note that a deletion can take several minutes to take effect.
// See https://googleapis.dev/nodejs/logging/latest/Log.html#delete
awaitlog.delete();
console.log(`Deleted log: ${logName}`);
}
deleteLog();PHP
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
use Google\Cloud\Logging\LoggingClient;
/** Delete a logger and all its entries.
*
* @param string $projectId The Google project ID.
* @param string $loggerName The name of the logger.
*/
function delete_logger($projectId, $loggerName)
{
$logging = new LoggingClient(['projectId' => $projectId]);
$logger = $logging->logger($loggerName);
$logger->delete();
printf("Deleted a logger '%s'." . PHP_EOL, $loggerName);
}Python
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
defdelete_logger(logger_name):
"""Deletes a logger and all its entries.
Note that a deletion can take several minutes to take effect.
"""
logging_client = logging.Client()
logger = logging_client.logger(logger_name)
logger.delete()
print("Deleted all logging entries for {}".format(logger.name))
Ruby
To learn how to install and use the client library for Logging, see Logging client libraries.
To authenticate to Logging, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
What's next
To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.