List sinks
Demonstrates how to list Cloud Logging Sinks.
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.
privatevoidListSinks()
{
varsinkClient=ConfigServiceV2Client.Create();
ProjectNameprojectName=newProjectName(s_projectId);
varlistOfSinks=sinkClient.ListSinks(projectName,callSettings:_retryAWhile);
foreach(varsinkinlistOfSinks)
{
Console.WriteLine($"{sink.Name} {sink.ToString()}");
}
}
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"
"google.golang.org/api/iterator"
"cloud.google.com/go/logging/logadmin"
)
funclistSinks(projectIDstring)([]string,error){
ctx:=context.Background()
client,err:=logadmin.NewClient (ctx,projectID)
iferr!=nil{
log.Fatalf("logadmin.NewClient: %v",err)
}
deferclient.Close ()
varsinks[]string
it:=client.Sinks (ctx)
for{
sink,err:=it.Next()
iferr==iterator.Done{
break
}
iferr!=nil{
returnnil,err
}
sinks=append(sinks,sink.ID)
}
returnsinks,nil
}
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.
Page<Sink>sinks=logging.listSinks(ListOption.pageSize(100));
for(Sinksink:sinks.iterateAll()){
// do something with the sink
}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 ();
asyncfunctionprintSinkMetadata(){
// See https://googleapis.dev/nodejs/logging/latest/Logging.html#getSinks
const[sinks]=awaitlogging.getSinks ();
console.log('Sinks:');
sinks.forEach(sink=>{
console.log(sink.name);
console.log(` Destination: ${sink.metadata.destination}`);
console.log(` Filter: ${sink.metadata.filter}`);
});
}
printSinkMetadata();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;
/**
* List log sinks.
*
* @param string $projectId
*/
function list_sinks($projectId)
{
$logging = new LoggingClient(['projectId' => $projectId]);
$sinks = $logging->sinks();
foreach ($sinks as $sink) {
/* @var $sink \Google\Cloud\Logging\Sink */
foreach ($sink->info() as $key => $value) {
printf('%s:%s' . PHP_EOL,
$key,
is_string($value) ? $value : var_export($value, true)
);
}
print PHP_EOL;
}
}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.
deflist_sinks():
"""Lists all sinks."""
logging_client = logging.Client()
sinks = list(logging_client.list_sinks())
if not sinks:
print("No sinks.")
for sink in sinks:
print("{}: {} -> {}".format(sink.name, sink.filter_, sink.destination))
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.