10
vendor/k8s.io/klog/v2/README.md
generated
vendored
10
vendor/k8s.io/klog/v2/README.md
generated
vendored
@@ -27,7 +27,7 @@ Historical context is available here:
|
||||
|
||||
How to use klog
|
||||
===============
|
||||
- Replace imports for `github.com/golang/glog` with `k8s.io/klog`
|
||||
- Replace imports for `"github.com/golang/glog"` with `"k8s.io/klog/v2"`
|
||||
- Use `klog.InitFlags(nil)` explicitly for initializing global flags as we no longer use `init()` method to register the flags
|
||||
- You can now use `log_file` instead of `log_dir` for logging to a single file (See `examples/log_file/usage_log_file.go`)
|
||||
- If you want to redirect everything logged using klog somewhere else (say syslog!), you can use `klog.SetOutput()` method and supply a `io.Writer`. (See `examples/set_output/usage_set_output.go`)
|
||||
@@ -35,8 +35,12 @@ How to use klog
|
||||
|
||||
**NOTE**: please use the newer go versions that support semantic import versioning in modules, ideally go 1.11.4 or greater.
|
||||
|
||||
### Coexisting with klog/v2
|
||||
|
||||
See [this example](examples/coexist_klog_v1_and_v2/) to see how to coexist with both klog/v1 and klog/v2.
|
||||
|
||||
### Coexisting with glog
|
||||
This package can be used side by side with glog. [This example](examples/coexist_glog/coexist_glog.go) shows how to initialize and syncronize flags from the global `flag.CommandLine` FlagSet. In addition, the example makes use of stderr as combined output by setting `alsologtostderr` (or `logtostderr`) to `true`.
|
||||
This package can be used side by side with glog. [This example](examples/coexist_glog/coexist_glog.go) shows how to initialize and synchronize flags from the global `flag.CommandLine` FlagSet. In addition, the example makes use of stderr as combined output by setting `alsologtostderr` (or `logtostderr`) to `true`.
|
||||
|
||||
## Community, discussion, contribution, and support
|
||||
|
||||
@@ -44,7 +48,7 @@ Learn how to engage with the Kubernetes community on the [community page](http:/
|
||||
|
||||
You can reach the maintainers of this project at:
|
||||
|
||||
- [Slack](https://kubernetes.slack.com/messages/sig-architecture)
|
||||
- [Slack](https://kubernetes.slack.com/messages/klog)
|
||||
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-sig-architecture)
|
||||
|
||||
### Code of conduct
|
||||
|
||||
22
vendor/k8s.io/klog/v2/SECURITY.md
generated
vendored
Normal file
22
vendor/k8s.io/klog/v2/SECURITY.md
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# Security Policy
|
||||
|
||||
## Security Announcements
|
||||
|
||||
Join the [kubernetes-security-announce] group for security and vulnerability announcements.
|
||||
|
||||
You can also subscribe to an RSS feed of the above using [this link][kubernetes-security-announce-rss].
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Instructions for reporting a vulnerability can be found on the
|
||||
[Kubernetes Security and Disclosure Information] page.
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Information about supported Kubernetes versions can be found on the
|
||||
[Kubernetes version and version skew support policy] page on the Kubernetes website.
|
||||
|
||||
[kubernetes-security-announce]: https://groups.google.com/forum/#!forum/kubernetes-security-announce
|
||||
[kubernetes-security-announce-rss]: https://groups.google.com/forum/feed/kubernetes-security-announce/msgs/rss_v2_0.xml?num=50
|
||||
[Kubernetes version and version skew support policy]: https://kubernetes.io/docs/setup/release/version-skew-policy/#supported-versions
|
||||
[Kubernetes Security and Disclosure Information]: https://kubernetes.io/docs/reference/issues-security/security/#report-a-vulnerability
|
||||
2
vendor/k8s.io/klog/v2/go.mod
generated
vendored
2
vendor/k8s.io/klog/v2/go.mod
generated
vendored
@@ -2,4 +2,4 @@ module k8s.io/klog/v2
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/go-logr/logr v0.1.0
|
||||
require github.com/go-logr/logr v0.4.0
|
||||
|
||||
4
vendor/k8s.io/klog/v2/go.sum
generated
vendored
4
vendor/k8s.io/klog/v2/go.sum
generated
vendored
@@ -1,2 +1,2 @@
|
||||
github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg=
|
||||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
|
||||
github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
|
||||
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
|
||||
|
||||
258
vendor/k8s.io/klog/v2/klog.go
generated
vendored
258
vendor/k8s.io/klog/v2/klog.go
generated
vendored
@@ -81,6 +81,7 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -413,6 +414,7 @@ func init() {
|
||||
logging.skipHeaders = false
|
||||
logging.addDirHeader = false
|
||||
logging.skipLogHeaders = false
|
||||
logging.oneOutput = false
|
||||
go logging.flushDaemon()
|
||||
}
|
||||
|
||||
@@ -432,6 +434,7 @@ func InitFlags(flagset *flag.FlagSet) {
|
||||
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
|
||||
flagset.BoolVar(&logging.addDirHeader, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header of the log messages")
|
||||
flagset.BoolVar(&logging.skipHeaders, "skip_headers", logging.skipHeaders, "If true, avoid header prefixes in the log messages")
|
||||
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.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
|
||||
@@ -505,6 +508,12 @@ type loggingT struct {
|
||||
|
||||
// If set, all output will be redirected unconditionally to the provided logr.Logger
|
||||
logr logr.Logger
|
||||
|
||||
// If true, messages will not be propagated to lower severity log levels
|
||||
oneOutput bool
|
||||
|
||||
// If set, all output will be filtered through the filter.
|
||||
filter LogFilter
|
||||
}
|
||||
|
||||
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
||||
@@ -687,7 +696,7 @@ func (buf *buffer) someDigits(i, d int) int {
|
||||
return copy(buf.tmp[i:], buf.tmp[j:])
|
||||
}
|
||||
|
||||
func (l *loggingT) println(s severity, logr logr.InfoLogger, args ...interface{}) {
|
||||
func (l *loggingT) println(s severity, logr logr.Logger, filter LogFilter, args ...interface{}) {
|
||||
buf, file, line := l.header(s, 0)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
@@ -695,15 +704,18 @@ func (l *loggingT) println(s severity, logr logr.InfoLogger, args ...interface{}
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprintln(buf, args...)
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) print(s severity, logr logr.InfoLogger, args ...interface{}) {
|
||||
l.printDepth(s, logr, 1, args...)
|
||||
func (l *loggingT) print(s severity, logr logr.Logger, filter LogFilter, args ...interface{}) {
|
||||
l.printDepth(s, logr, filter, 1, args...)
|
||||
}
|
||||
|
||||
func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args ...interface{}) {
|
||||
func (l *loggingT) printDepth(s severity, logr logr.Logger, filter LogFilter, depth int, args ...interface{}) {
|
||||
buf, file, line := l.header(s, depth)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
@@ -711,6 +723,9 @@ func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprint(buf, args...)
|
||||
if buf.Bytes()[buf.Len()-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
@@ -718,7 +733,7 @@ func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args ...interface{}) {
|
||||
func (l *loggingT) printf(s severity, logr logr.Logger, filter LogFilter, format string, args ...interface{}) {
|
||||
buf, file, line := l.header(s, 0)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
@@ -726,6 +741,9 @@ func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
format, args = filter.FilterF(format, args)
|
||||
}
|
||||
fmt.Fprintf(buf, format, args...)
|
||||
if buf.Bytes()[buf.Len()-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
@@ -736,7 +754,7 @@ func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args
|
||||
// printWithFileLine behaves like print but uses the provided file and line number. If
|
||||
// alsoLogToStderr is true, the log message always appears on standard error; it
|
||||
// will also appear in the log file unless --logtostderr is set.
|
||||
func (l *loggingT) printWithFileLine(s severity, logr logr.InfoLogger, file string, line int, alsoToStderr bool, args ...interface{}) {
|
||||
func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{}) {
|
||||
buf := l.formatHeader(s, file, line)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
@@ -744,6 +762,9 @@ func (l *loggingT) printWithFileLine(s severity, logr logr.InfoLogger, file stri
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprint(buf, args...)
|
||||
if buf.Bytes()[buf.Len()-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
@@ -751,17 +772,33 @@ func (l *loggingT) printWithFileLine(s severity, logr logr.InfoLogger, file stri
|
||||
l.output(s, logr, buf, file, line, alsoToStderr)
|
||||
}
|
||||
|
||||
// printS if loggr is specified, no need to output with logging module. If
|
||||
// err arguments is specified, will call logr.Error, or output to errorLog severity
|
||||
func (l *loggingT) printS(err error, loggr logr.Logger, msg string, keysAndValues ...interface{}) {
|
||||
// if loggr is specified, will call loggr.Error, otherwise output with logging module.
|
||||
func (l *loggingT) errorS(err error, loggr logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
if filter != nil {
|
||||
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
|
||||
}
|
||||
if loggr != nil {
|
||||
if err != nil {
|
||||
loggr.Error(err, msg, keysAndValues)
|
||||
} else {
|
||||
loggr.Info(msg, keysAndValues)
|
||||
}
|
||||
loggr.Error(err, msg, keysAndValues...)
|
||||
return
|
||||
}
|
||||
l.printS(err, errorLog, depth+1, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// if loggr is specified, will call loggr.Info, otherwise output with logging module.
|
||||
func (l *loggingT) infoS(loggr logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
if filter != nil {
|
||||
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
|
||||
}
|
||||
if loggr != nil {
|
||||
loggr.Info(msg, keysAndValues...)
|
||||
return
|
||||
}
|
||||
l.printS(nil, infoLog, depth+1, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// 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, depth int, msg string, keysAndValues ...interface{}) {
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(fmt.Sprintf("%q", msg))
|
||||
if err != nil {
|
||||
@@ -769,13 +806,7 @@ func (l *loggingT) printS(err error, loggr logr.Logger, msg string, keysAndValue
|
||||
b.WriteString(fmt.Sprintf("err=%q", err.Error()))
|
||||
}
|
||||
kvListFormat(b, keysAndValues...)
|
||||
var s severity
|
||||
if err == nil {
|
||||
s = infoLog
|
||||
} else {
|
||||
s = errorLog
|
||||
}
|
||||
l.printDepth(s, logging.logr, 1, b)
|
||||
l.printDepth(s, logging.logr, nil, depth+1, b)
|
||||
}
|
||||
|
||||
const missingValue = "(MISSING)"
|
||||
@@ -790,10 +821,16 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
v = missingValue
|
||||
}
|
||||
b.WriteByte(' ')
|
||||
if _, ok := v.(fmt.Stringer); ok {
|
||||
|
||||
switch v.(type) {
|
||||
case string, error:
|
||||
b.WriteString(fmt.Sprintf("%s=%q", k, v))
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("%s=%#v", k, v))
|
||||
default:
|
||||
if _, ok := v.(fmt.Stringer); ok {
|
||||
b.WriteString(fmt.Sprintf("%s=%q", k, v))
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("%s=%+v", k, v))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -853,8 +890,16 @@ func SetOutputBySeverity(name string, w io.Writer) {
|
||||
logging.file[sev] = rb
|
||||
}
|
||||
|
||||
// LogToStderr sets whether to log exclusively to stderr, bypassing outputs
|
||||
func LogToStderr(stderr bool) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
|
||||
logging.toStderr = stderr
|
||||
}
|
||||
|
||||
// output writes the data to the log files and releases the buffer.
|
||||
func (l *loggingT) output(s severity, log logr.InfoLogger, buf *buffer, file string, line int, alsoToStderr bool) {
|
||||
func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string, line int, alsoToStderr bool) {
|
||||
l.mu.Lock()
|
||||
if l.traceLocation.isSet() {
|
||||
if l.traceLocation.match(file, line) {
|
||||
@@ -895,18 +940,22 @@ func (l *loggingT) output(s severity, log logr.InfoLogger, buf *buffer, file str
|
||||
}
|
||||
}
|
||||
|
||||
switch s {
|
||||
case fatalLog:
|
||||
l.file[fatalLog].Write(data)
|
||||
fallthrough
|
||||
case errorLog:
|
||||
l.file[errorLog].Write(data)
|
||||
fallthrough
|
||||
case warningLog:
|
||||
l.file[warningLog].Write(data)
|
||||
fallthrough
|
||||
case infoLog:
|
||||
l.file[infoLog].Write(data)
|
||||
if l.oneOutput {
|
||||
l.file[s].Write(data)
|
||||
} else {
|
||||
switch s {
|
||||
case fatalLog:
|
||||
l.file[fatalLog].Write(data)
|
||||
fallthrough
|
||||
case errorLog:
|
||||
l.file[errorLog].Write(data)
|
||||
fallthrough
|
||||
case warningLog:
|
||||
l.file[warningLog].Write(data)
|
||||
fallthrough
|
||||
case infoLog:
|
||||
l.file[infoLog].Write(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1053,11 +1102,19 @@ func (sb *syncBuffer) rotateFile(now time.Time, startup bool) error {
|
||||
}
|
||||
var err error
|
||||
sb.file, _, err = create(severityName[sb.sev], now, startup)
|
||||
sb.nbytes = 0
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if startup {
|
||||
fileInfo, err := sb.file.Stat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("file stat could not get fileinfo: %v", err)
|
||||
}
|
||||
// init file size
|
||||
sb.nbytes = uint64(fileInfo.Size())
|
||||
} else {
|
||||
sb.nbytes = 0
|
||||
}
|
||||
sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)
|
||||
|
||||
if sb.logger.skipLogHeaders {
|
||||
@@ -1173,7 +1230,7 @@ func (lb logBridge) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
// printWithFileLine with alsoToStderr=true, so standard log messages
|
||||
// always appear on standard error.
|
||||
logging.printWithFileLine(severity(lb), logging.logr, file, line, true, text)
|
||||
logging.printWithFileLine(severity(lb), logging.logr, logging.filter, file, line, true, text)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
@@ -1207,14 +1264,15 @@ func (l *loggingT) setV(pc uintptr) Level {
|
||||
// See the documentation of V for more information.
|
||||
type Verbose struct {
|
||||
enabled bool
|
||||
logr logr.InfoLogger
|
||||
logr logr.Logger
|
||||
filter LogFilter
|
||||
}
|
||||
|
||||
func newVerbose(level Level, b bool) Verbose {
|
||||
if logging.logr == nil {
|
||||
return Verbose{b, nil}
|
||||
return Verbose{b, nil, logging.filter}
|
||||
}
|
||||
return Verbose{b, logging.logr.V(int(level))}
|
||||
return Verbose{b, logging.logr.V(int(level)), logging.filter}
|
||||
}
|
||||
|
||||
// V reports whether verbosity at the call site is at least the requested level.
|
||||
@@ -1228,9 +1286,10 @@ func newVerbose(level Level, b bool) Verbose {
|
||||
// not evaluate its arguments.
|
||||
//
|
||||
// Whether an individual call to V generates a log record depends on the setting of
|
||||
// the -v and --vmodule flags; both are off by default. If the level in the call to
|
||||
// V is at least the value of -v, or of -vmodule for the source file containing the
|
||||
// call, the V call will log.
|
||||
// the -v and -vmodule flags; both are off by default. The V call will log if its level
|
||||
// is less than or equal to the value of the -v flag, or alternatively if its level is
|
||||
// less than or equal to the value of the -vmodule pattern matching the source file
|
||||
// containing the call.
|
||||
func V(level Level) Verbose {
|
||||
// This function tries hard to be cheap unless there's work to do.
|
||||
// The fast path is two atomic loads and compares.
|
||||
@@ -1240,7 +1299,7 @@ func V(level Level) Verbose {
|
||||
return newVerbose(level, true)
|
||||
}
|
||||
|
||||
// It's off globally but it vmodule may still be set.
|
||||
// It's off globally but vmodule may still be set.
|
||||
// Here is another cheap but safe test to see if vmodule is enabled.
|
||||
if atomic.LoadInt32(&logging.filterLength) > 0 {
|
||||
// Now we need a proper lock to use the logging structure. The pcs field
|
||||
@@ -1271,7 +1330,7 @@ func (v Verbose) Enabled() bool {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Info(args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.print(infoLog, v.logr, args...)
|
||||
logging.print(infoLog, v.logr, v.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1279,7 +1338,7 @@ func (v Verbose) Info(args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infoln(args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.println(infoLog, v.logr, args...)
|
||||
logging.println(infoLog, v.logr, v.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1287,7 +1346,7 @@ func (v Verbose) Infoln(args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.printf(infoLog, v.logr, format, args...)
|
||||
logging.printf(infoLog, v.logr, v.filter, format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1295,36 +1354,53 @@ func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
if v.logr != nil {
|
||||
v.logr.Info(msg, keysAndValues)
|
||||
return
|
||||
}
|
||||
logging.printS(nil, nil, msg, keysAndValues...)
|
||||
logging.infoS(v.logr, v.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
// InfoSDepth acts as InfoS but uses depth to determine which call frame to log.
|
||||
// InfoSDepth(0, "msg") is the same as InfoS("msg").
|
||||
func InfoSDepth(depth int, msg string, keysAndValues ...interface{}) {
|
||||
logging.infoS(logging.logr, logging.filter, depth, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// Deprecated: Use ErrorS instead.
|
||||
func (v Verbose) Error(err error, msg string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.errorS(err, v.logr, v.filter, 0, msg, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorS is equivalent to the global Error function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) ErrorS(err error, msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.errorS(err, v.logr, v.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
// Info logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Info(args ...interface{}) {
|
||||
logging.print(infoLog, logging.logr, args...)
|
||||
logging.print(infoLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// InfoDepth acts as Info but uses depth to determine which call frame to log.
|
||||
// InfoDepth(0, "msg") is the same as Info("msg").
|
||||
func InfoDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(infoLog, logging.logr, depth, args...)
|
||||
logging.printDepth(infoLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Infoln logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Infoln(args ...interface{}) {
|
||||
logging.println(infoLog, logging.logr, args...)
|
||||
logging.println(infoLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Infof logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Infof(format string, args ...interface{}) {
|
||||
logging.printf(infoLog, logging.logr, format, args...)
|
||||
logging.printf(infoLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// InfoS structured logs to the INFO log.
|
||||
@@ -1336,55 +1412,55 @@ func Infof(format string, args ...interface{}) {
|
||||
// output:
|
||||
// >> I1025 00:15:15.525108 1 controller_utils.go:116] "Pod status updated" pod="kubedns" status="ready"
|
||||
func InfoS(msg string, keysAndValues ...interface{}) {
|
||||
logging.printS(nil, logging.logr, msg, keysAndValues...)
|
||||
logging.infoS(logging.logr, logging.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// Warning logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Warning(args ...interface{}) {
|
||||
logging.print(warningLog, logging.logr, args...)
|
||||
logging.print(warningLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// WarningDepth acts as Warning but uses depth to determine which call frame to log.
|
||||
// WarningDepth(0, "msg") is the same as Warning("msg").
|
||||
func WarningDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(warningLog, logging.logr, depth, args...)
|
||||
logging.printDepth(warningLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Warningln logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Warningln(args ...interface{}) {
|
||||
logging.println(warningLog, logging.logr, args...)
|
||||
logging.println(warningLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Warningf logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Warningf(format string, args ...interface{}) {
|
||||
logging.printf(warningLog, logging.logr, format, args...)
|
||||
logging.printf(warningLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// Error logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Error(args ...interface{}) {
|
||||
logging.print(errorLog, logging.logr, args...)
|
||||
logging.print(errorLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// ErrorDepth acts as Error but uses depth to determine which call frame to log.
|
||||
// ErrorDepth(0, "msg") is the same as Error("msg").
|
||||
func ErrorDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(errorLog, logging.logr, depth, args...)
|
||||
logging.printDepth(errorLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Errorln logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Errorln(args ...interface{}) {
|
||||
logging.println(errorLog, logging.logr, args...)
|
||||
logging.println(errorLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Errorf logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Errorf(format string, args ...interface{}) {
|
||||
logging.printf(errorLog, logging.logr, format, args...)
|
||||
logging.printf(errorLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// ErrorS structured logs to the ERROR, WARNING, and INFO logs.
|
||||
@@ -1397,34 +1473,40 @@ func Errorf(format string, args ...interface{}) {
|
||||
// output:
|
||||
// >> E1025 00:15:15.525108 1 controller_utils.go:114] "Failed to update pod status" err="timeout"
|
||||
func ErrorS(err error, msg string, keysAndValues ...interface{}) {
|
||||
logging.printS(err, logging.logr, msg, keysAndValues...)
|
||||
logging.errorS(err, logging.logr, logging.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// ErrorSDepth acts as ErrorS but uses depth to determine which call frame to log.
|
||||
// ErrorSDepth(0, "msg") is the same as ErrorS("msg").
|
||||
func ErrorSDepth(depth int, err error, msg string, keysAndValues ...interface{}) {
|
||||
logging.errorS(err, logging.logr, logging.filter, depth, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// Fatal logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Fatal(args ...interface{}) {
|
||||
logging.print(fatalLog, logging.logr, args...)
|
||||
logging.print(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// FatalDepth acts as Fatal but uses depth to determine which call frame to log.
|
||||
// FatalDepth(0, "msg") is the same as Fatal("msg").
|
||||
func FatalDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(fatalLog, logging.logr, depth, args...)
|
||||
logging.printDepth(fatalLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Fatalln(args ...interface{}) {
|
||||
logging.println(fatalLog, logging.logr, args...)
|
||||
logging.println(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Fatalf(format string, args ...interface{}) {
|
||||
logging.printf(fatalLog, logging.logr, format, args...)
|
||||
logging.printf(fatalLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// fatalNoStacks is non-zero if we are to exit without dumping goroutine stacks.
|
||||
@@ -1435,27 +1517,42 @@ var fatalNoStacks uint32
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Exit(args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.print(fatalLog, logging.logr, args...)
|
||||
logging.print(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// ExitDepth acts as Exit but uses depth to determine which call frame to log.
|
||||
// ExitDepth(0, "msg") is the same as Exit("msg").
|
||||
func ExitDepth(depth int, args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.printDepth(fatalLog, logging.logr, depth, args...)
|
||||
logging.printDepth(fatalLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
|
||||
func Exitln(args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.println(fatalLog, logging.logr, args...)
|
||||
logging.println(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Exitf(format string, args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.printf(fatalLog, logging.logr, format, args...)
|
||||
logging.printf(fatalLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// LogFilter is a collection of functions that can filter all logging calls,
|
||||
// e.g. for sanitization of arguments and prevent accidental leaking of secrets.
|
||||
type LogFilter interface {
|
||||
Filter(args []interface{}) []interface{}
|
||||
FilterF(format string, args []interface{}) (string, []interface{})
|
||||
FilterS(msg string, keysAndValues []interface{}) (string, []interface{})
|
||||
}
|
||||
|
||||
func SetLogFilter(filter LogFilter) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
|
||||
logging.filter = filter
|
||||
}
|
||||
|
||||
// ObjectRef references a kubernetes object
|
||||
@@ -1481,6 +1578,13 @@ type KMetadata interface {
|
||||
|
||||
// KObj returns ObjectRef from ObjectMeta
|
||||
func KObj(obj KMetadata) ObjectRef {
|
||||
if obj == nil {
|
||||
return ObjectRef{}
|
||||
}
|
||||
if val := reflect.ValueOf(obj); val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
return ObjectRef{}
|
||||
}
|
||||
|
||||
return ObjectRef{
|
||||
Name: obj.GetName(),
|
||||
Namespace: obj.GetNamespace(),
|
||||
|
||||
64
vendor/k8s.io/klog/v2/klog_file.go
generated
vendored
64
vendor/k8s.io/klog/v2/klog_file.go
generated
vendored
@@ -44,43 +44,49 @@ func createLogDirs() {
|
||||
}
|
||||
|
||||
var (
|
||||
pid = os.Getpid()
|
||||
program = filepath.Base(os.Args[0])
|
||||
host = "unknownhost"
|
||||
userName = "unknownuser"
|
||||
pid = os.Getpid()
|
||||
program = filepath.Base(os.Args[0])
|
||||
host = "unknownhost"
|
||||
userName = "unknownuser"
|
||||
userNameOnce sync.Once
|
||||
)
|
||||
|
||||
func init() {
|
||||
h, err := os.Hostname()
|
||||
if err == nil {
|
||||
if h, err := os.Hostname(); err == nil {
|
||||
host = shortHostname(h)
|
||||
}
|
||||
}
|
||||
|
||||
// On Windows, the Go 'user' package requires netapi32.dll.
|
||||
// This affects Windows Nano Server:
|
||||
// https://github.com/golang/go/issues/21867
|
||||
// Fallback to using environment variables.
|
||||
if runtime.GOOS == "windows" {
|
||||
u := os.Getenv("USERNAME")
|
||||
if len(u) == 0 {
|
||||
return
|
||||
}
|
||||
// Sanitize the USERNAME since it may contain filepath separators.
|
||||
u = strings.Replace(u, `\`, "_", -1)
|
||||
func getUserName() string {
|
||||
userNameOnce.Do(func() {
|
||||
// On Windows, the Go 'user' package requires netapi32.dll.
|
||||
// This affects Windows Nano Server:
|
||||
// https://github.com/golang/go/issues/21867
|
||||
// Fallback to using environment variables.
|
||||
if runtime.GOOS == "windows" {
|
||||
u := os.Getenv("USERNAME")
|
||||
if len(u) == 0 {
|
||||
return
|
||||
}
|
||||
// Sanitize the USERNAME since it may contain filepath separators.
|
||||
u = strings.Replace(u, `\`, "_", -1)
|
||||
|
||||
// user.Current().Username normally produces something like 'USERDOMAIN\USERNAME'
|
||||
d := os.Getenv("USERDOMAIN")
|
||||
if len(d) != 0 {
|
||||
userName = d + "_" + u
|
||||
// user.Current().Username normally produces something like 'USERDOMAIN\USERNAME'
|
||||
d := os.Getenv("USERDOMAIN")
|
||||
if len(d) != 0 {
|
||||
userName = d + "_" + u
|
||||
} else {
|
||||
userName = u
|
||||
}
|
||||
} else {
|
||||
userName = u
|
||||
current, err := user.Current()
|
||||
if err == nil {
|
||||
userName = current.Username
|
||||
}
|
||||
}
|
||||
} else {
|
||||
current, err := user.Current()
|
||||
if err == nil {
|
||||
userName = current.Username
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return userName
|
||||
}
|
||||
|
||||
// shortHostname returns its argument, truncating at the first period.
|
||||
@@ -98,7 +104,7 @@ func logName(tag string, t time.Time) (name, link string) {
|
||||
name = fmt.Sprintf("%s.%s.%s.log.%s.%04d%02d%02d-%02d%02d%02d.%d",
|
||||
program,
|
||||
host,
|
||||
userName,
|
||||
getUserName(),
|
||||
tag,
|
||||
t.Year(),
|
||||
t.Month(),
|
||||
|
||||
Reference in New Issue
Block a user