log

package
v0.0.4-openssl Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func Configure(format string, output io.Writer) error

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

func Debugf(format string, v ...any)

Debugf is equivalent to log.Printf(), but prefixed with "[DEBUG] ". It only outputs something if D is true.

func DeregisterListener

func DeregisterListener(old Listener) error

DeregisterListener deregister a listener object.

func Discard

func Discard()

Discard sets the log output to /dev/null.

func Error

func Error(v ...any)

Error is equivalent to log.Print, but prefixed with "[ERROR] ".

func Errorf

func Errorf(format string, v ...any)

Errorf is equivalent to log.Printf, but prefixed with "[ERROR] ".

func Fatal

func Fatal(v ...any)

Fatal is equivalent to log.Print, but prefixed with "[FATAL] ", and calling os.Exit(1).

func Fatalf

func Fatalf(format string, v ...any)

Fatalf is equivalent to log.Printf, but prefixed with "[FATAL] ", and calling os.Exit(1)

func Info

func Info(v ...any)

Info is equivalent to log.Print, but prefixed with "[INFO] ".

func InfoAttrs

func InfoAttrs(msg string, attrs ...slog.Attr)

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 Infof

func Infof(format string, v ...any)

Infof is equivalent to log.Printf, but prefixed with "[INFO] ".

func IsJSON

func IsJSON() bool

IsJSON reports whether structured logging is enabled.

func RegisterListener

func RegisterListener(new Listener) error

RegisterListener register a listener object.

func SetOutput

func SetOutput(w io.Writer)

SetOutput changes the destination of both CoreDNS and standard-library logs. Use this instead of log.SetOutput when JSON logging is enabled.

func Warning

func Warning(v ...any)

Warning is equivalent to log.Print, but prefixed with "[WARNING] ".

func Warningf

func Warningf(format string, v ...any)

Warningf is equivalent to log.Printf, but prefixed with "[WARNING] ".

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

func NewWithPlugin(name string) P

NewWithPlugin returns a logger that includes "plugin/name: " in the log message. I.e [INFO] plugin/<name>: message.

func (P) Debug

func (p P) Debug(v ...any)

Debug logs as log.Debug.

func (P) Debugf

func (p P) Debugf(format string, v ...any)

Debugf logs as log.Debugf.

func (P) Error

func (p P) Error(v ...any)

Error logs as log.Error.

func (P) Errorf

func (p P) Errorf(format string, v ...any)

Errorf logs as log.Errorf.

func (P) Fatal

func (p P) Fatal(v ...any)

Fatal logs as log.Fatal and calls os.Exit(1).

func (P) Fatalf

func (p P) Fatalf(format string, v ...any)

Fatalf logs as log.Fatalf and calls os.Exit(1).

func (P) Info

func (p P) Info(v ...any)

Info logs as log.Info.

func (P) Infof

func (p P) Infof(format string, v ...any)

Infof logs as log.Infof.

func (P) Warning

func (p P) Warning(v ...any)

Warning logs as log.Warning.

func (P) Warningf

func (p P) Warningf(format string, v ...any)

Warningf logs as log.Warningf.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL