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 ¶
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 ¶
DeregisterListener deregister a listener object.
func Fatal ¶
func Fatal(v ...any)
Fatal is equivalent to log.Print, but prefixed with "[FATAL] ", and calling os.Exit(1).
func Fatalf ¶
Fatalf is equivalent to log.Printf, but prefixed with "[FATAL] ", and calling os.Exit(1)
func InfoAttrs ¶
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 RegisterListener ¶
RegisterListener register a listener object.
func SetOutput ¶
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 ¶
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.