Documentation
¶
Overview ¶
Package projectlog searches, tails and counts a project's runtime logs across its functions, frontends or databases, with the filters the log routes share.
Index ¶
- Constants
- Variables
- func BuildQuery(filters Filters) string
- type Filters
- type Selector
- type Service
- func (s Service) Activity(ctx context.Context, query api.LogQuery, buckets int) (*apiclient.LogActivityResponse, error)
- func (s Service) Each(ctx context.Context, query api.LogQuery, limit int, ...) (bool, error)
- func (s Service) Query(ctx context.Context, selector Selector, filters Filters) (api.LogQuery, error)
- func (s Service) Search(ctx context.Context, query api.LogQuery, limit int, cursor string) (*apiclient.LogSearchResponse, error)
- func (s Service) Stream(ctx context.Context, query api.LogQuery, limit int, lastEventID string) (*api.ProjectLogStream, error)
Constants ¶
const ( TypeFunction = "function" TypeFrontend = "frontend" TypeDatabase = "database" )
Resource types a log read selects, as the API names them.
const ( KindStandard = "standard" KindDurable = "durable" )
Function kinds a function log read can narrow to.
const MaxPage = 1000
MaxPage is the API's largest log search page, and the most recent logs a tail can start with.
Variables ¶
var Levels = []string{"trace", "debug", "info", "warn", "error", "fatal"}
Levels are the log levels the API records, lowest first.
Functions ¶
func BuildQuery ¶
BuildQuery joins the free-text query and the field filters into one log query. Terms are ANDed, and the free-text query is parenthesized so an OR in it cannot swallow a filter.
Types ¶
type Filters ¶
type Filters struct {
// Query is a log query, such as `timeout OR "connection reset"`.
Query string
Level string
Region string
Invocation string
Start *time.Time
End *time.Time
}
Filters narrow a read the same way on every log route.
type Selector ¶
type Selector struct {
Type string
// Kind narrows functions to standard or durable ones; empty reads both.
Kind string
// Names are resource names or IDs. Databases are named only by name.
Names []string
}
Selector chooses whose logs to read: every resource of one type, or the named ones.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service reads the current project's logs.
func NewService ¶
func NewService(deps cliruntime.Deps) Service
NewService returns a project log service.
func (Service) Activity ¶
func (s Service) Activity(ctx context.Context, query api.LogQuery, buckets int) (*apiclient.LogActivityResponse, error)
Activity returns bucketed counts of matching logs.
func (Service) Each ¶
func (s Service) Each(ctx context.Context, query api.LogQuery, limit int, visit func([]apiclient.LogSearchEvent) error) (bool, error)
Each pages through matching logs, newest first, handing each page to visit until limit logs have been visited or none remain. It reports whether more may match than were visited.
A page can hold fewer logs than asked for, or none, while more remain, so paging stops on the API's has_more rather than on a short page.
func (Service) Query ¶
func (s Service) Query(ctx context.Context, selector Selector, filters Filters) (api.LogQuery, error)
Query checks the selector and filters, resolves each name to its ID, and returns the read they describe.