github.com/annwntech/go-micro/v2@v2.9.5/debug/log/options.go (about)

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