Documentation
¶
Overview ¶
Package log implements a small wrapper around the std lib log package. It implements log levels by prefixing the logs with [INFO], [DEBUG], [WARNING] or [ERROR]. Debug logging is available and enabled if the *debug* plugin is used. Configure can opt into structured JSON output instead of text prefixes.
log.Info("this is some logging"), will log on the Info level.
log.Debug("this is debug output"), will log in the Debug level, etc.
Index ¶
- Variables
- func Configure(format string, output io.Writer) error
- func Debug(v ...any)
- func Debugf(format string, v ...any)
- func DeregisterListener(old Listener) error
- func Discard()
- func Error(v ...any)
- func Errorf(format string, v ...any)
- func Fatal(v ...any)
- func Fatalf(format string, v ...any)
- func Info(v ...any)
- func InfoAttrs(msg string, attrs ...slog.Attr)
- func Infof(format string, v ...any)
- func IsJSON() bool
- func RegisterListener(new Listener) error
- func SetOutput(w io.Writer)
- func Warning(v ...any)
- func Warningf(format string, v ...any)
- type Listener
- type P
- func (p P) Debug(v ...any)
- func (p P) Debugf(format string, v ...any)
- func (p P) Error(v ...any)
- func (p P) Errorf(format string, v ...any)
- func (p P) Fatal(v ...any)
- func (p P) Fatalf(format string, v ...any)
- func (p P) Info(v ...any)
- func (p P) Infof(format string, v ...any)
- func (p P) Warning(v ...any)
- func (p P) Warningf(format string, v ...any)
Constants ¶
This section is empty.
Variables ¶
var D = &d{}
D controls whether we should output debug logs. If true, we do, once set it can not be unset.
Functions ¶
func Configure ¶ added in v1.15.0
Configure selects text (the default) or JSON logging and its destination. Call it at process startup, before starting servers. The format is process-wide and should not be changed by individual plugins or during a Corefile reload. JSON mode also routes the standard library's default logger through this backend, at INFO level, without interpreting message text as structured data.
func Debug ¶
func Debug(v ...any)
Debug is equivalent to log.Print(), but prefixed with "[DEBUG] ". It only outputs something if D is true.
func Debugf ¶
Debugf is equivalent to log.Printf(), but prefixed with "[DEBUG] ". It only outputs something if D is true.
func DeregisterListener ¶ added in v1.9.4
DeregisterListener deregister a listener object.
func Fatal ¶ added in v1.2.1
func Fatal(v ...any)
Fatal is equivalent to log.Print, but prefixed with "[FATAL] ", and calling os.Exit(1).
func Fatalf ¶ added in v1.2.1
Fatalf is equivalent to log.Printf, but prefixed with "[FATAL] ", and calling os.Exit(1)
func InfoAttrs ¶ added in v1.15.0
InfoAttrs logs msg with typed attributes in JSON mode. In text mode it is equivalent to Info(msg). Like Info, it does not call named-plugin listeners.
func IsJSON ¶ added in v1.15.0
func IsJSON() bool
IsJSON reports whether structured logging is enabled.
func RegisterListener ¶ added in v1.9.4
RegisterListener register a listener object.
func SetOutput ¶ added in v1.15.0
SetOutput changes the destination of both CoreDNS and standard-library logs. Use this instead of log.SetOutput when JSON logging is enabled.
Types ¶
type Listener ¶ added in v1.9.4
type Listener interface {
Name() string
Debug(plugin string, v ...any)
Debugf(plugin string, format string, v ...any)
Info(plugin string, v ...any)
Infof(plugin string, format string, v ...any)
Warning(plugin string, v ...any)
Warningf(plugin string, format string, v ...any)
Error(plugin string, v ...any)
Errorf(plugin string, format string, v ...any)
Fatal(plugin string, v ...any)
Fatalf(plugin string, format string, v ...any)
}
Listener listens for all log prints of plugin loggers aka loggers with plugin name. When a plugin logger gets called, it should first call the same method in the Listener object. A usage example is, the external plugin k8s_event will replicate log prints to Kubernetes events.
type P ¶
type P struct {
// contains filtered or unexported fields
}
P is a logger that includes the plugin doing the logging.
func NewWithPlugin ¶
NewWithPlugin returns a logger that includes "plugin/name: " in the log message. I.e [INFO] plugin/<name>: message.