github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/logger/local/config.go (about)

     1  package local
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  )
     6  
     7  // CreateConfig is used to configure new instances of driver
     8  type CreateConfig struct {
     9  	DisableCompression bool
    10  	MaxFileSize        int64
    11  	MaxFileCount       int
    12  }
    13  
    14  func newDefaultConfig() *CreateConfig {
    15  	return &CreateConfig{
    16  		MaxFileSize:        defaultMaxFileSize,
    17  		MaxFileCount:       defaultMaxFileCount,
    18  		DisableCompression: !defaultCompressLogs,
    19  	}
    20  }
    21  
    22  func validateConfig(cfg *CreateConfig) error {
    23  	if cfg.MaxFileSize < 0 {
    24  		return errors.New("max size should be a positive number")
    25  	}
    26  	if cfg.MaxFileCount < 0 {
    27  		return errors.New("max file count cannot be less than 0")
    28  	}
    29  
    30  	if !cfg.DisableCompression {
    31  		if cfg.MaxFileCount <= 1 {
    32  			return errors.New("compression cannot be enabled when max file count is 1")
    33  		}
    34  	}
    35  	return nil
    36  }