Skip to content

Commit

Permalink
util/log: ensure that all channel logs are displayed with -show-logs
Browse files Browse the repository at this point in the history
When `-show-logs` is specified, the `log.Scope` becomes a no-op and
the default configuration in the `log` package is used. This is the
only time ever when the default configuration is used.

Prior to this patch, only the logging for the DEV channel would
make its way to the standard error (and the test output) in that
case. This was unfortunate, since the intent (as spelled out in a
comment already) was to display everything.

This patch fixes that.

Release justification: non-production code changes

Release note: None
  • Loading branch information
knz committed Mar 1, 2021
1 parent 6521a8e commit a3d35c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions pkg/util/log/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ func init() {
// Default stderrThreshold to log everything to the process'
// external stderr (OrigStderr).
defaultConfig.Sinks.Stderr.Filter = severity.INFO
// We only register it for the DEV channels. No other
// channels get a configuration, whereby every channel
// ends up sharing the DEV logger (debugLog).
defaultConfig.Sinks.Stderr.Channels.Channels = []logpb.Channel{channel.DEV}
// Ensure all channels go to stderr.
defaultConfig.Sinks.Stderr.Channels.Channels = logconfig.SelectAllChannels()
// We also don't capture internal writes to fd2 by default:
// let the writes go to the external stderr.
defaultConfig.CaptureFd2.Enable = false
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/log/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAppliedStandaloneConfig(t *testing.T) {

const expected = `sinks:
stderr:
channels: [DEV]
channels: all
filter: INFO
format: crdb-v2-tty
redact: false
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/log/logconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func parseChannelList(s string) ([]logpb.Channel, error) {

// Special case: "ALL" selects all channels.
if s == "ALL" {
return selectAllChannels(), nil
return SelectAllChannels(), nil
}

// If channels starts with "all except", we invert the selection.
Expand Down Expand Up @@ -597,7 +597,7 @@ func selectChannels(invert bool, parts []string) ([]logpb.Channel, error) {
if len(parts) != 1 {
return nil, errors.New("cannot use ALL if there are other channel names present in the list")
}
return selectAllChannels(), nil
return SelectAllChannels(), nil
}

// Verify the channel name is known.
Expand Down Expand Up @@ -636,9 +636,9 @@ func selectChannels(invert bool, parts []string) ([]logpb.Channel, error) {
return selected, nil
}

// selectAllChannels returns a copy of channelValues,
// SelectAllChannels returns a copy of channelValues,
// for use in the ALL configuration.
func selectAllChannels() []logpb.Channel {
func SelectAllChannels() []logpb.Channel {
// Copy the default in case the code that uses a Config overwrites
// its channel list in-place.
chans := make([]logpb.Channel, 0, len(channelValues))
Expand Down

0 comments on commit a3d35c8

Please sign in to comment.