options.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package log
  2. import "time"
  3. // Option used by the logger
  4. type Option func(*Options)
  5. // Options are logger options
  6. type Options struct {
  7. // Name of the log
  8. Name string
  9. // Size is the size of ring buffer
  10. Size int
  11. // Format specifies the output format
  12. Format FormatFunc
  13. }
  14. // Name of the log
  15. func Name(n string) Option {
  16. return func(o *Options) {
  17. o.Name = n
  18. }
  19. }
  20. // Size sets the size of the ring buffer
  21. func Size(s int) Option {
  22. return func(o *Options) {
  23. o.Size = s
  24. }
  25. }
  26. func Format(f FormatFunc) Option {
  27. return func(o *Options) {
  28. o.Format = f
  29. }
  30. }
  31. // DefaultOptions returns default options
  32. func DefaultOptions() Options {
  33. return Options{
  34. Size: DefaultSize,
  35. }
  36. }
  37. // ReadOptions for querying the logs
  38. type ReadOptions struct {
  39. // Since what time in past to return the logs
  40. Since time.Time
  41. // Count specifies number of logs to return
  42. Count int
  43. // Stream requests continuous log stream
  44. Stream bool
  45. }
  46. // ReadOption used for reading the logs
  47. type ReadOption func(*ReadOptions)
  48. // Since sets the time since which to return the log records
  49. func Since(s time.Time) ReadOption {
  50. return func(o *ReadOptions) {
  51. o.Since = s
  52. }
  53. }
  54. // Count sets the number of log records to return
  55. func Count(c int) ReadOption {
  56. return func(o *ReadOptions) {
  57. o.Count = c
  58. }
  59. }