type severityValue … // get returns the value of the severity. func (s *severityValue) get() severity.Severity { … } // set sets the value of the severity. func (s *severityValue) set(val severity.Severity) { … } // String is part of the flag.Value interface. func (s *severityValue) String() string { … } // Get is part of the flag.Getter interface. func (s *severityValue) Get() interface{ … } // Set is part of the flag.Value interface. func (s *severityValue) Set(value string) error { … } type OutputStats … // Lines returns the number of lines written. func (s *OutputStats) Lines() int64 { … } // Bytes returns the number of bytes written. func (s *OutputStats) Bytes() int64 { … } var Stats … var severityStats … type Level … // get returns the value of the Level. func (l *Level) get() Level { … } // set sets the value of the Level. func (l *Level) set(val Level) { … } // String is part of the flag.Value interface. func (l *Level) String() string { … } // Get is part of the flag.Getter interface. func (l *Level) Get() interface{ … } // Set is part of the flag.Value interface. func (l *Level) Set(value string) error { … } type moduleSpec … type modulePat … // match reports whether the file matches the pattern. It uses a string // comparison if the pattern contains no metacharacters. func (m *modulePat) match(file string) bool { … } func (m *moduleSpec) String() string { … } func (m *moduleSpec) serialize() string { … } // Get is part of the (Go 1.2) flag.Getter interface. It always returns nil for this flag type since the // struct is not exported. func (m *moduleSpec) Get() interface{ … } var errVmoduleSyntax … // Set will sets module value // Syntax: -vmodule=recordio=2,file=1,gfs*=3 func (m *moduleSpec) Set(value string) error { … } func parseModuleSpec(value string) ([]modulePat, error) { … } // isLiteral reports whether the pattern is a literal string, that is, has no metacharacters // that require filepath.Match to be called to match the pattern. func isLiteral(pattern string) bool { … } type traceLocation … // isSet reports whether the trace location has been specified. // logging.mu is held. func (t *traceLocation) isSet() bool { … } // match reports whether the specified file and line matches the trace location. // The argument file name is the full path, not the basename specified in the flag. // logging.mu is held. func (t *traceLocation) match(file string, line int) bool { … } func (t *traceLocation) String() string { … } // Get is part of the (Go 1.2) flag.Getter interface. It always returns nil for this flag type since the // struct is not exported func (t *traceLocation) Get() interface{ … } var errTraceSyntax … // Set will sets backtrace value // Syntax: -log_backtrace_at=gopherflakes.go:234 // Note that unlike vmodule the file extension is included here. func (t *traceLocation) Set(value string) error { … } var logging … var commandLine … // init sets up the defaults and creates command line flags. func init() { … } // InitFlags is for explicitly initializing the flags. // It may get called repeatedly for different flagsets, but not // twice for the same one. May get called concurrently // to other goroutines using klog. However, only some flags // may get set concurrently (see implementation). func InitFlags(flagset *flag.FlagSet) { … } // Flush flushes all pending log I/O. func Flush() { … } type settings … // deepCopy creates a copy that doesn't share anything with the original // instance. func (s settings) deepCopy() settings { … } type loggingT … // setVState sets a consistent state for V logging. // l.mu is held. func (l *loggingT) setVState(verbosity Level, filter []modulePat, setFilter bool) { … } var timeNow … // CaptureState gathers information about all current klog settings. // The result can be used to restore those settings. func CaptureState() State { … } type State … type state … func (s *state) Restore() { … } /* header formats a log header as defined by the C++ implementation. It returns a buffer containing the formatted header and the user's file and line number. The depth specifies how many stack frames above lives the source line to be identified in the log message. Log lines have this form: Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... where the fields are defined as follows: L A single character, representing the log level (eg 'I' for INFO) mm The month (zero padded; ie May is '05') dd The day (zero padded) hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds threadid The space-padded thread ID as returned by GetTID() file The file name line The line number msg The user-supplied message */ func (l *loggingT) header(s severity.Severity, depth int) (*buffer.Buffer, string, int) { … } // formatHeader formats a log header using the provided file name and line number. func (l *loggingT) formatHeader(s severity.Severity, file string, line int, now time.Time) *buffer.Buffer { … } func (l *loggingT) println(s severity.Severity, logger *logWriter, filter LogFilter, args ...interface{ … } func (l *loggingT) printlnDepth(s severity.Severity, logger *logWriter, filter LogFilter, depth int, args ...interface{ … } func (l *loggingT) print(s severity.Severity, logger *logWriter, filter LogFilter, args ...interface{ … } func (l *loggingT) printDepth(s severity.Severity, logger *logWriter, filter LogFilter, depth int, args ...interface{ … } func (l *loggingT) printWithInfos(buf *buffer.Buffer, file string, line int, s severity.Severity, logger *logWriter, filter LogFilter, depth int, args ...interface{ … } func (l *loggingT) printf(s severity.Severity, logger *logWriter, filter LogFilter, format string, args ...interface{ … } func (l *loggingT) printfDepth(s severity.Severity, logger *logWriter, filter LogFilter, depth int, format string, args ...interface{ … } // 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.Severity, logger *logWriter, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{ … } // if logger is specified, will call logger.Error, otherwise output with logging module. func (l *loggingT) errorS(err error, logger *logWriter, filter LogFilter, depth int, msg string, keysAndValues ...interface{ … } // if logger is specified, will call logger.Info, otherwise output with logging module. func (l *loggingT) infoS(logger *logWriter, filter LogFilter, depth int, msg string, keysAndValues ...interface{ … } // printS is called from infoS and errorS if logger is not specified. // set log severity by s func (l *loggingT) printS(err error, s severity.Severity, depth int, msg string, keysAndValues ...interface{ … } // SetOutput sets the output destination for all severities func SetOutput(w io.Writer) { … } // SetOutputBySeverity sets the output destination for specific severity func SetOutputBySeverity(name string, w io.Writer) { … } // LogToStderr sets whether to log exclusively to stderr, bypassing outputs func LogToStderr(stderr bool) { … } // output writes the data to the log files and releases the buffer. func (l *loggingT) output(s severity.Severity, logger *logWriter, buf *buffer.Buffer, depth int, file string, line int, alsoToStderr bool) { … } var logExitFunc … // exit is called if there is trouble creating or writing log files. // It flushes the logs and exits the program; there's no point in hanging around. // l.mu is held. func (l *loggingT) exit(err error) { … } type syncBuffer … // CalculateMaxSize returns the real max size in bytes after considering the default max size and the flag options. func CalculateMaxSize() uint64 { … } func (sb *syncBuffer) Write(p []byte) (n int, err error) { … } // rotateFile closes the syncBuffer's file and starts a new one. // The startup argument indicates whether this is the initial startup of klog. // If startup is true, existing files are opened for appending instead of truncated. func (sb *syncBuffer) rotateFile(now time.Time, startup bool) error { … } const bufferSize … // createFiles creates all the log files for severity from sev down to infoLog. // l.mu is held. func (l *loggingT) createFiles(sev severity.Severity) error { … } const flushInterval … type flushDaemon … // newFlushDaemon returns a new flushDaemon. If the passed clock is nil, a // clock.RealClock is used. func newFlushDaemon(flush func(), tickClock clock.Clock) *flushDaemon { … } // run starts a goroutine that periodically calls the daemons flush function. // Calling run on an already running daemon will have no effect. func (f *flushDaemon) run(interval time.Duration) { … } // stop stops the running flushDaemon and waits until the daemon has shut down. // Calling stop on a daemon that isn't running will have no effect. func (f *flushDaemon) stop() { … } // isRunning returns true if the flush daemon is running. func (f *flushDaemon) isRunning() bool { … } // StopFlushDaemon stops the flush daemon, if running, and flushes once. // This prevents klog from leaking goroutines on shutdown. After stopping // the daemon, you can still manually flush buffers again by calling Flush(). func StopFlushDaemon() { … } // StartFlushDaemon ensures that the flush daemon runs with the given delay // between flush calls. If it is already running, it gets restarted. func StartFlushDaemon(interval time.Duration) { … } // lockAndFlushAll is like flushAll but locks l.mu first. func (l *loggingT) lockAndFlushAll() { … } // flushAll flushes all the logs // l.mu is held. // // The result is the number of files which need to be synced and the pointers to them. func (l *loggingT) flushAll() fileArray { … } type fileArray … // syncAll attempts to "sync" their data to disk. func (l *loggingT) syncAll(needToSync fileArray) { … } // CopyStandardLogTo arranges for messages written to the Go "log" package's // default logs to also appear in the Google logs for the named and lower // severities. Subsequent changes to the standard log's default output location // or format may break this behavior. // // Valid names are "INFO", "WARNING", "ERROR", and "FATAL". If the name is not // recognized, CopyStandardLogTo panics. func CopyStandardLogTo(name string) { … } // NewStandardLogger returns a Logger that writes to the klog logs for the // named and lower severities. // // Valid names are "INFO", "WARNING", "ERROR", and "FATAL". If the name is not // recognized, NewStandardLogger panics. func NewStandardLogger(name string) *stdLog.Logger { … } type logBridge … // Write parses the standard logging line and passes its components to the // logger for severity(lb). func (lb logBridge) Write(b []byte) (n int, err error) { … } // setV computes and remembers the V level for a given PC // when vmodule is enabled. // File pattern matching takes the basename of the file, stripped // of its .go suffix, and uses filepath.Match, which is a little more // general than the *? matching used in C++. // l.mu is held. func (l *loggingT) setV(pc uintptr) Level { … } type Verbose … func newVerbose(level Level, b bool) Verbose { … } // V reports whether verbosity at the call site is at least the requested level. // 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 klog.V(2).Enabled() { klog.Info("log this") } // // or // // 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. 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 { … } // VDepth is a variant of V that accepts a number of stack frames that will be // skipped when checking the -vmodule patterns. VDepth(0) is equivalent to // V(). func VDepth(depth int, level Level) Verbose { … } // 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 { … } // 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{ … } // InfoDepth is equivalent to the global InfoDepth function, guarded by the value of v. // See the documentation of V for usage. func (v Verbose) InfoDepth(depth int, args ...interface{ … } // 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{ … } // InfolnDepth is equivalent to the global InfolnDepth function, guarded by the value of v. // See the documentation of V for usage. func (v Verbose) InfolnDepth(depth int, args ...interface{ … } // 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{ … } // InfofDepth is equivalent to the global InfofDepth function, guarded by the value of v. // See the documentation of V for usage. func (v Verbose) InfofDepth(depth int, format string, args ...interface{ … } // 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{ … } // 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{ … } // InfoSDepth is equivalent to the global InfoSDepth function, guarded by the value of v. // See the documentation of V for usage. func (v Verbose) InfoSDepth(depth int, msg string, keysAndValues ...interface{ … } // Deprecated: Use ErrorS instead. func (v Verbose) Error(err error, msg string, args ...interface{ … } // 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{ … } // 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{ … } // 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{ … } // Infoln logs to the INFO log. // Arguments are handled in the manner of fmt.Println; a newline is always appended. func Infoln(args ...interface{ … } // InfolnDepth acts as Infoln but uses depth to determine which call frame to log. // InfolnDepth(0, "msg") is the same as Infoln("msg"). func InfolnDepth(depth int, args ...interface{ … } // 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{ … } // InfofDepth acts as Infof but uses depth to determine which call frame to log. // InfofDepth(0, "msg", args...) is the same as Infof("msg", args...). func InfofDepth(depth int, format string, args ...interface{ … } // 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{ … } // 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{ … } // 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{ … } // 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{ … } // WarninglnDepth acts as Warningln but uses depth to determine which call frame to log. // WarninglnDepth(0, "msg") is the same as Warningln("msg"). func WarninglnDepth(depth int, args ...interface{ … } // 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{ … } // WarningfDepth acts as Warningf but uses depth to determine which call frame to log. // WarningfDepth(0, "msg", args...) is the same as Warningf("msg", args...). func WarningfDepth(depth int, format string, args ...interface{ … } // 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{ … } // 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{ … } // 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{ … } // ErrorlnDepth acts as Errorln but uses depth to determine which call frame to log. // ErrorlnDepth(0, "msg") is the same as Errorln("msg"). func ErrorlnDepth(depth int, args ...interface{ … } // 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{ … } // ErrorfDepth acts as Errorf but uses depth to determine which call frame to log. // ErrorfDepth(0, "msg", args...) is the same as Errorf("msg", args...). func ErrorfDepth(depth int, format string, args ...interface{ … } // 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{ … } // 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{ … } // Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, // prints stack trace(s), then calls OsExit(255). // // Stderr only receives a dump of the current goroutine's stack trace. Log files, // if there are any, receive a dump of the stack traces in all goroutines. // // Callers who want more control over handling of fatal events may instead use a // combination of different functions: // - some info or error logging function, optionally with a stack trace // value generated by github.com/go-logr/lib/dbg.Backtrace // - Flush to flush pending log data // - panic, os.Exit or returning to the caller with an error // // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Fatal(args ...interface{ … } // 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{ … } // Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, // including a stack trace of all running goroutines, then calls OsExit(255). // Arguments are handled in the manner of fmt.Println; a newline is always appended. func Fatalln(args ...interface{ … } // FatallnDepth acts as Fatalln but uses depth to determine which call frame to log. // FatallnDepth(0, "msg") is the same as Fatalln("msg"). func FatallnDepth(depth int, args ...interface{ … } // Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, // including a stack trace of all running goroutines, then calls OsExit(255). // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Fatalf(format string, args ...interface{ … } // FatalfDepth acts as Fatalf but uses depth to determine which call frame to log. // FatalfDepth(0, "msg", args...) is the same as Fatalf("msg", args...). func FatalfDepth(depth int, format string, args ...interface{ … } var fatalNoStacks … // Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls OsExit(1). // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Exit(args ...interface{ … } // 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{ … } // Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls OsExit(1). func Exitln(args ...interface{ … } // ExitlnDepth acts as Exitln but uses depth to determine which call frame to log. // ExitlnDepth(0, "msg") is the same as Exitln("msg"). func ExitlnDepth(depth int, args ...interface{ … } // Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls OsExit(1). // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Exitf(format string, args ...interface{ … } // ExitfDepth acts as Exitf but uses depth to determine which call frame to log. // ExitfDepth(0, "msg", args...) is the same as Exitf("msg", args...). func ExitfDepth(depth int, format string, args ...interface{ … } type LogFilter … // SetLogFilter installs a filter that is used for all log calls. // // Modifying the filter is not thread-safe and should be done while no other // goroutines invoke log calls, usually during program initialization. func SetLogFilter(filter LogFilter) { … }