Skip to content

Commit 0e84a7a

Browse files
committed
log,logflags: allow seeding test log config from env
This makes it easier to apply a custom config to various test invocations without having to juggle flags. Many KV-specific logs are not included by default, so they're not in `-show-logs`, which can be annoying.
1 parent 9bcc3fd commit 0e84a7a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pkg/util/log/flags.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,22 @@ const redactionPolicyManagedEnvVar = "COCKROACH_REDACTION_POLICY_MANAGED"
5656

5757
var RedactionPolicyManaged = envutil.EnvOrDefaultBool(redactionPolicyManagedEnvVar, false)
5858

59+
// testLogConfigEnvVar is the env var used to specify a custom YAML log configuration
60+
// for tests. This can be overridden by the -test-log-config command-line flag.
61+
//
62+
// Example: To show all log channels (including HEALTH, STORAGE, KV_DISTRIBUTION)
63+
// inline with -show-logs:
64+
//
65+
// export COCKROACH_TEST_LOG_CONFIG='sinks: {stderr: {channels: all, filter: INFO}}'
66+
const testLogConfigEnvVar = "COCKROACH_TEST_LOG_CONFIG"
67+
68+
var envTestLogConfig = envutil.EnvOrDefaultString(testLogConfigEnvVar, "")
69+
5970
func init() {
6071
logflags.InitFlags(
6172
&logging.showLogs,
6273
&logging.testLogConfig,
74+
envTestLogConfig, // default value
6375
&logging.vmoduleConfig.mu.vmodule,
6476
)
6577

pkg/util/log/logflags/logflags.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ const (
1616

1717
// InitFlags creates logging flags which update the given variables. The passed mutex is
1818
// locked while the boolean variables are accessed during flag updates.
19-
func InitFlags(showLogs *bool, testLogConfig *string, vmodule flag.Value) {
19+
func InitFlags(
20+
showLogs *bool, testLogConfig *string, testLogConfigDefault string, vmodule flag.Value,
21+
) {
2022
flag.Var(vmodule, VModuleName, "comma-separated list of pattern=N settings for file-filtered logging (significantly hurts performance)")
21-
flag.StringVar(testLogConfig, TestLogConfigName, "", "YAML log configuration for tests")
23+
flag.StringVar(testLogConfig, TestLogConfigName, testLogConfigDefault, "YAML log configuration for tests")
2224
flag.BoolVar(showLogs, ShowLogsName, *showLogs, "print logs instead of saving them in files")
2325
}

0 commit comments

Comments
 (0)