logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

logger

logger is a logging library for Go with multiple output destinations and semantic logging methods.

Installation

go get crdx.org/logger

Usage

import "crdx.org/logger"

func main() {
    logger.InitStderr() // see below for other types

    logger.Info("starting up")
    logger.Added("new device: %s", name)
    logger.Warn("disk usage at %d%%", usage)
    logger.Fatal(err)
}
Initialisation
logger.InitStderr()
logger.InitSyslog()
logger.InitNull()

If you need dynamic initialisation, pass a destination directly.

logger.Init(logger.DestinationStderr)
logger.Init(logger.DestinationSyslog)
logger.Init(logger.DestinationNull)

Methods

All methods accept a format string and variadic arguments.

Status
Method Prefix Colour
Added [+] Green
Removed [-] Yellow
Succeeded [✓] Green
Failed [𐄂] Red
Enabled [✓] Green
Disabled [𐄂] Red
General
Method Description
Print General message.
Info Info message.
Warn Warning (yellow, prefixed with "Warning:").
Err Error (red, prefixed with "Error:"). Accepts error or string.
Fatal Like Err, but calls os.Exit(1) after logging.

Destinations

Three output destinations are available.

Stderr

Logs to standard error with colour-coded output. Status methods are prefixed with relevant status symbols.

Syslog

Logs to the system log with the program name as the tag. Messages are routed to info or error level as appropriate.

Null

Silently discards all log output. Useful for testing.

Contributions

Open an issue or send a pull request.

Licence

GPLv3.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Added

func Added(v string, args ...any)

Added logs a message prefixed with [+].

func Disabled

func Disabled(v string, args ...any)

Disabled logs a message prefixed with [𐄂].

func Enabled

func Enabled(v string, args ...any)

Enabled logs a message prefixed with [✓].

func Err

func Err(v any, args ...any)

Err logs an error message.

func Failed

func Failed(v string, args ...any)

Failed logs a message prefixed with [𐄂].

func Fatal

func Fatal(v any, args ...any)

Fatal logs an error message and then exits.

func Info

func Info(v string, args ...any)

Info logs an informative message.

func Init

func Init(destination Destination)

func InitNull

func InitNull()

func InitStderr

func InitStderr()

func InitSyslog

func InitSyslog()

func Print

func Print(v string, args ...any)

Print logs a general message.

func Removed

func Removed(v string, args ...any)

Removed logs a message prefixed with [-].

func Succeeded

func Succeeded(v string, args ...any)

Succeeded logs a message prefixed with [✓].

func Warn

func Warn(v string, args ...any)

Warn logs a warning message.

Types

type Destination

type Destination int
const (
	DestinationSyslog Destination = iota + 1
	DestinationStderr
	DestinationNull
)

type Logger

type Logger interface {
	Added(v string, args ...any)
	Removed(v string, args ...any)
	Enabled(v string, args ...any)
	Disabled(v string, args ...any)
	Succeeded(v string, args ...any)
	Failed(v string, args ...any)
	Print(v string, args ...any)
	Info(v string, args ...any)
	Warn(v string, args ...any)
	Err(v string, args ...any)
}

type NullLogger

type NullLogger struct{}

func NewNullLogger

func NewNullLogger() *NullLogger

func (*NullLogger) Added

func (*NullLogger) Added(string, ...any)

func (*NullLogger) Disabled

func (*NullLogger) Disabled(string, ...any)

func (*NullLogger) Enabled

func (*NullLogger) Enabled(string, ...any)

func (*NullLogger) Err

func (*NullLogger) Err(string, ...any)

func (*NullLogger) Failed

func (*NullLogger) Failed(string, ...any)

func (*NullLogger) Info

func (*NullLogger) Info(string, ...any)

func (*NullLogger) Print

func (*NullLogger) Print(string, ...any)

func (*NullLogger) Removed

func (*NullLogger) Removed(string, ...any)

func (*NullLogger) Succeeded

func (*NullLogger) Succeeded(string, ...any)

func (*NullLogger) Warn

func (*NullLogger) Warn(string, ...any)

type StderrLogger

type StderrLogger struct {
	// contains filtered or unexported fields
}

func NewStderrLogger

func NewStderrLogger() *StderrLogger

func (*StderrLogger) Added

func (self *StderrLogger) Added(s string, args ...any)

func (*StderrLogger) Disabled

func (self *StderrLogger) Disabled(s string, args ...any)

func (*StderrLogger) Enabled

func (self *StderrLogger) Enabled(s string, args ...any)

func (*StderrLogger) Err

func (self *StderrLogger) Err(s string, args ...any)

func (*StderrLogger) Failed

func (self *StderrLogger) Failed(s string, args ...any)

func (*StderrLogger) Info

func (self *StderrLogger) Info(s string, args ...any)

func (*StderrLogger) Print

func (self *StderrLogger) Print(s string, args ...any)

func (*StderrLogger) Removed

func (self *StderrLogger) Removed(s string, args ...any)

func (*StderrLogger) Succeeded

func (self *StderrLogger) Succeeded(s string, args ...any)

func (*StderrLogger) Warn

func (self *StderrLogger) Warn(s string, args ...any)

type SyslogLogger

type SyslogLogger struct {
	// contains filtered or unexported fields
}

func NewSyslogLogger

func NewSyslogLogger() *SyslogLogger

func (*SyslogLogger) Added

func (self *SyslogLogger) Added(s string, args ...any)

func (*SyslogLogger) Disabled

func (self *SyslogLogger) Disabled(s string, args ...any)

func (*SyslogLogger) Enabled

func (self *SyslogLogger) Enabled(s string, args ...any)

func (*SyslogLogger) Err

func (self *SyslogLogger) Err(s string, args ...any)

func (*SyslogLogger) Failed

func (self *SyslogLogger) Failed(s string, args ...any)

func (*SyslogLogger) Info

func (self *SyslogLogger) Info(s string, args ...any)

func (*SyslogLogger) Print

func (self *SyslogLogger) Print(s string, args ...any)

func (*SyslogLogger) Removed

func (self *SyslogLogger) Removed(s string, args ...any)

func (*SyslogLogger) Succeeded

func (self *SyslogLogger) Succeeded(s string, args ...any)

func (*SyslogLogger) Warn

func (self *SyslogLogger) Warn(s string, args ...any)

Jump to

Keyboard shortcuts

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