go.mod: bump client-go and api machinerie
I had to run `make generate`. Some API functions got additional parameters `Options` and `Context`. I used empty options and `context.TODO()` for now. Signed-off-by: leonnicolas <leonloechner@gmx.de>
This commit is contained in:
15
vendor/k8s.io/klog/.travis.yml
generated
vendored
15
vendor/k8s.io/klog/.travis.yml
generated
vendored
@@ -1,15 +0,0 @@
|
||||
language: go
|
||||
go_import_path: k8s.io/klog
|
||||
dist: xenial
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
script:
|
||||
- go get -t -v ./...
|
||||
- diff -u <(echo -n) <(gofmt -d .)
|
||||
- diff -u <(echo -n) <(golint $(go list -e ./...))
|
||||
- go tool vet .
|
||||
- go test -v -race ./...
|
||||
install:
|
||||
- go get golang.org/x/lint/golint
|
17
vendor/k8s.io/klog/v2/.gitignore
generated
vendored
Normal file
17
vendor/k8s.io/klog/v2/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# OSX leaves these everywhere on SMB shares
|
||||
._*
|
||||
|
||||
# OSX trash
|
||||
.DS_Store
|
||||
|
||||
# Eclipse files
|
||||
.classpath
|
||||
.project
|
||||
.settings/**
|
||||
|
||||
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# Vscode files
|
||||
.vscode
|
2
vendor/k8s.io/klog/CONTRIBUTING.md → vendor/k8s.io/klog/v2/CONTRIBUTING.md
generated
vendored
2
vendor/k8s.io/klog/CONTRIBUTING.md → vendor/k8s.io/klog/v2/CONTRIBUTING.md
generated
vendored
@@ -10,7 +10,7 @@ We have full documentation on how to get started contributing here:
|
||||
|
||||
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
|
||||
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
|
||||
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
|
||||
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet) - Common resources for existing developers
|
||||
|
||||
## Mentorship
|
||||
|
0
vendor/k8s.io/klog/LICENSE → vendor/k8s.io/klog/v2/LICENSE
generated
vendored
0
vendor/k8s.io/klog/LICENSE → vendor/k8s.io/klog/v2/LICENSE
generated
vendored
0
vendor/k8s.io/klog/OWNERS → vendor/k8s.io/klog/v2/OWNERS
generated
vendored
0
vendor/k8s.io/klog/OWNERS → vendor/k8s.io/klog/v2/OWNERS
generated
vendored
16
vendor/k8s.io/klog/README.md → vendor/k8s.io/klog/v2/README.md
generated
vendored
16
vendor/k8s.io/klog/README.md → vendor/k8s.io/klog/v2/README.md
generated
vendored
@@ -27,14 +27,20 @@ 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`)
|
||||
- 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`)
|
||||
- For more logging conventions (See [Logging Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md))
|
||||
- For more logging conventions (See [Logging Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md))
|
||||
|
||||
**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
|
||||
|
||||
@@ -42,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
|
0
vendor/k8s.io/klog/RELEASE.md → vendor/k8s.io/klog/v2/RELEASE.md
generated
vendored
0
vendor/k8s.io/klog/RELEASE.md → vendor/k8s.io/klog/v2/RELEASE.md
generated
vendored
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
|
0
vendor/k8s.io/klog/SECURITY_CONTACTS → vendor/k8s.io/klog/v2/SECURITY_CONTACTS
generated
vendored
0
vendor/k8s.io/klog/SECURITY_CONTACTS → vendor/k8s.io/klog/v2/SECURITY_CONTACTS
generated
vendored
0
vendor/k8s.io/klog/code-of-conduct.md → vendor/k8s.io/klog/v2/code-of-conduct.md
generated
vendored
0
vendor/k8s.io/klog/code-of-conduct.md → vendor/k8s.io/klog/v2/code-of-conduct.md
generated
vendored
5
vendor/k8s.io/klog/v2/go.mod
generated
vendored
Normal file
5
vendor/k8s.io/klog/v2/go.mod
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
module k8s.io/klog/v2
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/go-logr/logr v0.4.0
|
2
vendor/k8s.io/klog/v2/go.sum
generated
vendored
Normal file
2
vendor/k8s.io/klog/v2/go.sum
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
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=
|
555
vendor/k8s.io/klog/klog.go → vendor/k8s.io/klog/v2/klog.go
generated
vendored
555
vendor/k8s.io/klog/klog.go → vendor/k8s.io/klog/v2/klog.go
generated
vendored
@@ -20,26 +20,26 @@
|
||||
//
|
||||
// Basic examples:
|
||||
//
|
||||
// glog.Info("Prepare to repel boarders")
|
||||
// klog.Info("Prepare to repel boarders")
|
||||
//
|
||||
// glog.Fatalf("Initialization failed: %s", err)
|
||||
// klog.Fatalf("Initialization failed: %s", err)
|
||||
//
|
||||
// See the documentation for the V function for an explanation of these examples:
|
||||
//
|
||||
// if glog.V(2) {
|
||||
// glog.Info("Starting transaction...")
|
||||
// if klog.V(2) {
|
||||
// klog.Info("Starting transaction...")
|
||||
// }
|
||||
//
|
||||
// glog.V(2).Infoln("Processed", nItems, "elements")
|
||||
// klog.V(2).Infoln("Processed", nItems, "elements")
|
||||
//
|
||||
// Log output is buffered and written periodically using Flush. Programs
|
||||
// should call Flush before exiting to guarantee all log output is written.
|
||||
//
|
||||
// By default, all log statements write to files in a temporary directory.
|
||||
// By default, all log statements write to standard error.
|
||||
// This package provides several flags that modify this behavior.
|
||||
// As a result, flag.Parse must be called before any logging is done.
|
||||
//
|
||||
// -logtostderr=false
|
||||
// -logtostderr=true
|
||||
// Logs are written to standard error instead of to files.
|
||||
// -alsologtostderr=false
|
||||
// Logs are written to standard error as well as to files.
|
||||
@@ -81,12 +81,15 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
// severity identifies the sort of log: info, warning etc. It also implements
|
||||
@@ -130,7 +133,7 @@ func (s *severity) String() string {
|
||||
return strconv.FormatInt(int64(*s), 10)
|
||||
}
|
||||
|
||||
// Get is part of the flag.Value interface.
|
||||
// Get is part of the flag.Getter interface.
|
||||
func (s *severity) Get() interface{} {
|
||||
return *s
|
||||
}
|
||||
@@ -142,7 +145,7 @@ func (s *severity) Set(value string) error {
|
||||
if v, ok := severityByName(value); ok {
|
||||
threshold = v
|
||||
} else {
|
||||
v, err := strconv.Atoi(value)
|
||||
v, err := strconv.ParseInt(value, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -219,14 +222,14 @@ func (l *Level) String() string {
|
||||
return strconv.FormatInt(int64(*l), 10)
|
||||
}
|
||||
|
||||
// Get is part of the flag.Value interface.
|
||||
// Get is part of the flag.Getter interface.
|
||||
func (l *Level) Get() interface{} {
|
||||
return *l
|
||||
}
|
||||
|
||||
// Set is part of the flag.Value interface.
|
||||
func (l *Level) Set(value string) error {
|
||||
v, err := strconv.Atoi(value)
|
||||
v, err := strconv.ParseInt(value, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -294,7 +297,7 @@ func (m *moduleSpec) Set(value string) error {
|
||||
return errVmoduleSyntax
|
||||
}
|
||||
pattern := patLev[0]
|
||||
v, err := strconv.Atoi(patLev[1])
|
||||
v, err := strconv.ParseInt(patLev[1], 10, 32)
|
||||
if err != nil {
|
||||
return errors.New("syntax error: expect comma-separated list of filename=N")
|
||||
}
|
||||
@@ -364,8 +367,11 @@ var errTraceSyntax = errors.New("syntax error: expect file.go:234")
|
||||
func (t *traceLocation) Set(value string) error {
|
||||
if value == "" {
|
||||
// Unset.
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
t.line = 0
|
||||
t.file = ""
|
||||
return nil
|
||||
}
|
||||
fields := strings.Split(value, ":")
|
||||
if len(fields) != 2 {
|
||||
@@ -396,29 +402,40 @@ type flushSyncWriter interface {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
// init sets up the defaults and runs flushDaemon.
|
||||
func init() {
|
||||
// Default stderrThreshold is ERROR.
|
||||
logging.stderrThreshold = errorLog
|
||||
|
||||
logging.stderrThreshold = errorLog // Default stderrThreshold is ERROR.
|
||||
logging.setVState(0, nil, false)
|
||||
logging.logDir = ""
|
||||
logging.logFile = ""
|
||||
logging.logFileMaxSizeMB = 1800
|
||||
logging.toStderr = true
|
||||
logging.alsoToStderr = false
|
||||
logging.skipHeaders = false
|
||||
logging.addDirHeader = false
|
||||
logging.skipLogHeaders = false
|
||||
logging.oneOutput = false
|
||||
go logging.flushDaemon()
|
||||
}
|
||||
|
||||
// InitFlags is for explicitly initializing the flags
|
||||
// InitFlags is for explicitly initializing the flags.
|
||||
func InitFlags(flagset *flag.FlagSet) {
|
||||
if flagset == nil {
|
||||
flagset = flag.CommandLine
|
||||
}
|
||||
flagset.StringVar(&logging.logDir, "log_dir", "", "If non-empty, write log files in this directory")
|
||||
flagset.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file")
|
||||
flagset.Uint64Var(&logging.logFileMaxSizeMB, "log_file_max_size", 1800,
|
||||
|
||||
flagset.StringVar(&logging.logDir, "log_dir", logging.logDir, "If non-empty, write log files in this directory")
|
||||
flagset.StringVar(&logging.logFile, "log_file", logging.logFile, "If non-empty, use this log file")
|
||||
flagset.Uint64Var(&logging.logFileMaxSizeMB, "log_file_max_size", logging.logFileMaxSizeMB,
|
||||
"Defines the maximum size a log file can grow to. Unit is megabytes. "+
|
||||
"If the value is 0, the maximum file size is unlimited.")
|
||||
flagset.BoolVar(&logging.toStderr, "logtostderr", true, "log to standard error instead of files")
|
||||
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
|
||||
flagset.BoolVar(&logging.toStderr, "logtostderr", logging.toStderr, "log to standard error instead of files")
|
||||
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", logging.alsoToStderr, "log to standard error as well as files")
|
||||
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
|
||||
flagset.BoolVar(&logging.skipHeaders, "skip_headers", false, "If true, avoid header prefixes in the log messages")
|
||||
flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", false, "If true, avoid headers when openning log files")
|
||||
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")
|
||||
flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
|
||||
@@ -473,7 +490,7 @@ type loggingT struct {
|
||||
logDir string
|
||||
|
||||
// If non-empty, specifies the path of the file to write logs. mutually exclusive
|
||||
// with the log-dir option.
|
||||
// with the log_dir option.
|
||||
logFile string
|
||||
|
||||
// When logFile is specified, this limiter makes sure the logFile won't exceeds a certain size. When exceeds, the
|
||||
@@ -485,6 +502,18 @@ type loggingT struct {
|
||||
|
||||
// If true, do not add the headers to log files
|
||||
skipLogHeaders bool
|
||||
|
||||
// If true, add the file directory to the header
|
||||
addDirHeader bool
|
||||
|
||||
// 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.
|
||||
@@ -500,20 +529,20 @@ var logging loggingT
|
||||
// l.mu is held.
|
||||
func (l *loggingT) setVState(verbosity Level, filter []modulePat, setFilter bool) {
|
||||
// Turn verbosity off so V will not fire while we are in transition.
|
||||
logging.verbosity.set(0)
|
||||
l.verbosity.set(0)
|
||||
// Ditto for filter length.
|
||||
atomic.StoreInt32(&logging.filterLength, 0)
|
||||
atomic.StoreInt32(&l.filterLength, 0)
|
||||
|
||||
// Set the new filters and wipe the pc->Level map if the filter has changed.
|
||||
if setFilter {
|
||||
logging.vmodule.filter = filter
|
||||
logging.vmap = make(map[uintptr]Level)
|
||||
l.vmodule.filter = filter
|
||||
l.vmap = make(map[uintptr]Level)
|
||||
}
|
||||
|
||||
// Things are consistent now, so enable filtering and verbosity.
|
||||
// They are enabled in order opposite to that in V.
|
||||
atomic.StoreInt32(&logging.filterLength, int32(len(filter)))
|
||||
logging.verbosity.set(verbosity)
|
||||
atomic.StoreInt32(&l.filterLength, int32(len(filter)))
|
||||
l.verbosity.set(verbosity)
|
||||
}
|
||||
|
||||
// getBuffer returns a new, ready-to-use buffer.
|
||||
@@ -570,9 +599,14 @@ func (l *loggingT) header(s severity, depth int) (*buffer, string, int) {
|
||||
file = "???"
|
||||
line = 1
|
||||
} else {
|
||||
slash := strings.LastIndex(file, "/")
|
||||
if slash >= 0 {
|
||||
file = file[slash+1:]
|
||||
if slash := strings.LastIndex(file, "/"); slash >= 0 {
|
||||
path := file
|
||||
file = path[slash+1:]
|
||||
if l.addDirHeader {
|
||||
if dirsep := strings.LastIndex(path[:slash], "/"); dirsep >= 0 {
|
||||
file = path[dirsep+1:]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return l.formatHeader(s, file, line), file, line
|
||||
@@ -662,44 +696,143 @@ func (buf *buffer) someDigits(i, d int) int {
|
||||
return copy(buf.tmp[i:], buf.tmp[j:])
|
||||
}
|
||||
|
||||
func (l *loggingT) println(s severity, 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
|
||||
if logr != nil {
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprintln(buf, args...)
|
||||
l.output(s, buf, file, line, false)
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) print(s severity, args ...interface{}) {
|
||||
l.printDepth(s, 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, 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
|
||||
if logr != nil {
|
||||
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')
|
||||
}
|
||||
l.output(s, buf, file, line, false)
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) printf(s severity, 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
|
||||
if logr != nil {
|
||||
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')
|
||||
}
|
||||
l.output(s, buf, file, line, false)
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
}
|
||||
|
||||
// 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, 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
|
||||
if logr != nil {
|
||||
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')
|
||||
}
|
||||
l.output(s, buf, file, line, alsoToStderr)
|
||||
l.output(s, logr, buf, file, line, alsoToStderr)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
b.WriteByte(' ')
|
||||
b.WriteString(fmt.Sprintf("err=%q", err.Error()))
|
||||
}
|
||||
kvListFormat(b, keysAndValues...)
|
||||
l.printDepth(s, logging.logr, nil, depth+1, b)
|
||||
}
|
||||
|
||||
const missingValue = "(MISSING)"
|
||||
|
||||
func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
for i := 0; i < len(keysAndValues); i += 2 {
|
||||
var v interface{}
|
||||
k := keysAndValues[i]
|
||||
if i+1 < len(keysAndValues) {
|
||||
v = keysAndValues[i+1]
|
||||
} else {
|
||||
v = missingValue
|
||||
}
|
||||
b.WriteByte(' ')
|
||||
|
||||
switch v.(type) {
|
||||
case string, error:
|
||||
b.WriteString(fmt.Sprintf("%s=%q", 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// redirectBuffer is used to set an alternate destination for the logs
|
||||
@@ -719,8 +852,22 @@ func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
|
||||
return rb.w.Write(bytes)
|
||||
}
|
||||
|
||||
// SetLogger will set the backing logr implementation for klog.
|
||||
// If set, all log lines will be suppressed from the regular Output, and
|
||||
// redirected to the logr implementation.
|
||||
// All log lines include the 'severity', 'file' and 'line' values attached as
|
||||
// structured logging values.
|
||||
// Use as:
|
||||
// ...
|
||||
// klog.SetLogger(zapr.NewLogger(zapLog))
|
||||
func SetLogger(logr logr.Logger) {
|
||||
logging.logr = logr
|
||||
}
|
||||
|
||||
// SetOutput sets the output destination for all severities
|
||||
func SetOutput(w io.Writer) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
for s := fatalLog; s >= infoLog; s-- {
|
||||
rb := &redirectBuffer{
|
||||
w: w,
|
||||
@@ -731,6 +878,8 @@ func SetOutput(w io.Writer) {
|
||||
|
||||
// SetOutputBySeverity sets the output destination for specific severity
|
||||
func SetOutputBySeverity(name string, w io.Writer) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
sev, ok := severityByName(name)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("SetOutputBySeverity(%q): unrecognized severity name", name))
|
||||
@@ -741,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, 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) {
|
||||
@@ -750,30 +907,56 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
|
||||
}
|
||||
}
|
||||
data := buf.Bytes()
|
||||
if l.toStderr {
|
||||
if log != nil {
|
||||
// TODO: set 'severity' and caller information as structured log info
|
||||
// keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line}
|
||||
if s == errorLog {
|
||||
l.logr.Error(nil, string(data))
|
||||
} else {
|
||||
log.Info(string(data))
|
||||
}
|
||||
} else if l.toStderr {
|
||||
os.Stderr.Write(data)
|
||||
} else {
|
||||
if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {
|
||||
os.Stderr.Write(data)
|
||||
}
|
||||
if l.file[s] == nil {
|
||||
if err := l.createFiles(s); err != nil {
|
||||
os.Stderr.Write(data) // Make sure the message appears somewhere.
|
||||
l.exit(err)
|
||||
|
||||
if logging.logFile != "" {
|
||||
// Since we are using a single log file, all of the items in l.file array
|
||||
// will point to the same file, so just use one of them to write data.
|
||||
if l.file[infoLog] == nil {
|
||||
if err := l.createFiles(infoLog); err != nil {
|
||||
os.Stderr.Write(data) // Make sure the message appears somewhere.
|
||||
l.exit(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
} else {
|
||||
if l.file[s] == nil {
|
||||
if err := l.createFiles(s); err != nil {
|
||||
os.Stderr.Write(data) // Make sure the message appears somewhere.
|
||||
l.exit(err)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if s == fatalLog {
|
||||
@@ -784,14 +967,12 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
|
||||
os.Exit(1)
|
||||
}
|
||||
// Dump all goroutine stacks before exiting.
|
||||
// First, make sure we see the trace for the current goroutine on standard error.
|
||||
// If -logtostderr has been specified, the loop below will do that anyway
|
||||
// as the first stack in the full dump.
|
||||
if !l.toStderr {
|
||||
os.Stderr.Write(stacks(false))
|
||||
trace := stacks(true)
|
||||
// Write the stack trace for all goroutines to the stderr.
|
||||
if l.toStderr || l.alsoToStderr || s >= l.stderrThreshold.get() || alsoToStderr {
|
||||
os.Stderr.Write(trace)
|
||||
}
|
||||
// Write the stack trace for all goroutines to the files.
|
||||
trace := stacks(true)
|
||||
logExitFunc = func(error) {} // If we get a write error, we'll still exit below.
|
||||
for log := fatalLog; log >= infoLog; log-- {
|
||||
if f := l.file[log]; f != nil { // Can be nil if -logtostderr is set.
|
||||
@@ -812,7 +993,7 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
|
||||
|
||||
// timeoutFlush calls Flush and returns when it completes or after timeout
|
||||
// elapses, whichever happens first. This is needed because the hooks invoked
|
||||
// by Flush may deadlock when glog.Fatal is called from a hook that holds
|
||||
// by Flush may deadlock when klog.Fatal is called from a hook that holds
|
||||
// a lock.
|
||||
func timeoutFlush(timeout time.Duration) {
|
||||
done := make(chan bool, 1)
|
||||
@@ -823,7 +1004,7 @@ func timeoutFlush(timeout time.Duration) {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(timeout):
|
||||
fmt.Fprintln(os.Stderr, "glog: Flush took longer than", timeout)
|
||||
fmt.Fprintln(os.Stderr, "klog: Flush took longer than", timeout)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,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 {
|
||||
@@ -1041,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), file, line, true, text)
|
||||
logging.printWithFileLine(severity(lb), logging.logr, logging.filter, file, line, true, text)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
@@ -1073,32 +1262,44 @@ func (l *loggingT) setV(pc uintptr) Level {
|
||||
|
||||
// Verbose is a boolean type that implements Infof (like Printf) etc.
|
||||
// See the documentation of V for more information.
|
||||
type Verbose bool
|
||||
type Verbose struct {
|
||||
enabled bool
|
||||
logr logr.Logger
|
||||
filter LogFilter
|
||||
}
|
||||
|
||||
func newVerbose(level Level, b bool) Verbose {
|
||||
if logging.logr == nil {
|
||||
return Verbose{b, nil, logging.filter}
|
||||
}
|
||||
return Verbose{b, logging.logr.V(int(level)), logging.filter}
|
||||
}
|
||||
|
||||
// V reports whether verbosity at the call site is at least the requested level.
|
||||
// The returned value is a boolean of type Verbose, which implements Info, Infoln
|
||||
// The returned value is a struct of type Verbose, which implements Info, Infoln
|
||||
// and Infof. These methods will write to the Info log if called.
|
||||
// Thus, one may write either
|
||||
// if glog.V(2) { glog.Info("log this") }
|
||||
// if glog.V(2).Enabled() { klog.Info("log this") }
|
||||
// or
|
||||
// glog.V(2).Info("log this")
|
||||
// klog.V(2).Info("log this")
|
||||
// The second form is shorter but the first is cheaper if logging is off because it does
|
||||
// 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.
|
||||
|
||||
// Here is a cheap but safe test to see if V logging is enabled globally.
|
||||
if logging.verbosity.get() >= level {
|
||||
return Verbose(true)
|
||||
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
|
||||
@@ -1107,138 +1308,205 @@ func V(level Level) Verbose {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
if runtime.Callers(2, logging.pcs[:]) == 0 {
|
||||
return Verbose(false)
|
||||
return newVerbose(level, false)
|
||||
}
|
||||
v, ok := logging.vmap[logging.pcs[0]]
|
||||
if !ok {
|
||||
v = logging.setV(logging.pcs[0])
|
||||
}
|
||||
return Verbose(v >= level)
|
||||
return newVerbose(level, v >= level)
|
||||
}
|
||||
return Verbose(false)
|
||||
return newVerbose(level, false)
|
||||
}
|
||||
|
||||
// Enabled will return true if this log level is enabled, guarded by the value
|
||||
// of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Enabled() bool {
|
||||
return v.enabled
|
||||
}
|
||||
|
||||
// Info is equivalent to the global Info function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Info(args ...interface{}) {
|
||||
if v {
|
||||
logging.print(infoLog, args...)
|
||||
if v.enabled {
|
||||
logging.print(infoLog, v.logr, v.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// Infoln is equivalent to the global Infoln function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infoln(args ...interface{}) {
|
||||
if v {
|
||||
logging.println(infoLog, args...)
|
||||
if v.enabled {
|
||||
logging.println(infoLog, v.logr, v.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// Infof is equivalent to the global Infof function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
if v {
|
||||
logging.printf(infoLog, format, args...)
|
||||
if v.enabled {
|
||||
logging.printf(infoLog, v.logr, v.filter, format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// InfoS is equivalent to the global InfoS function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
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, 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, 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 appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Infoln(args ...interface{}) {
|
||||
logging.println(infoLog, 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, format, args...)
|
||||
logging.printf(infoLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// InfoS structured logs to the INFO log.
|
||||
// The msg argument used to add constant description to the log line.
|
||||
// The key/value pairs would be join by "=" ; a newline is always appended.
|
||||
//
|
||||
// Basic examples:
|
||||
// >> klog.InfoS("Pod status updated", "pod", "kubedns", "status", "ready")
|
||||
// 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.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, 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, 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 appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Warningln(args ...interface{}) {
|
||||
logging.println(warningLog, 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, 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, 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, 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 appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Errorln(args ...interface{}) {
|
||||
logging.println(errorLog, 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, format, args...)
|
||||
logging.printf(errorLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// ErrorS structured logs to the ERROR, WARNING, and INFO logs.
|
||||
// the err argument used as "err" field of log line.
|
||||
// The msg argument used to add constant description to the log line.
|
||||
// The key/value pairs would be join by "=" ; a newline is always appended.
|
||||
//
|
||||
// Basic examples:
|
||||
// >> klog.ErrorS(err, "Failed to update pod status")
|
||||
// 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.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, 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, 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 appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Fatalln(args ...interface{}) {
|
||||
logging.println(fatalLog, 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, format, args...)
|
||||
logging.printf(fatalLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// fatalNoStacks is non-zero if we are to exit without dumping goroutine stacks.
|
||||
@@ -1249,25 +1517,84 @@ 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, 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, 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, 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, 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
|
||||
type ObjectRef struct {
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
}
|
||||
|
||||
func (ref ObjectRef) String() string {
|
||||
if ref.Namespace != "" {
|
||||
return fmt.Sprintf("%s/%s", ref.Namespace, ref.Name)
|
||||
}
|
||||
return ref.Name
|
||||
}
|
||||
|
||||
// KMetadata is a subset of the kubernetes k8s.io/apimachinery/pkg/apis/meta/v1.Object interface
|
||||
// this interface may expand in the future, but will always be a subset of the
|
||||
// kubernetes k8s.io/apimachinery/pkg/apis/meta/v1.Object interface
|
||||
type KMetadata interface {
|
||||
GetName() string
|
||||
GetNamespace() string
|
||||
}
|
||||
|
||||
// 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(),
|
||||
}
|
||||
}
|
||||
|
||||
// KRef returns ObjectRef from name and namespace
|
||||
func KRef(namespace, name string) ObjectRef {
|
||||
return ObjectRef{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
}
|
||||
}
|
51
vendor/k8s.io/klog/klog_file.go → vendor/k8s.io/klog/v2/klog_file.go
generated
vendored
51
vendor/k8s.io/klog/klog_file.go → vendor/k8s.io/klog/v2/klog_file.go
generated
vendored
@@ -24,6 +24,7 @@ import (
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -43,25 +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)
|
||||
}
|
||||
}
|
||||
|
||||
current, err := user.Current()
|
||||
if err == nil {
|
||||
userName = current.Username
|
||||
}
|
||||
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)
|
||||
|
||||
// Sanitize userName since it may contain filepath separators on Windows.
|
||||
userName = strings.Replace(userName, `\`, "_", -1)
|
||||
// user.Current().Username normally produces something like 'USERDOMAIN\USERNAME'
|
||||
d := os.Getenv("USERDOMAIN")
|
||||
if len(d) != 0 {
|
||||
userName = d + "_" + u
|
||||
} else {
|
||||
userName = u
|
||||
}
|
||||
} else {
|
||||
current, err := user.Current()
|
||||
if err == nil {
|
||||
userName = current.Username
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return userName
|
||||
}
|
||||
|
||||
// shortHostname returns its argument, truncating at the first period.
|
||||
@@ -79,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