golog

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 7 Imported by: 9

README

golog

Simple, zero allocation logger with colors (and sentry integration)!

Example:

Colors

golog uses colors by default on all platforms, including windows. However if they don't work or you prefer to have them disabled, set env variable GCOLORS=off

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FatalMessage

type FatalMessage interface {
	Message
	ExitCode(code int) Message
}

type HookHandler

type HookHandler func(msg Message, arg any)

type Level

type Level uint8
const (
	LevelPanic Level = iota + 1
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
)

func (Level) String

func (l Level) String() string

type LogHandler

type LogHandler func(msg Message)

type Logger

type Logger interface {
	Recover()

	Info() Message
	Warn() Message
	Error() Message
	Debug() Message
	// Panic is a special log message type with extra decorations.
	//
	// By default, it doesn't exit process.
	Panic() FatalMessage
	// Fatal is wrapper for Logger.Panic that exits process after sending log message.
	//
	// Default exit code is 1.
	Fatal() FatalMessage
	Empty()

	Module(name string) Logger
	Modules() []string
	SetLevel(level Level) Logger
	Level() Level
	SetWriter(wr io.Writer) Logger
	Writer() io.Writer

	AddOnLog(id string, fn LogHandler) Logger
	OnLog(msg Message)

	ClearHooks() Logger
	ClearAll() Logger
	ClearHandlers() Logger

	CreateHook(name string, fn HookHandler)
	Hook(name string) HookHandler
}

func New

func New(name string) Logger

func NewDefault

func NewDefault() Logger

func NewWithLevel

func NewWithLevel(name string, level Level) Logger

type Message

type Message interface {
	Instance() Logger
	Level() Level
	Arguments() []string
	UserMessage() string
	Time() time.Time
	Error() error
	GetExitCode() int

	Stack() Message
	GetStack() []byte
	FileWithLine() Message
	SendError(err error)

	Use(hook string, arg any) Message
	Any(arg ...any) Message
	Add(format string, args ...any) Message
	Send(format string, args ...any)
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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