2019-11-27 19:02:16 +03:00
|
|
|
package log
|
|
|
|
|
2019-11-27 20:31:35 +03:00
|
|
|
import "time"
|
|
|
|
|
2019-11-27 19:02:16 +03:00
|
|
|
// Option used by the logger
|
|
|
|
type Option func(*Options)
|
|
|
|
|
|
|
|
// Options are logger options
|
|
|
|
type Options struct {
|
2019-12-17 18:46:09 +03:00
|
|
|
// Name of the log
|
|
|
|
Name string
|
2019-11-27 19:02:16 +03:00
|
|
|
// Size is the size of ring buffer
|
|
|
|
Size int
|
|
|
|
}
|
|
|
|
|
2019-12-17 18:46:09 +03:00
|
|
|
// Name of the log
|
|
|
|
func Name(n string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Name = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:02:16 +03:00
|
|
|
// Size sets the size of the ring buffer
|
|
|
|
func Size(s int) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Size = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultOptions returns default options
|
|
|
|
func DefaultOptions() Options {
|
|
|
|
return Options{
|
|
|
|
Size: DefaultSize,
|
|
|
|
}
|
|
|
|
}
|
2019-11-27 20:31:35 +03:00
|
|
|
|
|
|
|
// ReadOptions for querying the logs
|
|
|
|
type ReadOptions struct {
|
|
|
|
// Since what time in past to return the logs
|
|
|
|
Since time.Time
|
|
|
|
// Count specifies number of logs to return
|
|
|
|
Count int
|
2019-11-28 21:08:48 +03:00
|
|
|
// Stream requests continuous log stream
|
|
|
|
Stream bool
|
2019-11-27 20:31:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadOption used for reading the logs
|
|
|
|
type ReadOption func(*ReadOptions)
|
|
|
|
|
|
|
|
// Since sets the time since which to return the log records
|
|
|
|
func Since(s time.Time) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Since = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count sets the number of log records to return
|
|
|
|
func Count(c int) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Count = c
|
|
|
|
}
|
|
|
|
}
|