build: update logging statements to make json log work - fixes #6038

This changes log statements from log to fs package, which is required for --use-json-log
to properly make log output in JSON format. The recently added custom linting rule,
handled by ruleguard via gocritic via golangci-lint, warns about these and suggests
the alternative. Fixing was therefore basically running "golangci-lint run --fix",
although some manual fixup of mainly imports are necessary following that.
This commit is contained in:
albertony
2024-09-06 17:04:18 +01:00
committed by Nick Craig-Wood
parent 88b0757288
commit bcdfad3c83
64 changed files with 333 additions and 357 deletions
+2 -2
View File
@@ -144,7 +144,7 @@ func InitLogging() {
if Opt.File != "" {
f, err := os.OpenFile(Opt.File, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
if err != nil {
log.Fatalf("Failed to open log file: %v", err)
fs.Fatalf(nil, "Failed to open log file: %v", err)
}
_, err = f.Seek(0, io.SeekEnd)
if err != nil {
@@ -158,7 +158,7 @@ func InitLogging() {
// Syslog output
if Opt.UseSyslog {
if Opt.File != "" {
log.Fatalf("Can't use --syslog and --log-file together")
fs.Fatalf(nil, "Can't use --syslog and --log-file together")
}
startSysLog()
}
+3 -3
View File
@@ -5,9 +5,9 @@
package log
import (
"log"
"os"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config"
"golang.org/x/sys/unix"
)
@@ -16,11 +16,11 @@ import (
func redirectStderr(f *os.File) {
passPromptFd, err := unix.Dup(int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to duplicate stderr: %v", err)
fs.Fatalf(nil, "Failed to duplicate stderr: %v", err)
}
config.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt")
err = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err)
fs.Fatalf(nil, "Failed to redirect stderr to file: %v", err)
}
}
+3 -2
View File
@@ -9,9 +9,10 @@
package log
import (
"log"
"os"
"syscall"
"github.com/rclone/rclone/fs"
)
var (
@@ -34,6 +35,6 @@ func setStdHandle(stdhandle int32, handle syscall.Handle) error {
func redirectStderr(f *os.File) {
err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err)
fs.Fatalf(nil, "Failed to redirect stderr to file: %v", err)
}
}
+3 -2
View File
@@ -5,12 +5,13 @@
package log
import (
"log"
"runtime"
"github.com/rclone/rclone/fs"
)
// Starts syslog if configured, returns true if it was started
func startSysLog() bool {
log.Fatalf("--syslog not supported on %s platform", runtime.GOOS)
fs.Fatalf(nil, "--syslog not supported on %s platform", runtime.GOOS)
return false
}
+2 -2
View File
@@ -42,12 +42,12 @@ var (
func startSysLog() bool {
facility, ok := syslogFacilityMap[Opt.SyslogFacility]
if !ok {
log.Fatalf("Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility)
fs.Fatalf(nil, "Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility)
}
Me := path.Base(os.Args[0])
w, err := syslog.New(syslog.LOG_NOTICE|facility, Me)
if err != nil {
log.Fatalf("Failed to start syslog: %v", err)
fs.Fatalf(nil, "Failed to start syslog: %v", err)
}
log.SetFlags(0)
log.SetOutput(w)
+3 -2
View File
@@ -5,13 +5,14 @@
package log
import (
"log"
"runtime"
"github.com/rclone/rclone/fs"
)
// Enables systemd logs if configured or if auto-detected
func startSystemdLog() bool {
log.Fatalf("--log-systemd not supported on %s platform", runtime.GOOS)
fs.Fatalf(nil, "--log-systemd not supported on %s platform", runtime.GOOS)
return false
}