slog

package
v0.0.0-...-88d80bb Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 8 Imported by: 0

README

slog

Cross-platform logger for Go

Documentation

Overview

Package slog provides a cross-platform logging interface. It is designed to provide a universal logging interface on any operating system. It defaults to using the log package of the standard library, but can easily be used with other logging backends. Thus, we can use syslog on unicies and the event log on windows.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogLineNumber prints the file and line number of the caller.
	LogLineNumber = true
)

Functions

func Error

func Error(v ...interface{})

Error logs an error message.

func Errorf

func Errorf(format string, v ...interface{})

Errorf logs an error message.

func Errorln

func Errorln(v ...interface{})

Errorln logs an error message.

func Fatal

func Fatal(v ...interface{})

Fatal logs a fatal message and calls os.Exit(1).

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf logs a fatal message and calls os.Exit(1).

func Fatalln

func Fatalln(v ...interface{})

Fatalln logs a fatal message and calls os.Exit(1).

func Info

func Info(v ...interface{})

Info logs an info message.

func Infof

func Infof(format string, v ...interface{})

Infof logs an info message.

func Infoln

func Infoln(v ...interface{})

Infoln logs an info message.

func PanicAsFatal

func PanicAsFatal()

Add defer slog.PanicAsFatal() to the top of a goroutine to recover panics and log them using slog.Fatal

func Set

func Set(l Logger)

Set configures l to be the default logger for slog.

func SetSyslog

func SetSyslog(tag string) error

SetSyslog configures slog to use the system syslog daemon.

func Warning

func Warning(v ...interface{})

Warning logs a warning message.

func Warningf

func Warningf(format string, v ...interface{})

Warningf logs a warning message.

func Warningln

func Warningln(v ...interface{})

Warningln logs a warning message.

func Wrap

func Wrap(err error) error

Helper to wrap an error with relevant line information. Wrap an error when it enters "our" code before passing it up the stack. This will help narrow down the source of the error.

Types

type Logger

type Logger interface {
	Error(v string)
	Info(v string)
	Warning(v string)
	Fatal(v string)
}

Logger is the slog logging interface.

type StdLog

type StdLog struct {
	Log *log.Logger
}

StdLog logs to a log.Logger.

func (*StdLog) Error

func (s *StdLog) Error(v string)

Error logs an error message.

func (*StdLog) Fatal

func (s *StdLog) Fatal(v string)

Fatal logs a fatal message and calls os.Exit(1).

func (*StdLog) Info

func (s *StdLog) Info(v string)

Info logs an info message.

func (*StdLog) Warning

func (s *StdLog) Warning(v string)

Warning logs a warning message.

type Syslog

type Syslog struct {
	W *syslog.Writer
}

Syslog logs to syslog.

func (*Syslog) Error

func (s *Syslog) Error(v string)

Error logs an error message.

func (*Syslog) Fatal

func (s *Syslog) Fatal(v string)

Fatal logs a fatal message and calls os.Exit(1).

func (*Syslog) Info

func (s *Syslog) Info(v string)

Info logs an info message.

func (*Syslog) Warning

func (s *Syslog) Warning(v string)

Warning logs a warning message.

Jump to

Keyboard shortcuts

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