Skip to content

Commit

Permalink
new parameter inside the test (test needs to be fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierluigi Lenoci committed Mar 10, 2021
1 parent 1d97b27 commit 6f2fbaa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
22 changes: 11 additions & 11 deletions integration_tests/klog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,31 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
"everything disabled": {
// Nothing, including the trace on fatal, is showing anywhere

flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=1000"},

notExpectedOnStderr: allLogREs,
},
"everything disabled but low stderrthreshold": {
// Everything above -stderrthreshold, including the trace on fatal, will
// be logged to stderr, even if we set -logtostderr to false.

flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1"},
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1", "-alsologtostderrthreshold=1"},

expectedOnStderr: res{warningLogRE, errorLogRE, stackTraceRE},
notExpectedOnStderr: res{infoLogRE},
},
"with logtostderr only": {
// Everything, including the trace on fatal, goes to stderr

flags: []string{"-logtostderr=true", "-alsologtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-logtostderr=true", "-alsologtostderr=false", "-stderrthreshold=0", "-alsologtostderrthreshold=1000"},

expectedOnStderr: allLogREs,
},
"with log file only": {
// Everything, including the trace on fatal, goes to the single log file

logfile: true,
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=1000"},

expectedLogFile: true,

Expand All @@ -133,7 +133,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
// Everything, including the trace on fatal, goes to the log files in the log dir

logdir: true,
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=1000"},

expectedLogDir: true,

Expand All @@ -145,7 +145,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
// Everything, including the trace on fatal, goes to the log files in the log dir

logdir: true,
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000", "-one_output=true"},
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=1000", "-one_output=true"},

expectedLogDir: true,

Expand All @@ -158,7 +158,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
// ignored, nothing goes to the log files in the log dir.

logdir: true,
flags: []string{"-logtostderr=true", "-alsologtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-logtostderr=true", "-alsologtostderr=false", "-stderrthreshold=0", "-alsologtostderrthreshold=1000"},

expectedOnStderr: allLogREs,
},
Expand All @@ -168,7 +168,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {

logdir: true,
logfile: true,
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-logtostderr=false", "-alsologtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=1000"},

expectedLogFile: true,

Expand All @@ -179,7 +179,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
// Everything, including the trace on fatal, goes to the single log file
// AND to stderr.

flags: []string{"-alsologtostderr=true", "-logtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-alsologtostderr=true", "-logtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=0"},
logfile: true,

expectedLogFile: true,
Expand All @@ -192,7 +192,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
// log dir AND to stderr.

logdir: true,
flags: []string{"-alsologtostderr=true", "-logtostderr=false", "-stderrthreshold=1000"},
flags: []string{"-alsologtostderr=true", "-logtostderr=false", "-stderrthreshold=1000", "-alsologtostderrthreshold=0"},

expectedLogDir: true,

Expand All @@ -205,7 +205,7 @@ func TestDestinationsWithDifferentFlags(t *testing.T) {
// log dir AND to stderr.

logdir: true,
flags: []string{"-alsologtostderr=true", "-logtostderr=false", "-stderrthreshold=1000", "-one_output=true"},
flags: []string{"-alsologtostderr=true", "-logtostderr=false", "-stderrthreshold=1000", "-alsotostderrthreshold=0", "-one_output=true"},

expectedLogDir: true,

Expand Down
8 changes: 4 additions & 4 deletions klog.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
// -stderrthreshold=INFO
// Log events at or above this severity are logged to standard
// error.
// -alsotostderrthreshold=ERROR
// -alsologtostderrthreshold=ERROR
// Log events at or above this severity are logged to standard
// error as well as to files.
// -log_dir=""
Expand Down Expand Up @@ -95,7 +95,7 @@ import (
)

// severity identifies the sort of log: info, warning etc. It also implements the
// flag.Value interface. The -stderrthreshold and -alsotostderrthreshold flags are
// flag.Value interface. The -stderrthreshold and -alsologtostderrthreshold flags are
// of type severity and should be modified only through the flag.Value interface.
// The values match the corresponding constants in C++.
type severity int32 // sync/atomic int32
Expand Down Expand Up @@ -440,7 +440,7 @@ func InitFlags(flagset *flag.FlagSet) {
flagset.BoolVar(&logging.oneOutput, "one_output", logging.oneOutput, "If true, only write logs to their native severity level (vs also writing to each lower severity level)")
flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", logging.skipLogHeaders, "If true, avoid headers when opening log files")
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
flagset.Var(&logging.alsoToStderrThreshold, "alsotostderrthreshold", "logs at or above this threshold go to stderr as well as files")
flagset.Var(&logging.alsoToStderrThreshold, "alsologtostderrthreshold", "logs at or above this threshold go to stderr as well as files")
flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
}
Expand All @@ -460,7 +460,7 @@ type loggingT struct {

// Level flag. Handled atomically.
stderrThreshold severity // The -stderrthreshold flag.
alsoToStderrThreshold severity // The -alsotostderrthreshold flag.
alsoToStderrThreshold severity // The -alsologtostderrthreshold flag.

// freeList is a list of byte buffers, maintained under freeListMu.
freeList *buffer
Expand Down
27 changes: 14 additions & 13 deletions klog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,19 +1427,20 @@ func (l *testLogr) WithValues(...interface{}) logr.Logger {

// existedFlag contains all existed flag, without KlogPrefix
var existedFlag = map[string]struct{}{
"log_dir": {},
"add_dir_header": {},
"alsologtostderr": {},
"log_backtrace_at": {},
"log_file": {},
"log_file_max_size": {},
"logtostderr": {},
"one_output": {},
"skip_headers": {},
"skip_log_headers": {},
"stderrthreshold": {},
"v": {},
"vmodule": {},
"log_dir": {},
"add_dir_header": {},
"alsologtostderr": {},
"alsologtostderrthreshold": {},
"log_backtrace_at": {},
"log_file": {},
"log_file_max_size": {},
"logtostderr": {},
"one_output": {},
"skip_headers": {},
"skip_log_headers": {},
"stderrthreshold": {},
"v": {},
"vmodule": {},
}

// KlogPrefix define new flag prefix
Expand Down

0 comments on commit 6f2fbaa

Please sign in to comment.