Documentation
¶
Overview ¶
Package logadmin contains a Stackdriver Logging client that can be used for reading logs and working with sinks, metrics and monitored resources. For a client that can write logs, see package cloud.google.com/go/logging.
The client uses Logging API v2. See https://cloud.google.com/logging/docs/api/v2/ for an introduction to the API.
Note: This package is in beta. Some backwards-incompatible changes may occur.
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) CreateMetric(ctx context.Context, m *Metric) error
- func (c *Client) CreateSink(ctx context.Context, sink *Sink) (*Sink, error)
- func (c *Client) DeleteLog(ctx context.Context, logID string) error
- func (c *Client) DeleteMetric(ctx context.Context, metricID string) error
- func (c *Client) DeleteSink(ctx context.Context, sinkID string) error
- func (c *Client) Entries(ctx context.Context, opts ...EntriesOption) *EntryIterator
- func (c *Client) Logs(ctx context.Context) *LogIterator
- func (c *Client) Metric(ctx context.Context, metricID string) (*Metric, error)
- func (c *Client) Metrics(ctx context.Context) *MetricIterator
- func (c *Client) ResourceDescriptors(ctx context.Context) *ResourceDescriptorIterator
- func (c *Client) Sink(ctx context.Context, sinkID string) (*Sink, error)
- func (c *Client) Sinks(ctx context.Context) *SinkIterator
- func (c *Client) UpdateMetric(ctx context.Context, m *Metric) error
- func (c *Client) UpdateSink(ctx context.Context, sink *Sink) (*Sink, error)
- type EntriesOption
- type EntryIterator
- type LogIterator
- type Metric
- type MetricIterator
- type ResourceDescriptorIterator
- type Sink
- type SinkIterator
Examples ¶
- Client.CreateMetric
- Client.CreateSink
- Client.DeleteLog
- Client.DeleteMetric
- Client.DeleteSink
- Client.Entries
- Client.Entries (Pagination)
- Client.Metric
- Client.Metrics
- Client.ResourceDescriptors
- Client.Sink
- Client.Sinks
- Client.UpdateMetric
- Client.UpdateSink
- EntryIterator.Next
- Filter (Timestamp)
- MetricIterator.Next
- NewClient
- ResourceDescriptorIterator.Next
- SinkIterator.Next
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Logging client. A Client is associated with a single Cloud project.
func NewClient ¶
NewClient returns a new logging client associated with the provided project ID.
By default NewClient uses AdminScope. To use a different scope, call NewClient using a WithScopes option (see https://godoc.org/google.golang.org/api/option#WithScopes).
func (*Client) CreateMetric ¶
CreateMetric creates a logs-based metric.
func (*Client) CreateSink ¶
CreateSink creates a Sink. It returns an error if the Sink already exists. Requires AdminScope.
func (*Client) DeleteLog ¶
DeleteLog deletes a log and all its log entries. The log will reappear if it receives new entries. logID identifies the log within the project. An example log ID is "syslog". Requires AdminScope.
func (*Client) DeleteMetric ¶
DeleteMetric deletes a log-based metric. The provided metric ID is the metric identifier. For example, "severe_errors".
func (*Client) DeleteSink ¶
DeleteSink deletes a sink. The provided sinkID is the sink's identifier, such as "my-severe-errors-to-pubsub". Requires AdminScope.
func (*Client) Entries ¶
func (c *Client) Entries(ctx context.Context, opts ...EntriesOption) *EntryIterator
Entries returns an EntryIterator for iterating over log entries. By default, the log entries will be restricted to those from the project passed to NewClient. This may be overridden by passing a ProjectIDs option. Requires ReadScope or AdminScope.
func (*Client) Logs ¶ added in v0.8.0
func (c *Client) Logs(ctx context.Context) *LogIterator
Logs lists the logs owned by the parent resource of the client.
func (*Client) Metric ¶
Metric gets a logs-based metric. The provided metric ID is the metric identifier. For example, "severe_errors". Requires ReadScope or AdminScope.
func (*Client) Metrics ¶
func (c *Client) Metrics(ctx context.Context) *MetricIterator
Metrics returns a MetricIterator for iterating over all Metrics in the Client's project. Requires ReadScope or AdminScope.
func (*Client) ResourceDescriptors ¶
func (c *Client) ResourceDescriptors(ctx context.Context) *ResourceDescriptorIterator
ResourceDescriptors returns a ResourceDescriptorIterator for iterating over MonitoredResourceDescriptors. Requires ReadScope or AdminScope. See https://cloud.google.com/logging/docs/api/v2/#monitored-resources for an explanation of monitored resources. See https://cloud.google.com/logging/docs/api/v2/resource-list for a list of monitored resources.
func (*Client) Sink ¶
Sink gets a sink. The provided sinkID is the sink's identifier, such as "my-severe-errors-to-pubsub". Requires ReadScope or AdminScope.
func (*Client) Sinks ¶
func (c *Client) Sinks(ctx context.Context) *SinkIterator
Sinks returns a SinkIterator for iterating over all Sinks in the Client's project. Requires ReadScope or AdminScope.
func (*Client) UpdateMetric ¶
UpdateMetric creates a logs-based metric if it does not exist, or updates an existing one.
type EntriesOption ¶
type EntriesOption interface {
// contains filtered or unexported methods
}
An EntriesOption is an option for listing log entries.
func Filter ¶
func Filter(f string) EntriesOption
Filter sets an advanced logs filter for listing log entries (see https://cloud.google.com/logging/docs/view/advanced_filters). The filter is compared against all log entries in the projects specified by ProjectIDs. Only entries that match the filter are retrieved. An empty filter (the default) matches all log entries.
In the filter string, log names must be written in their full form, as "projects/PROJECT-ID/logs/LOG-ID". Forward slashes in LOG-ID must be replaced by %2F before calling Filter.
Timestamps in the filter string must be written in RFC 3339 format. See the timestamp example.
func NewestFirst ¶
func NewestFirst() EntriesOption
NewestFirst causes log entries to be listed from most recent (newest) to least recent (oldest). By default, they are listed from oldest to newest.
func ProjectIDs ¶
func ProjectIDs(pids []string) EntriesOption
ProjectIDs sets the project IDs or project numbers from which to retrieve log entries. Examples of a project ID: "my-project-1A", "1234567890".
func ResourceNames ¶ added in v0.18.0
func ResourceNames(rns []string) EntriesOption
ResourceNames sets the resource names from which to retrieve log entries. Examples: "projects/my-project-1A", "organizations/my-org".
type EntryIterator ¶
type EntryIterator struct {
// contains filtered or unexported fields
}
An EntryIterator iterates over log entries.
func (*EntryIterator) Next ¶
func (it *EntryIterator) Next() (*logging.Entry, error)
Next returns the next result. Its second return value is iterator.Done (https://godoc.org/google.golang.org/api/iterator) if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*EntryIterator) PageInfo ¶
func (it *EntryIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See https://godoc.org/google.golang.org/api/iterator package for details.
type LogIterator ¶ added in v0.8.0
type LogIterator struct {
// contains filtered or unexported fields
}
A LogIterator iterates over logs.
func (*LogIterator) Next ¶ added in v0.8.0
func (it *LogIterator) Next() (string, error)
Next returns the next result. Its second return value is iterator.Done (https://godoc.org/google.golang.org/api/iterator) if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*LogIterator) PageInfo ¶ added in v0.8.0
func (it *LogIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See https://godoc.org/google.golang.org/api/iterator package for details.
type Metric ¶
type Metric struct { // ID is a client-assigned metric identifier. Example: // "severe_errors". Metric identifiers are limited to 1000 // characters and can include only the following characters: A-Z, // a-z, 0-9, and the special characters _-.,+!*',()%/\. The // forward-slash character (/) denotes a hierarchy of name pieces, // and it cannot be the first character of the name. ID string // Description describes this metric. It is used in documentation. Description string // Filter is an advanced logs filter (see // https://cloud.google.com/logging/docs/view/advanced_filters). // Example: "logName:syslog AND severity>=ERROR". Filter string }
Metric describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter.
Metrics are a feature of Stackdriver Monitoring. See https://cloud.google.com/monitoring/api/v3/metrics for more about them.
type MetricIterator ¶
type MetricIterator struct {
// contains filtered or unexported fields
}
A MetricIterator iterates over Metrics.
func (*MetricIterator) Next ¶
func (it *MetricIterator) Next() (*Metric, error)
Next returns the next result. Its second return value is Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*MetricIterator) PageInfo ¶
func (it *MetricIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type ResourceDescriptorIterator ¶
type ResourceDescriptorIterator struct {
// contains filtered or unexported fields
}
ResourceDescriptorIterator is an iterator over MonitoredResourceDescriptors.
func (*ResourceDescriptorIterator) Next ¶
func (it *ResourceDescriptorIterator) Next() (*mrpb.MonitoredResourceDescriptor, error)
Next returns the next result. Its second return value is Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*ResourceDescriptorIterator) PageInfo ¶
func (it *ResourceDescriptorIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type Sink ¶
type Sink struct { // ID is a client-assigned sink identifier. Example: // "my-severe-errors-to-pubsub". // Sink identifiers are limited to 1000 characters // and can include only the following characters: A-Z, a-z, // 0-9, and the special characters "_-.". ID string // Destination is the export destination. See // https://cloud.google.com/logging/docs/api/tasks/exporting-logs. // Examples: "storage.googleapis.com/a-bucket", // "bigquery.googleapis.com/projects/a-project-id/datasets/a-dataset". Destination string // Filter optionally specifies an advanced logs filter (see // https://cloud.google.com/logging/docs/view/advanced_filters) that // defines the log entries to be exported. Example: "logName:syslog AND // severity>=ERROR". If omitted, all entries are returned. Filter string }
Sink describes a sink used to export log entries outside Stackdriver Logging. Incoming log entries matching a filter are exported to a destination (a Cloud Storage bucket, BigQuery dataset or Cloud Pub/Sub topic).
For more information, see https://cloud.google.com/logging/docs/export/using_exported_logs. (The Sinks in this package are what the documentation refers to as "project sinks".)
type SinkIterator ¶
type SinkIterator struct {
// contains filtered or unexported fields
}
A SinkIterator iterates over Sinks.
func (*SinkIterator) Next ¶
func (it *SinkIterator) Next() (*Sink, error)
Next returns the next result. Its second return value is Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*SinkIterator) PageInfo ¶
func (it *SinkIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.