-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
59 lines (49 loc) · 1.43 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package panyl
import "context"
const (
PostProcessOrderFirst = 0
PostProcessOrderLast = 10
PostProcessOrderDefault = 5
)
type Option func(p *Processor)
type JobOption func(p *Job)
// WithLineLimit outputs only starting from startLine up to the lineAmount amount of lines.
func WithLineLimit(startLine, lineAmount int) JobOption {
return func(p *Job) {
p.StartLine = startLine
p.LineAmount = lineAmount
}
}
// WithMaxBacklogLines sets the maximum amount of unprocessed lines to try until giving up.
// This is used to detect multiline logs.
func WithMaxBacklogLines(maxBacklogLines int) JobOption {
return func(p *Job) {
p.MaxBacklogLines = maxBacklogLines
}
}
// WithIncludeSource sets whether to set Item.Source with the source line.
func WithIncludeSource(includeSource bool) JobOption {
return func(p *Job) {
p.IncludeSource = includeSource
}
}
// WithDebugLog sets a DebugLog to be used for debugging.
func WithDebugLog(logger DebugLog) Option {
return func(p *Processor) {
p.DebugLog = logger
}
}
// WithPlugins adds Plugin instances to be registered.
func WithPlugins(plugin ...Plugin) Option {
return func(p *Processor) {
for _, pl := range plugin {
p.RegisterPlugin(pl)
}
}
}
// WithOnJobFinished sets a callback to be called when a Job is about to finish.
func WithOnJobFinished(f func(context.Context, *Job) error) Option {
return func(p *Processor) {
p.onJobFinished = append(p.onJobFinished, f)
}
}