mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-16 01:55:01 +03:00
refactor(logger): choose the console backend with build tags
The runtime.GOOS switch compiled the syslog branch into Windows builds, where go-logging's syslog stub always returns an error. staticcheck therefore reported SA4023 at logger.go:95 on every Windows lint run, keeping `make lint-go` red on a clean main there while Linux CI never saw it. console_windows.go and console_other.go now pick the backend at build time, with each platform's behaviour unchanged. No test can observe build-tag selection: `golangci-lint run` on Windows goes from 1 issue to 0, and `GOOS=linux golangci-lint run ./internal/logger/...` stays clean.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
//go:build !windows
|
||||
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
|
||||
// newConsoleBackend prefers syslog and falls back to stderr when it is unavailable.
|
||||
func newConsoleBackend() (backend logging.Backend, includeTime bool) {
|
||||
syslogBackend, err := logging.NewSyslogBackend("")
|
||||
if err == nil {
|
||||
return syslogBackend, false
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "syslog backend disabled: %v\n", err)
|
||||
return logging.NewLogBackend(os.Stderr, "", 0), os.Getppid() > 0
|
||||
}
|
||||
Reference in New Issue
Block a user