github.com/searKing/golang/go@v1.2.117/log/slog/rotate_options.go (about)

     1  // Code generated by "go-option -type rotate"; DO NOT EDIT.
     2  // Install go-option by "go get install github.com/searKing/golang/tools/go-option"
     3  
     4  package slog
     5  
     6  import "time"
     7  
     8  // A RotateOption sets options.
     9  type RotateOption interface {
    10  	apply(*rotate)
    11  }
    12  
    13  // EmptyRotateOption does not alter the configuration. It can be embedded
    14  // in another structure to build custom options.
    15  //
    16  // This API is EXPERIMENTAL.
    17  type EmptyRotateOption struct{}
    18  
    19  func (EmptyRotateOption) apply(*rotate) {}
    20  
    21  // RotateOptionFunc wraps a function that modifies rotate into an
    22  // implementation of the RotateOption interface.
    23  type RotateOptionFunc func(*rotate)
    24  
    25  func (f RotateOptionFunc) apply(do *rotate) {
    26  	f(do)
    27  }
    28  
    29  // ApplyOptions call apply() for all options one by one
    30  func (o *rotate) ApplyOptions(options ...RotateOption) *rotate {
    31  	for _, opt := range options {
    32  		if opt == nil {
    33  			continue
    34  		}
    35  		opt.apply(o)
    36  	}
    37  	return o
    38  }
    39  
    40  // withRotate sets rotate.
    41  func withRotate(v rotate) RotateOption {
    42  	return RotateOptionFunc(func(o *rotate) {
    43  		*o = v
    44  	})
    45  }
    46  
    47  // WithRotateFilePathRotateLayout sets FilePathRotateLayout in rotate.
    48  // Time layout to format rotate file
    49  func WithRotateFilePathRotateLayout(v string) RotateOption {
    50  	return RotateOptionFunc(func(o *rotate) {
    51  		o.FilePathRotateLayout = v
    52  	})
    53  }
    54  
    55  // WithRotateFileLinkPath sets FileLinkPath in rotate.
    56  // sets the symbolic link name that gets linked to the current file name being used.
    57  func WithRotateFileLinkPath(v string) RotateOption {
    58  	return RotateOptionFunc(func(o *rotate) {
    59  		o.FileLinkPath = v
    60  	})
    61  }
    62  
    63  // WithRotateRotateInterval sets RotateInterval in rotate.
    64  // Rotate files are rotated until RotateInterval expired before being removed
    65  // take effects if only RotateInterval is bigger than 0.
    66  func WithRotateRotateInterval(v time.Duration) RotateOption {
    67  	return RotateOptionFunc(func(o *rotate) {
    68  		o.RotateInterval = v
    69  	})
    70  }
    71  
    72  // WithRotateRotateSize sets RotateSize in rotate.
    73  // Rotate files are rotated if they grow bigger then size bytes.
    74  // take effects if only RotateSize is bigger than 0.
    75  func WithRotateRotateSize(v int64) RotateOption {
    76  	return RotateOptionFunc(func(o *rotate) {
    77  		o.RotateSize = v
    78  	})
    79  }
    80  
    81  // WithRotateMaxAge sets MaxAge in rotate.
    82  // max age of a log file before it gets purged from the file system.
    83  // Remove rotated logs older than duration. The age is only checked if the file is
    84  // to be rotated.
    85  // take effects if only MaxAge is bigger than 0.
    86  func WithRotateMaxAge(v time.Duration) RotateOption {
    87  	return RotateOptionFunc(func(o *rotate) {
    88  		o.MaxAge = v
    89  	})
    90  }
    91  
    92  // WithRotateMaxCount sets MaxCount in rotate.
    93  // Rotate files are rotated MaxCount times before being removed
    94  // take effects if only MaxCount is bigger than 0.
    95  func WithRotateMaxCount(v int) RotateOption {
    96  	return RotateOptionFunc(func(o *rotate) {
    97  		o.MaxCount = v
    98  	})
    99  }
   100  
   101  // WithRotateForceNewFileOnStartup sets ForceNewFileOnStartup in rotate.
   102  // Force File Rotate when start up
   103  func WithRotateForceNewFileOnStartup(v bool) RotateOption {
   104  	return RotateOptionFunc(func(o *rotate) {
   105  		o.ForceNewFileOnStartup = v
   106  	})
   107  }