mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
…
|
||
---|---|---|
.. | ||
apiv2 | ||
internal | ||
CHANGES.md | ||
doc.go | ||
go_mod_tidy_hack.go | ||
LICENSE | ||
logging.go | ||
README.md | ||
resource.go |
Cloud Logging
Example Usage
First create a logging.Client
to use throughout your application:
[snip]:# (logging-1)
ctx := context.Background()
client, err := logging.NewClient(ctx, "my-project")
if err != nil {
// TODO: Handle error.
}
Usually, you'll want to add log entries to a buffer to be periodically flushed (automatically and asynchronously) to the Cloud Logging service. [snip]:# (logging-2)
logger := client.Logger("my-log")
logger.Log(logging.Entry{Payload: "something happened!"})
Close your client before your program exits, to flush any buffered log entries. [snip]:# (logging-3)
err = client.Close()
if err != nil {
// TODO: Handle error.
}