From b3edc9d360c6a721e484b96ca8be4ba0454f18b4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 20 Jul 2024 12:10:42 +0100 Subject: [PATCH] fs: fix --use-json-log and -vv after config reorganization --- cmdtest/environment_test.go | 21 +++++++++++++++++++++ fs/config/configflags/configflags.go | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/cmdtest/environment_test.go b/cmdtest/environment_test.go index 5a56a692a..3f1ad8035 100644 --- a/cmdtest/environment_test.go +++ b/cmdtest/environment_test.go @@ -323,4 +323,25 @@ func TestEnvironmentVariables(t *testing.T) { assert.NotContains(t, out, "fileB1.txt") } + // Test --use-json-log and -vv combinations + jsonLogOK := func() { + t.Helper() + if assert.NoError(t, err) { + assert.Contains(t, out, `{"level":"debug",`) + assert.Contains(t, out, `"msg":"Version `) + assert.Contains(t, out, `"}`) + } + } + env = "RCLONE_USE_JSON_LOG=1;RCLONE_LOG_LEVEL=DEBUG" + out, err = rcloneEnv(env, "version") + jsonLogOK() + env = "RCLONE_USE_JSON_LOG=1" + out, err = rcloneEnv(env, "version", "-vv") + jsonLogOK() + env = "RCLONE_LOG_LEVEL=DEBUG" + out, err = rcloneEnv(env, "version", "--use-json-log") + jsonLogOK() + env = "" + out, err = rcloneEnv(env, "version", "-vv", "--use-json-log") + jsonLogOK() } diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.go index 056c0d9d2..d3beb9a3e 100644 --- a/fs/config/configflags/configflags.go +++ b/fs/config/configflags/configflags.go @@ -4,6 +4,7 @@ package configflags // Options set by command line flags import ( + "context" "log" "net" "os" @@ -202,6 +203,11 @@ func SetFlags(ci *fs.ConfigInfo) { // Process --multi-thread-streams - set whether multi-thread-streams was set multiThreadStreamsFlag := pflag.Lookup("multi-thread-streams") ci.MultiThreadSet = multiThreadStreamsFlag != nil && multiThreadStreamsFlag.Changed + + // Reload any changes + if err := ci.Reload(context.Background()); err != nil { + log.Fatalf("Failed to reload config changes: %v", err) + } } // parseHeaders converts DSCP names to value