github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/log/testshout/shout_test.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package testshout 12 13 import ( 14 "context" 15 "flag" 16 "os" 17 18 "github.com/cockroachdb/cockroach/pkg/util/log" 19 "github.com/cockroachdb/cockroach/pkg/util/log/logflags" 20 ) 21 22 // Example_shout_before_log verifies that Shout output emitted after 23 // the log flags were set, but before the first log message was 24 // output, properly appears on stderr. 25 // 26 // This test needs to occur in its own test package where there is no 27 // other activity on the log flags, and no other log activity, 28 // otherwise the test's behavior will break on `make stress`. 29 func Example_shout_before_log() { 30 origStderr := log.OrigStderr 31 log.OrigStderr = os.Stdout 32 defer func() { log.OrigStderr = origStderr }() 33 34 if err := flag.Set(logflags.LogToStderrName, "WARNING"); err != nil { 35 panic(err) 36 } 37 if err := flag.Set(logflags.NoRedirectStderrName, "false"); err != nil { 38 panic(err) 39 } 40 41 log.Shout(context.Background(), log.Severity_INFO, "hello world") 42 43 // output: 44 // * 45 // * INFO: hello world 46 // * 47 }