logger

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

README

Go Report Card GoDoc GPLv3 license Maintenance Sourcegraph

logger

This Go package implements a simple and extensible logging mechanism.

Documentation

Index

Constants

View Source
const Warning = Warn

Variables

This section is empty.

Functions

func RegisterLogWriter

func RegisterLogWriter(lw LogWriter)

RegisterLogWriter register the log writers where the log line will be propagated.

Types

type LogEntry

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

LogEntry is the log line that will be sent to the default log channel.

func Log

func Log(level LogLevel, message string, fields ...interface{}) LogEntry

Log creates a new log entry with `level` (info, error, debug, warn).

func LogDebug

func LogDebug(message string, fields ...interface{}) LogEntry

LogDebug creates a new log entry with `level` debug

func LogError

func LogError(message string, fields ...interface{}) LogEntry

LogError creates a new log entry with `level` error

func LogInfo

func LogInfo(message string, fields ...interface{}) LogEntry

LogInfo creates a new log entry with `level` info

func LogWarning

func LogWarning(message string, fields ...interface{}) LogEntry

LogWarning creates a new log entry with `level` warning

func (LogEntry) Fields

func (l LogEntry) Fields() map[string]interface{}

Fields returns the extra info for the log entry.

func (LogEntry) Level

func (l LogEntry) Level() string

Level returns the level to be logged to.

func (LogEntry) Message

func (l LogEntry) Message() string

Message returns the message to be logged.

func (LogEntry) SetField

func (l LogEntry) SetField(name string, value interface{}) LogEntry

SetField adds an extra field with name 'name' of value 'value'.

func (LogEntry) Write

func (l LogEntry) Write()

Write sends the logEntry to de logging channel.

func (LogEntry) WriteTo

func (l LogEntry) WriteTo(w io.Writer)

type LogLevel

type LogLevel int8

LogLevel is one of Info, Error, Debug, Warn | Warning

const (
	Info LogLevel = iota
	Error
	Debug
	Warn
)

func (LogLevel) String

func (l LogLevel) String() string

type LogWriter

type LogWriter interface {
	// WriteLogLine receives a JSON string without the ending \n
	WriteLogLine(string)
}

LogWriter interface to implement to make a log writer.

type Logger

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

Logger is a logging facility with fixed fields written in every log line

func NewLogger

func NewLogger(fields ...interface{}) *Logger

NewLogger creates a new Logger with fixed fields

func (*Logger) AddFields

func (l *Logger) AddFields(fields ...interface{})

AddFields appends a new fixed field to Logger

func (*Logger) Log

func (l *Logger) Log(level LogLevel, message string, fields ...interface{}) LogEntry

Log creates a new log entry with `level` (info, error, debug, warn).

func (*Logger) LogError

func (l *Logger) LogError(message string, fields ...interface{}) LogEntry

LogError creates a new log entry with `level` Error

func (*Logger) LogInfo

func (l *Logger) LogInfo(message string, fields ...interface{}) LogEntry

LogInfo creates a new log entry with `level` info

Jump to

Keyboard shortcuts

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