Be able to build the logger on windows (#596)

Seems like provider can build for windows for the kairosctl command and
it would fail due to the systemd libs not being available to build under
windows so we need to protect against that

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka
2025-05-06 11:19:17 +02:00
committed by GitHub
parent 040a722e24
commit 571996d6ba
3 changed files with 39 additions and 14 deletions

View File

@@ -4,25 +4,14 @@ import (
"bytes"
"fmt"
"io"
"net"
"os"
"path/filepath"
"strings"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/journald"
)
func isJournaldAvailable() bool {
conn, err := net.Dial("unixgram", "/run/systemd/journal/socket")
if err != nil {
return false
}
defer conn.Close()
return true
}
// NewKairosLogger creates a new logger with the given name and level.
// The level is used to set the log level, defaulting to info
// The log level can be overridden by setting the environment variable $NAME_DEBUG to any parseable value.
@@ -32,9 +21,9 @@ func NewKairosLogger(name, level string, quiet bool) KairosLogger {
var l zerolog.Level
var err error
// Add journald logger
if isJournaldAvailable() {
loggers = append(loggers, journald.NewJournalDWriter())
// Add journald logger if available
if writer := getJournaldWriter(); writer != nil {
loggers = append(loggers, writer)
} else {
// Default to file logging
logName := fmt.Sprintf("%s.log", name)