Documentation
¶
Overview ¶
Package cloudlogging is the Cloud Logging emulation.
It exists for the one thing you cannot do against a real project locally: assert on what your code logged. A service writes structured entries with WriteLogEntries; a test (or gcloud) reads them back with ListLogEntries and a filter. "When a payment fails, does an ERROR entry carry the order id?" is a real thing to test, and this is where that entry lands.
Index ¶
- Constants
- type Service
- func (s *Service) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest) (*emptypb.Empty, error)
- func (s *Service) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest) (*loggingpb.ListLogEntriesResponse, error)
- func (s *Service) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest) (*loggingpb.ListLogsResponse, error)
- func (s *Service) Reset(ctx context.Context, project string) error
- func (s *Service) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) (*loggingpb.WriteLogEntriesResponse, error)
Constants ¶
const MaxEntries = 10000
MaxEntries is how many entries are kept. Enough to assert on a test's output, small enough that a loop logging forever cannot exhaust memory.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
loggingpb.UnimplementedLoggingServiceV2Server
// contains filtered or unexported fields
}
Service holds log entries in memory.
In memory rather than the KV store: logs are append-heavy and read by query, not by key, and a local run keeps few enough that a bounded slice is simpler than a key layout. The bound keeps a chatty service from growing without end.
func (*Service) DeleteLog ¶
func (s *Service) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest) (*emptypb.Empty, error)
DeleteLog drops every entry for one log name.
func (*Service) ListLogEntries ¶
func (s *Service) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest) (*loggingpb.ListLogEntriesResponse, error)
ListLogEntries returns matching entries. The default order is oldest first; "timestamp desc" reverses it, which is what a console tail asks for.
func (*Service) ListLogs ¶
func (s *Service) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest) (*loggingpb.ListLogsResponse, error)
ListLogs returns the distinct log names that have entries.
func (*Service) WriteLogEntries ¶
func (s *Service) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) (*loggingpb.WriteLogEntriesResponse, error)
WriteLogEntries appends entries, filling the timestamp and id the server stamps. A per-request LogName, Resource or Labels is the default for entries that omit their own, which is how the high-level client writes a batch.