Repository: kubernetes/klog
Pull request #376 (2023-05-09 15:29:50)

stderrthreshold: fix flag comment
**What this PR does / why we need it**:

The code is so that the -stderrthreshold gets ignored when -alsologtostderr=true.


**Which issue(s) this PR fixes**:
Fixes https://github.com/kubernetes/klog/issues/371

**Release note**:
```release-note
Fixed command line help for -stderrthreshold: it has no effect when   -alsologtostderr=true.
```

k8s-ci-robot: This issue is currently awaiting triage.

If klog contributors determine this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.

The `triage/accepted` label can be added by org members by writing `/triage accepted` in a comment.


<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>

Patch:
diff --git a/examples/flushing/.gitignore b/examples/flushing/.gitignore
deleted file mode 100644
index 2383fed..0000000
--- a/examples/flushing/.gitignore
+++ /dev/null
@@ -1,1 +0,0 @@
-myfile.log
diff --git a/klog.go b/klog.go
index c18576e..cdd0c55 100644
--- a/klog.go
+++ b/klog.go
@@ -415,7 +415,7 @@ func init() {
 	logging.stderrThreshold = severityValue{
 		Severity: severity.ErrorLog, // Default stderrThreshold is ERROR.
 	}
-	commandLine.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false)")
+	commandLine.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true)")
 	commandLine.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
 	commandLine.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
 
@@ -759,7 +759,7 @@ func (l *loggingT) printWithFileLine(s severity.Severity, logger *logWriter, fil
 	l.output(s, logger, buf, 2 /* depth */, file, line, alsoToStderr)
 }
 
-// if logger is specified, will call logger.Error, otherwise output with logging module.
+// if loggr is specified, will call loggr.Error, otherwise output with logging module.
 func (l *loggingT) errorS(err error, logger *logWriter, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
 	if filter != nil {
 		msg, keysAndValues = filter.FilterS(msg, keysAndValues)
@@ -771,7 +771,7 @@ func (l *loggingT) errorS(err error, logger *logWriter, filter LogFilter, depth
 	l.printS(err, severity.ErrorLog, depth+1, msg, keysAndValues...)
 }
 
-// if logger is specified, will call logger.Info, otherwise output with logging module.
+// if loggr is specified, will call loggr.Info, otherwise output with logging module.
 func (l *loggingT) infoS(logger *logWriter, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
 	if filter != nil {
 		msg, keysAndValues = filter.FilterS(msg, keysAndValues)
@@ -783,7 +783,7 @@ func (l *loggingT) infoS(logger *logWriter, filter LogFilter, depth int, msg str
 	l.printS(nil, severity.InfoLog, depth+1, msg, keysAndValues...)
 }
 
-// printS is called from infoS and errorS if logger is not specified.
+// printS is called from infoS and errorS if loggr is not specified.
 // set log severity by s
 func (l *loggingT) printS(err error, s severity.Severity, depth int, msg string, keysAndValues ...interface{}) {
 	// Only create a new buffer if we don't have one cached.
@@ -873,9 +873,6 @@ func (l *loggingT) output(s severity.Severity, logger *logWriter, buf *buffer.Bu
 		if logger.writeKlogBuffer != nil {
 			logger.writeKlogBuffer(data)
 		} else {
-			if len(data) > 0 && data[len(data)-1] == '\n' {
-				data = data[:len(data)-1]
-			}
 			// TODO: set 'severity' and caller information as structured log info
 			// keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line}
 			if s == severity.ErrorLog {


Test patch:
diff --git a/klog_test.go b/klog_test.go
index 7b6ebdb..7cf6168 100644
--- a/klog_test.go
+++ b/klog_test.go
@@ -913,7 +913,7 @@ func TestCommandLine(t *testing.T) {
   -skip_log_headers
     	If true, avoid headers when opening log files (no effect when -logtostderr=true)
   -stderrthreshold value
-    	logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
+    	logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true) (default 2)
   -v value
     	number for the log level verbosity
   -vmodule value
@@ -1484,13 +1484,13 @@ func TestInfoWithLogr(t *testing.T) {
 		msg: "foo",
 		expected: testLogrEntry{
 			severity: severity.InfoLog,
-			msg:      "foo",
+			msg:      "foo\n",
 		},
 	}, {
 		msg: "",
 		expected: testLogrEntry{
 			severity: severity.InfoLog,
-			msg:      "",
+			msg:      "\n",
 		},
 	}}
 
diff --git a/test/zapr.go b/test/zapr.go
index 6c7e809..7b15944 100644
--- a/test/zapr.go
+++ b/test/zapr.go
@@ -171,22 +171,22 @@ I output.go:<LINE>] "odd WithValues" keyWithoutValue="(MISSING)"
 
 		// klog.Info
 		`I output.go:<LINE>] "helloworld\n"
-`: `{"caller":"test/output.go:<LINE>","msg":"helloworld","v":0}
+`: `{"caller":"test/output.go:<LINE>","msg":"helloworld\n","v":0}
 `,
 
 		// klog.Infoln
 		`I output.go:<LINE>] "hello world\n"
-`: `{"caller":"test/output.go:<LINE>","msg":"hello world","v":0}
+`: `{"caller":"test/output.go:<LINE>","msg":"hello world\n","v":0}
 `,
 
 		// klog.Error
 		`E output.go:<LINE>] "helloworld\n"
-`: `{"caller":"test/output.go:<LINE>","msg":"helloworld"}
+`: `{"caller":"test/output.go:<LINE>","msg":"helloworld\n"}
 `,
 
 		// klog.Errorln
 		`E output.go:<LINE>] "hello world\n"
-`: `{"caller":"test/output.go:<LINE>","msg":"hello world"}
+`: `{"caller":"test/output.go:<LINE>","msg":"hello world\n"}
 `,
 
 		// klog.ErrorS
@@ -201,12 +201,12 @@ I output.go:<LINE>] "odd WithValues" keyWithoutValue="(MISSING)"
 
 		// klog.V(1).Info
 		`I output.go:<LINE>] "hellooneworld\n"
-`: `{"caller":"test/output.go:<LINE>","msg":"hellooneworld","v":1}
+`: `{"caller":"test/output.go:<LINE>","msg":"hellooneworld\n","v":1}
 `,
 
 		// klog.V(1).Infoln
 		`I output.go:<LINE>] "hello one world\n"
-`: `{"caller":"test/output.go:<LINE>","msg":"hello one world","v":1}
+`: `{"caller":"test/output.go:<LINE>","msg":"hello one world\n","v":1}
 `,
 
 		// klog.V(1).ErrorS