logger

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: EUPL-1.2 Imports: 10 Imported by: 0

Documentation

Overview

Package logger implements a logging package for use in the Zettelstore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level uint8

Level defines the possible log levels

const (
	NoLevel        Level = iota // the absent log level
	TraceLevel                  // Log most internal activities
	DebugLevel                  // Log most data updates
	InfoLevel                   // Log normal activities
	ErrorLevel                  // Log (persistent) errors
	MandatoryLevel              // Log only mandatory events
	NeverLevel                  // Logging is disabled
)

Constants for Level

func ParseLevel

func ParseLevel(text string) Level

ParseLevel returns the recognized level.

func (Level) Format

func (l Level) Format() string

Format returns a string representation suitable for logging.

func (Level) IsValid

func (l Level) IsValid() bool

IsValid returns true, if the level is a valid level

func (Level) String

func (l Level) String() string

type LogWriter

type LogWriter interface {
	WriteMessage(level Level, ts time.Time, prefix, msg string, details []byte) error
}

LogWriter writes log messages to their specified destinations.

type Logger

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

Logger represents an objects that emits logging messages.

func New

func New(lw LogWriter, prefix string) *Logger

New creates a new logger for the given service.

This function must only be called from a kernel implementation, not from code that tries to log something.

func (*Logger) Clone

func (l *Logger) Clone() *Message

Clone creates a message to clone the logger.

func (*Logger) Debug

func (l *Logger) Debug() *Message

Debug creates a debug message.

func (*Logger) Error

func (l *Logger) Error() *Message

Error creates a message suitable for errors.

func (*Logger) Info

func (l *Logger) Info() *Message

Info creates a message suitable for information data.

func (*Logger) Level

func (l *Logger) Level() Level

Level returns the current level of the given logger

func (*Logger) Mandatory

func (l *Logger) Mandatory() *Message

Mandatory creates a message that will always logged, except when logging is disabled.

func (*Logger) SetLevel

func (l *Logger) SetLevel(newLevel Level) *Logger

SetLevel sets the level of the logger.

func (*Logger) Trace

func (l *Logger) Trace() *Message

Trace creates a tracing message.

func (*Logger) WithUser

func (l *Logger) WithUser(up UserProvider) *Logger

WithUser creates a derivied logger that allows to retrieve and log user identifer.

type Message

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

Message presents a message to log.

func (*Message) Bool

func (m *Message) Bool(text string, val bool) *Message

Bool adds a boolean value to the full message

func (*Message) Bytes

func (m *Message) Bytes(text string, val []byte) *Message

Bytes adds a byte slice value to the full message

func (*Message) Child

func (m *Message) Child() *Logger

Child creates a child logger with context of this message.

func (*Message) Enabled

func (m *Message) Enabled() bool

Enabled returns whether the message will log or not.

func (*Message) Err

func (m *Message) Err(err error) *Message

Err adds an error value to the full message

func (*Message) HTTPIP added in v0.5.1

func (m *Message) HTTPIP(r *http.Request) *Message

HTTPIP adds the IP address of a HTTP request to the message.

func (*Message) Int

func (m *Message) Int(text string, i int64) *Message

Int adds an integer to the full message

func (*Message) Msg

func (m *Message) Msg(text string)

Msg add the given text to the message and writes it to the log.

func (*Message) Str

func (m *Message) Str(text, val string) *Message

Str adds a string value to the full message

func (*Message) Uint

func (m *Message) Uint(text string, u uint64) *Message

Uint adds an unsigned integer to the full message

func (*Message) User

func (m *Message) User(ctx context.Context) *Message

User adds the user-id field of the given user to the message.

func (*Message) Zid

func (m *Message) Zid(zid id.Zid) *Message

Zid adds a zettel identifier to the full message

type UserProvider

type UserProvider interface {
	GetUser(ctx context.Context) *meta.Meta
}

UserProvider allows to retrieve an user metadata from a context.

Jump to

Keyboard shortcuts

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