summaryrefslogtreecommitdiffstats
path: root/pkg/config/logging.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:40:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:40:59 +0000
commitbc4e624732bd51c0dd1e9529cf228e8c23127732 (patch)
treed95dab8960e9d02d3b95f8653074ad2e54ca207c /pkg/config/logging.go
parentInitial commit. (diff)
downloadicingadb-bc4e624732bd51c0dd1e9529cf228e8c23127732.tar.xz
icingadb-bc4e624732bd51c0dd1e9529cf228e8c23127732.zip
Adding upstream version 1.1.1.upstream/1.1.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pkg/config/logging.go')
-rw-r--r--pkg/config/logging.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/config/logging.go b/pkg/config/logging.go
new file mode 100644
index 0000000..9ccd35e
--- /dev/null
+++ b/pkg/config/logging.go
@@ -0,0 +1,44 @@
+package config
+
+import (
+ "github.com/icinga/icingadb/pkg/logging"
+ "github.com/pkg/errors"
+ "go.uber.org/zap/zapcore"
+ "os"
+ "time"
+)
+
+// Logging defines Logger configuration.
+type Logging struct {
+ // zapcore.Level at 0 is for info level.
+ Level zapcore.Level `yaml:"level" default:"0"`
+ Output string `yaml:"output"`
+ // Interval for periodic logging.
+ Interval time.Duration `yaml:"interval" default:"20s"`
+
+ logging.Options `yaml:"options"`
+}
+
+// Validate checks constraints in the supplied Logging configuration and returns an error if they are violated.
+// Also configures the log output if it is not configured:
+// systemd-journald is used when Icinga DB is running under systemd, otherwise stderr.
+func (l *Logging) Validate() error {
+ if l.Interval <= 0 {
+ return errors.New("periodic logging interval must be positive")
+ }
+
+ if l.Output == "" {
+ if _, ok := os.LookupEnv("NOTIFY_SOCKET"); ok {
+ // When started by systemd, NOTIFY_SOCKET is set by systemd for Type=notify supervised services,
+ // which is the default setting for the Icinga DB service.
+ // This assumes that Icinga DB is running under systemd, so set output to systemd-journald.
+ l.Output = logging.JOURNAL
+ } else {
+ // Otherwise set it to console, i.e. write log messages to stderr.
+ l.Output = logging.CONSOLE
+ }
+ }
+
+ // To be on the safe side, always call AssertOutput.
+ return logging.AssertOutput(l.Output)
+}