log

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 104

README

Go Reference Go Report Go Version License Disgo Version Disgo Discord

log

The Logger interface can be used instead to give the user choice over which logger they want use

This lib ships with a default implementation of the Logger interface

SimpleLogger is a wrapped standard Logger to fit the Logger interface

You can use your own implementation or a library like logrus

Installing
go get github.com/disgoorg/log

Documentation

Overview

Package log based on https://en.wikipedia.org/wiki/ANSI_escape_code

Index

Constants

View Source
const (
	Ldate         = 1 << iota     // the date in the local time zone: 2009/01/23
	Ltime                         // the time in the local time zone: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	LUTC                          // if Ldate or Ltime is set, use UTC rather than the local time zone
	Lmsgprefix                    // move the "prefix" from the beginning of the line to before the message
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)

These flags define which text to prefix to each Output entry generated by the Logger. Bits are or'ed together to control what's printed. Except the Lmsgprefix flag, there is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,

2009/01/23 01:23:23 message

while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

View Source
var (
	EnableColors = true
	PrefixStyle  = ForegroundColorBrightBlack
	LevelStyle   = StyleBold
	TextStyle    = ForegroundColorWhite
)
View Source
var (
	StyleReset       = newInt(0)
	StyleBold        = newInt(1)
	StyleFaint       = newInt(2)
	StyleItalic      = newInt(3)
	StyleUnderline   = newInt(4)
	StyleSlowBlink   = newInt(5)
	StyleRapidBlink  = newInt(6)
	StyleInvert      = newInt(7)
	StyleHide        = newInt(8)
	StyleStrike      = newInt(9)
	StyleDefaultFont = newInt(10)
)

general Style(s)any

View Source
var (
	StyleBlackLetterFont             = newInt(20)
	StyleDoubleUnderlined            = newInt(21)
	StyleNormalIntensity             = newInt(22)
	StyleNeitherItalicNorBlackLetter = newInt(23)
	StyleNotUnderlined               = newInt(24)
	StyleNotBlinking                 = newInt(25)
	StyleProportionalSpacing         = newInt(26)
	StyleNotReversed                 = newInt(27)
	StyleReveal                      = newInt(28)
	StyleNotCrossedOut               = newInt(29)
)

more general Style(s)any

View Source
var (
	ForegroundColorBlack   = newInt(30)
	ForegroundColorRed     = newInt(31)
	ForegroundColorGreen   = newInt(32)
	ForegroundColorYellow  = newInt(33)
	ForegroundColorBlue    = newInt(34)
	ForegroundColorMagenta = newInt(35)
	ForegroundColorCyan    = newInt(36)
	ForegroundColorWhite   = newInt(37)
)

foreground color Style(s)any

View Source
var (
	DefaultForegroundColor = newInt(39)
	BackgroundColorBlack   = newInt(40)
	BackgroundColorRed     = newInt(41)
	BackgroundColorGreen   = newInt(42)
	BackgroundColorYellow  = newInt(43)
	BackgroundColorBlue    = newInt(44)
	BackgroundColorMagenta = newInt(45)
	BackgroundColorCyan    = newInt(46)
	BackgroundColorWhite   = newInt(47)
)

background color Style(s)any

View Source
var (
	DefaultBackgroundColor          = newInt(49)
	StyleDisableProportionalSpacing = newInt(50)
	StyleFramed                     = newInt(51)
	StyleEncircled                  = newInt(52)
	StyleOverlined                  = newInt(53)
	StyleNeitherFramedNorEncircled  = newInt(54)
	StyleNotOverlined               = newInt(55)
)

more general Style(s)any

View Source
var (
	StyleDefaultUnderlineColor                           = newInt(59)
	StyleIdeogramUnderlineOrRightSideLine                = newInt(60)
	StyleIdeogramDoubleUnderlineOrDoubleLineOnRightSide  = newInt(61)
	StyleIdeogramOverlineOrLeftSideLine                  = newInt(62)
	StyleIdeogramDoubleOverlineOrDoubleLineOnTheLeftSide = newInt(63)
	StyleIdeogramStressMarking                           = newInt(64)
	StyleNoIdeogramAttributes                            = newInt(65)
)

more general Style(s)any

View Source
var (
	StyleSuperscript                    = newInt(73)
	StyleSubscript                      = newInt(74)
	StyleNeitherSuperscriptNorSubscript = newInt(75)
)

super/subscript Style(s)any

View Source
var (
	ForegroundColorBrightBlack   = newInt(90)
	ForegroundColorBrightRed     = newInt(91)
	ForegroundColorBrightGreen   = newInt(92)
	ForegroundColorBrightYellow  = newInt(93)
	ForegroundColorBrightBlue    = newInt(94)
	ForegroundColorBrightMagenta = newInt(95)
	ForegroundColorBrightCyan    = newInt(96)
	ForegroundColorBrightWhite   = newInt(97)
)

foreground bright color Style(s)any

View Source
var (
	BackgroundColorBrightBlack   = newInt(100)
	BackgroundColorBrightRed     = newInt(101)
	BackgroundColorBrightGreen   = newInt(102)
	BackgroundColorBrightYellow  = newInt(103)
	BackgroundColorBrightBlue    = newInt(104)
	BackgroundColorBrightMagenta = newInt(105)
	BackgroundColorBrightCyan    = newInt(106)
	BackgroundColorBrightWhite   = newInt(107)
)

background bright color Style(s)any

Functions

func ApplyStyles added in v1.2.0

func ApplyStyles(message string, colors ...Style) string

ApplyStyles wraps a given message in the given Style(s).

func Debug added in v1.2.0

func Debug(v ...any)

Debug logs on the LevelDebug with the default SimpleLogger

func Debugf added in v1.2.0

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

Debugf logs on the LevelDebug with the default SimpleLogger

func Error added in v1.2.0

func Error(v ...any)

Error logs on the LevelError with the default SimpleLogger

func Errorf added in v1.2.0

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

Errorf logs on the LevelError with the default SimpleLogger

func Fatal added in v1.2.0

func Fatal(v ...any)

Fatal logs on the LevelFatal with the default SimpleLogger

func Fatalf added in v1.2.0

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

Fatalf logs on the LevelFatal with the default SimpleLogger

func Info added in v1.2.0

func Info(v ...any)

Info logs on the LevelInfo with the default SimpleLogger

func Infof added in v1.2.0

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

Infof logs on the LevelInfo with the default SimpleLogger

func Output added in v1.2.0

func Output(calldepth int, level Level, v ...any)

func Outputf added in v1.2.0

func Outputf(calldepth int, level Level, format string, v ...any)

func Panic added in v1.2.0

func Panic(v ...any)

Panic logs on the LevelPanic with the default SimpleLogger

func Panicf added in v1.2.0

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

Panicf logs on the LevelPanic with the default SimpleLogger

func SetDefault added in v1.2.0

func SetDefault(logger *SimpleLogger)

SetDefault sets the default SimpleLogger

func SetFlags added in v1.2.0

func SetFlags(flags int)

SetFlags sets the Output flags like: Ldate, Ltime, Lmicroseconds, Llongfile, Lshortfile, LUTC, Lmsgprefix,LstdFlags of the default Logger

func SetLevel added in v1.2.0

func SetLevel(level Level)

SetLevel sets the Level of the default Logger

func SetLevelColor added in v1.2.0

func SetLevelColor(level Level, color Style)

SetLevelColor sets the Style of the given Level

func Trace added in v1.2.0

func Trace(v ...any)

Trace logs on the LevelTrace with the default SimpleLogger

func Tracef added in v1.2.0

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

Tracef logs on the LevelTrace with the default SimpleLogger

func Warn added in v1.2.0

func Warn(v ...any)

Warn logs on the LevelWarn with the default SimpleLogger

func Warnf added in v1.2.0

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

Warnf logs on the Level with the default SimpleLogger

Types

type Level added in v1.2.0

type Level int

Level are different levels at which the SimpleLogger can Output

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelPanic
)

All Level(s) which SimpleLogger supports

func (Level) String added in v1.2.0

func (l Level) String() string

String returns the name of the Level

type Logger

type Logger interface {
	Trace(args ...any)
	Debug(args ...any)
	Info(args ...any)
	Warn(args ...any)
	Error(args ...any)
	Fatal(args ...any)
	Panic(args ...any)

	Tracef(format string, args ...any)
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
	Fatalf(format string, args ...any)
	Panicf(format string, args ...any)
}

Logger is the logging interface you can implement/use

func NewNoop added in v1.2.1

func NewNoop() Logger

NewNoop creates a new noop logger

type SimpleLogger added in v1.2.0

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

SimpleLogger is a wrapper for the std Logger

func Default added in v1.2.0

func Default() *SimpleLogger

Default returns the default SimpleLogger

func New added in v1.2.0

func New(flags int) *SimpleLogger

New returns a newInt SimpleLogger implementation

func (*SimpleLogger) Debug added in v1.2.0

func (l *SimpleLogger) Debug(v ...any)

Debug logs on the LevelDebug

func (*SimpleLogger) Debugf added in v1.2.0

func (l *SimpleLogger) Debugf(format string, v ...any)

Debugf logs on the LevelDebug

func (*SimpleLogger) Error added in v1.2.0

func (l *SimpleLogger) Error(v ...any)

Error logs on the LevelError

func (*SimpleLogger) Errorf added in v1.2.0

func (l *SimpleLogger) Errorf(format string, v ...any)

Errorf logs on the LevelError

func (*SimpleLogger) Fatal added in v1.2.0

func (l *SimpleLogger) Fatal(v ...any)

Fatal logs on the LevelFatal

func (*SimpleLogger) Fatalf added in v1.2.0

func (l *SimpleLogger) Fatalf(format string, v ...any)

Fatalf logs on the LevelFatal

func (*SimpleLogger) Info added in v1.2.0

func (l *SimpleLogger) Info(v ...any)

Info logs on the LevelInfo

func (*SimpleLogger) Infof added in v1.2.0

func (l *SimpleLogger) Infof(format string, v ...any)

Infof logs on the LevelInfo

func (*SimpleLogger) Output added in v1.2.0

func (l *SimpleLogger) Output(calldepth int, level Level, v ...any)

func (*SimpleLogger) Outputf added in v1.2.0

func (l *SimpleLogger) Outputf(calldepth int, level Level, format string, v ...any)

func (*SimpleLogger) Panic added in v1.2.0

func (l *SimpleLogger) Panic(v ...any)

Panic logs on the LevelPanic

func (*SimpleLogger) Panicf added in v1.2.0

func (l *SimpleLogger) Panicf(format string, v ...any)

Panicf logs on the LevelPanic

func (*SimpleLogger) SetFlags added in v1.2.0

func (l *SimpleLogger) SetFlags(flags int)

SetFlags sets the Output flags like: Ldate, Ltime, Lmicroseconds, Llongfile, Lshortfile, LUTC, Lmsgprefix,LstdFlags

func (*SimpleLogger) SetLevel added in v1.2.0

func (l *SimpleLogger) SetLevel(level Level)

SetLevel sets the lowest Level to Output for

func (*SimpleLogger) Trace added in v1.2.0

func (l *SimpleLogger) Trace(v ...any)

Trace logs on the LevelTrace

func (*SimpleLogger) Tracef added in v1.2.0

func (l *SimpleLogger) Tracef(format string, v ...any)

Tracef logs on the LevelTrace

func (*SimpleLogger) Warn added in v1.2.0

func (l *SimpleLogger) Warn(v ...any)

Warn logs on the LevelWarn

func (*SimpleLogger) Warnf added in v1.2.0

func (l *SimpleLogger) Warnf(format string, v ...any)

Warnf logs on the LevelWarn

type Style added in v1.2.0

type Style string

Style represents a text

func AlternateFont added in v1.2.0

func AlternateFont(font int) Style

AlternateFont returns a Style which alternates the font

func SetBackgroundColor added in v1.2.0

func SetBackgroundColor(r, g, b int) Style

SetBackgroundColor returns a Style which sets the background color

func SetForegroundColor added in v1.2.0

func SetForegroundColor(r, g, b int) Style

SetForegroundColor returns a Style which sets the foreground color

func SetUnderlineColor added in v1.2.0

func SetUnderlineColor(r, g, b int) Style

SetUnderlineColor returns a Style which sets the underline color

func (Style) And added in v1.2.0

func (s Style) And(style Style) Style

And adds 2 Style(s) together

func (Style) Apply added in v1.2.0

func (s Style) Apply(text string) string

Apply applies a given Style to the given text

func (Style) ApplyClear added in v1.2.0

func (s Style) ApplyClear(text string) string

ApplyClear applies a given Style to the given text with clearing all Style(s) before

func (Style) String added in v1.2.0

func (s Style) String() string

String returns the Style as string to be used in a Terminal

Jump to

Keyboard shortcuts

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