package loggerconfig import ( "os" "time" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "git.frostfs.info/TrueCloudLab/frostfs-observability/logging/lokicore/loki" ) const ( // LevelDefault is a default logger level. LevelDefault = "info" DestinationDefault = logger.DestinationStdout subsection = "logger" lokiSubsection = "loki" AddressDefault = "localhost:3100" BatchEntriesNumberDefault = 100 BatchWaitDefault = time.Second ) // Level returns the value of "level" config parameter // from "logger" section. // // Returns LevelDefault if the value is not a non-empty string. func Level(c *config.Config) string { v := config.StringSafe( c.Sub(subsection), "level", ) if v != "" { return v } return LevelDefault } // Destination returns the value of "destination" config parameter // from "logger" section. // // Returns DestinationDefault if the value is not a non-empty string. func Destination(c *config.Config) string { v := config.StringSafe( c.Sub(subsection), "destination", ) if v != "" { return v } return DestinationDefault } // ToLokiConfig extracts loki config. func ToLokiConfig(c *config.Config) loki.Config { hostname, _ := os.Hostname() return loki.Config{ Enabled: config.BoolSafe(c.Sub(subsection).Sub(lokiSubsection), "enabled"), BatchWait: getBatchWait(c), BatchEntriesNumber: getBatchEntriesNumber(c), Endpoint: getEndpoint(c), Labels: map[string]string{ "hostname": hostname, }, } } func getBatchWait(c *config.Config) time.Duration { v := config.DurationSafe(c.Sub(subsection).Sub(lokiSubsection), "max_batch_delay") if v > 0 { return v } return BatchWaitDefault } func getBatchEntriesNumber(c *config.Config) int { v := config.IntSafe(c.Sub(subsection).Sub(lokiSubsection), "max_batch_size") if v > 0 { return int(v) } return BatchEntriesNumberDefault } func getEndpoint(c *config.Config) string { v := config.StringSafe(c.Sub(subsection).Sub(lokiSubsection), "endpoint") if v != "" { return v } return AddressDefault }