InitConfigAndLogger initializes the configuration and sets up the logger. We allow continuing with the initialization process even if the config file loading fails. In this situation, the default config flag values are used to tweak any of the internal behaviours.
(cfg *config.Config)
| 30 | // loading fails. In this situation, the default config flag values are used |
| 31 | // to tweak any of the internal behaviours. |
| 32 | func InitConfigAndLogger(cfg *config.Config) error { |
| 33 | err := cfg.TryLoadFile(cfg.File()) |
| 34 | notExists := os.IsNotExist(err) |
| 35 | if err != nil && !notExists { |
| 36 | return err |
| 37 | } |
| 38 | if err := cfg.Init(); err != nil { |
| 39 | return err |
| 40 | } |
| 41 | if err == nil { |
| 42 | if err := cfg.Validate(); err != nil { |
| 43 | return err |
| 44 | } |
| 45 | } |
| 46 | if err := log.InitFromConfig(cfg.Log, "fibratus.log"); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | if notExists { |
| 50 | logrus.Infof("configuration file "+ |
| 51 | "%s not found. Continuing with default "+ |
| 52 | "settings...", cfg.File()) |
| 53 | } |
| 54 | return nil |
| 55 | } |
no test coverage detected