logger

package module
v0.0.0-...-97d1025 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 11 Imported by: 3

README

go-logger

Logging wrappers to make it easier to not depend on thirdparty loggers when I don't need them, but still being able to plug them in without much trouble.

This package only depends on the standard library; it doesn't have any external dependencies.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffered

type Buffered interface {
	Logger

	// Flush writes any pending messages.
	Flush() error
}

Buffered is a logger that might not persist the logged messages immediately, e.g. because doing so may be too inefficient.

The `Flush` method must be called from time to time, to ensure all pending writes are persisted.

type Fields

type Fields map[string]interface{}

type Logger

type Logger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	WithFields(fields Fields) Logger
}
var Discard Logger = &discardLogger{}

func Default

func Default() Logger

func FromSlog

func FromSlog(slogger *slog.Logger) Logger

func FromStandard

func FromStandard(stdLogger *log.Logger) Logger

func NewJSON

func NewJSON(w io.Writer) Logger

type Message

type Message struct {
	Type      MessageType `json:"type"`
	Timestamp time.Time   `json:"timestamp"`

	File     string `json:"file"`
	Line     int    `json:"line"`
	Function string `json:"function"`

	Summary string `json:"summary"`
	Data    Fields `json:"data"`
}

type MessageLogger

type MessageLogger interface {
	LogMessage(msg *Message) error
}

type MessageType

type MessageType string
const (
	MessageTypeDebug   MessageType = "debug"
	MessageTypeWarning MessageType = "warning"
	MessageTypeError   MessageType = "error"
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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