log: fix enabling systemd logging when using --log-file

This also moves all the systemd logging decisions to fs/log
This commit is contained in:
Nick Craig-Wood 2020-12-17 11:55:27 +00:00
parent 5ae5e1dd56
commit c98dd8755c
6 changed files with 61 additions and 53 deletions

View file

@ -21,7 +21,6 @@ import (
"sync"
"time"
systemd "github.com/iguanesolutions/go-systemd/v5"
"github.com/pkg/errors"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting"
@ -376,11 +375,6 @@ func StartStats() func() {
func initConfig() {
ctx := context.Background()
ci := fs.GetConfig(ctx)
// Activate logger systemd support if systemd invocation ID is detected
_, sysdLaunch := systemd.GetInvocationID()
if sysdLaunch {
ci.LogSystemdSupport = true // used during fslog.InitLogging()
}
// Start the logger
fslog.InitLogging()
@ -398,10 +392,8 @@ func initConfig() {
fs.Debugf("rclone", "Version %q starting with parameters %q", fs.Version, os.Args)
// Inform user about systemd log support now that we have a logger
if sysdLaunch {
fs.Debugf("rclone", "systemd logging support automatically activated")
} else if ci.LogSystemdSupport {
fs.Debugf("rclone", "systemd logging support manually activated")
if fslog.Opt.LogSystemdSupport {
fs.Debugf("rclone", "systemd logging support activated")
}
// Start the remote control server if configured