SetUpGlobalTestLogging sets a global log level at runtime by using the SG_TEST_LOG_LEVEL environment variable. This global level overrides any tests that specify their own test log level with SetUpTestLogging.
(ctx context.Context)
| 564 | // SetUpGlobalTestLogging sets a global log level at runtime by using the SG_TEST_LOG_LEVEL environment variable. |
| 565 | // This global level overrides any tests that specify their own test log level with SetUpTestLogging. |
| 566 | func SetUpGlobalTestLogging(ctx context.Context) (teardownFn func()) { |
| 567 | if logLevel := os.Getenv(TestEnvGlobalLogLevel); logLevel != "" { |
| 568 | var l LogLevel |
| 569 | err := l.UnmarshalText([]byte(logLevel)) |
| 570 | if err != nil { |
| 571 | FatalfCtx(ctx, "TEST: Invalid log level used for %q: %s", TestEnvGlobalLogLevel, err) |
| 572 | } |
| 573 | caller := GetCallersName(1, false) |
| 574 | InfofCtx(context.Background(), KeyAll, "%s: Setup logging: level: %v - keys: %v", caller, logLevel, KeyAll) |
| 575 | teardown := setTestLogging(l, caller, KeyAll) |
| 576 | GlobalTestLoggingSet.Set(true) |
| 577 | return func() { |
| 578 | teardown() |
| 579 | GlobalTestLoggingSet.Set(false) |
| 580 | } |
| 581 | } |
| 582 | // noop |
| 583 | return func() { GlobalTestLoggingSet.Set(false) } |
| 584 | } |
| 585 | |
| 586 | // SetUpTestLogging will set the given log level and log keys, and revert the changes at the end of the current test. |
| 587 | // |