github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csconfig/common.go (about)

     1  package csconfig
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	log "github.com/sirupsen/logrus"
     8  )
     9  
    10  /*daemonization/service related stuff*/
    11  type CommonCfg struct {
    12  	Daemonize      bool
    13  	PidDir         string     `yaml:"pid_dir,omitempty"` // TODO: This is just for backward compat. Remove this later
    14  	LogMedia       string     `yaml:"log_media"`
    15  	LogDir         string     `yaml:"log_dir,omitempty"` //if LogMedia = file
    16  	LogLevel       *log.Level `yaml:"log_level"`
    17  	WorkingDir     string     `yaml:"working_dir,omitempty"` // TODO: This is just for backward compat. Remove this later
    18  	CompressLogs   *bool      `yaml:"compress_logs,omitempty"`
    19  	LogMaxSize     int        `yaml:"log_max_size,omitempty"`
    20  	LogMaxAge      int        `yaml:"log_max_age,omitempty"`
    21  	LogMaxFiles    int        `yaml:"log_max_files,omitempty"`
    22  	ForceColorLogs bool       `yaml:"force_color_logs,omitempty"`
    23  }
    24  
    25  func (c *Config) loadCommon() error {
    26  	var err error
    27  	if c.Common == nil {
    28  		c.Common = &CommonCfg{}
    29  	}
    30  
    31  	if c.Common.LogMedia == "" {
    32  		c.Common.LogMedia = "stdout"
    33  	}
    34  
    35  	var CommonCleanup = []*string{
    36  		&c.Common.LogDir,
    37  	}
    38  	for _, k := range CommonCleanup {
    39  		if *k == "" {
    40  			continue
    41  		}
    42  		*k, err = filepath.Abs(*k)
    43  		if err != nil {
    44  			return fmt.Errorf("failed to get absolute path of '%s': %w", *k, err)
    45  		}
    46  	}
    47  
    48  	return nil
    49  }