logs

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CriticalLevels = []Level{FatalLevel, ErrorLevel, WarningLevel}

CriticalLevels lists critical levels.

View Source
var FatalExitCode = 1

Exit Code generato da Fatal() e Fatalf().

Levels is a constant of all logging levels.

View Source
var LevelsIcons = [LevelsCount]string{
	"\xE2\x9D\x8C", "\xE2\x9D\x97", "\xE2\x9A\xA0", "\xE2\x84\xB9", "\xF0\x9F\x90\x9B",
}

LevelsIcons is a constant of all logging levels UTF8 icons.

View Source
var LevelsString = [LevelsCount]string{
	"fatal", "error", "warning", "info", "debug",
}

LevelsString is a constant of all logging levels names.

Functions

func AddLevelWriter

func AddLevelWriter(level Level, w Writer)

Associa un writer a uno specifico livello. NON thread safe.

func AddLevelsWriter

func AddLevelsWriter(levels []Level, w Writer)

Associa un writer a un set di livelli. NON thread safe.

func AddWriter

func AddWriter(w Writer)

Associa un writer a tutti i livelli. NON thread safe.

func Debug

func Debug(args ...any)

Logga a livello debug.

func Debugf

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

Logga a livello debug.

func EnableLevelsStackTrace added in v1.0.0

func EnableLevelsStackTrace(levels []Level)

Attiva lo stacktrace per specifici livelli. NON thread safe.

func Error

func Error(args ...any)

Logga a livello errore.

func Errorf

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

Logga a livello errore.

func Fatal

func Fatal(args ...any)

Logga a livello fatale effetuando anche os.Exit(FatalExitCode)

func Fatalf

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

Logga a livello fatale effetuando anche os.Exit(FatalExitCode)

func Info

func Info(args ...any)

Logga a livello info.

func Infof

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

Logga a livello info.

func InitDefaultLogger added in v1.0.0

func InitDefaultLogger(defaultWriter Writer)

Invocata da sparalog.init() Inizializza la libreria allocando il logger di default e associando un writer di default (di tipo Stdout).

func LogItem added in v1.0.0

func LogItem(item *Item)

Logga un item precedentemente generato.

func Mute

func Mute(level Level, state bool)

Mute mute/unmute a specific level.

func ResetLevelWriters

func ResetLevelWriters(level Level, defaultW Writer)

Disassocia tutti i writer per un certo livello e ne reimposta un writer di default (il writer di default riceve le eventuali loggate di errore o di feedback da parte degli altri writer). NON thread safe.

func ResetLevelsWriters

func ResetLevelsWriters(levels []Level, defaultW Writer)

Disassocia tutti i writer per un set di livelli e ne reimposta un writer di default (il writer di default riceve le eventuali loggate di errore o di feedback da parte degli altri writer). NON thread safe.

func ResetWriters

func ResetWriters(defaultW Writer)

Disassocia tutti i writer e reimposta un writer di default (il writer di default riceve le eventuali loggate di errore o di feedback da parte degli altri writer). NON thread safe.

func SetInitItemFunc added in v1.0.0

func SetInitItemFunc(f InitItemF)

Imposta una funzione di inizializzazione per ogni item allocato dal logger di default.

func SetPayload added in v1.0.0

func SetPayload(name string, value any)

Setta un valore del payload di default del logger di default.

func StartDefaultLogger added in v1.0.0

func StartDefaultLogger()

Invocata da sparalog.Start() Avvia il logger di default.

func StartPanicWatcher

func StartPanicWatcher()

StartPanicWatcher starts a supervisor that monitors panics in all goroutines. Since the supervision is made starting a parent + child processes: - Call the function after all writers initialization, or at least after fatal level initialization; - This function should not to be called in debugging sessions.

func StopDefaultLogger added in v1.0.0

func StopDefaultLogger()

Invocata da sparalog.Stop() Gestisce i panic (della routine corrente), termina il dispatcher attendendo gentilmente il termine dei writer asincroni. Va chiamata al termine del main.

func Warning added in v1.0.0

func Warning(args ...any)

Logga a livello warning.

func Warningf added in v1.0.0

func Warningf(format string, args ...any)

Logga a livello warning.

Types

type InitItemF added in v1.0.0

type InitItemF func(*Item)

Funzione di inizializzazione item appena dopo la sua allocazione, permette di settare ulteriormente in modo custom specifiche proprietà.

type Item added in v1.0.0

type Item struct {
	Ts        time.Time
	Timestamp string // renderizzata

	Level Level

	Prefix, Message string

	StackTrace string

	Payload map[string]any
}

func NewErrorItem added in v1.0.0

func NewErrorItem(err error) *Item

Genera un nuovo item dal logger di default, di livello errore. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func NewErrorItemf added in v1.0.0

func NewErrorItemf(format string, a ...any) *Item

Genera un nuovo item dal logger di default, di livello errore. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func NewItem

func NewItem(level Level, args ...any) *Item

Genera un nuovo item dal logger di default, di livello specifico. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func NewItemf

func NewItemf(level Level, format string, args ...any) *Item

Genera un nuovo item dal logger di default, di livello specifico. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func (*Item) GenerateStackTrace added in v1.0.0

func (i *Item) GenerateStackTrace(callsToSkip int)

GenerateStackTrace assign the stack trace of current position to the item.

func (*Item) SetPayload added in v1.0.0

func (i *Item) SetPayload(key string, value any)

Setta un valore del payload.

func (Item) ToString added in v1.0.0

func (i Item) ToString(timestamp, stacktrace bool) string

Formatta l'item sottoforma di stringa.

type Level added in v1.0.0

type Level int

Level type.

const (
	// FatalLevel - Shutdown of the service or application to prevent data loss (or further data loss).
	// Wake up the SysAdmin!
	// Stack trace enabled by default.
	FatalLevel Level = iota
	// ErrorLevel - Any error which is fatal to the operation, but not the service or application
	// (can't open a required file, missing data, incorrect connection strings, missing services, etc.).
	// SysAdmin should be notified automatically, but doesn't need to be dragged out of bed.
	// Stack trace enabled by default.
	ErrorLevel
	// WarningLevel - Anything that can potentially cause application oddities, but automatically recovered.
	WarningLevel
	// InfoLevel - General operational entries about what's going on inside the service or application.
	// Should be the out-of-the-box level.
	InfoLevel
	// DebugLevel - Tracciatura del flusso interno, di solito abilitato solo in modalità debug.
	// Mutato di default.
	DebugLevel

	LevelsCount
)

Logging levels.

type Logger added in v1.0.0

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

func NewLogger

func NewLogger(prefix string) *Logger

Alloca un nuovo logger dotato di prefisso e di differente payload, utilizzabile come componente in una struct o in un package. Eredita una copia del payload dal logger di default. - prefix: prefisso di default che comparirà nelle relative loggate.

func (*Logger) Debug added in v1.0.0

func (l *Logger) Debug(args ...any)

Logga a livello debug.

func (*Logger) Debugf added in v1.0.0

func (l *Logger) Debugf(format string, args ...any)

Logga a livello debug.

func (*Logger) Error added in v1.0.0

func (l *Logger) Error(args ...any)

Logga a livello errore.

func (*Logger) Errorf added in v1.0.0

func (l *Logger) Errorf(format string, args ...any)

Logga a livello errore.

func (*Logger) Fatal added in v1.0.0

func (l *Logger) Fatal(args ...any)

Logga a livello fatale effetuando anche os.Exit(FatalExitCode)

func (*Logger) Fatalf added in v1.0.0

func (l *Logger) Fatalf(format string, args ...any)

Logga a livello fatale effetuando anche os.Exit(FatalExitCode)

func (*Logger) Info added in v1.0.0

func (l *Logger) Info(args ...any)

Logga a livello info.

func (*Logger) Infof added in v1.0.0

func (l *Logger) Infof(format string, args ...any)

Logga a livello info.

func (*Logger) LogItem added in v1.0.0

func (l *Logger) LogItem(item *Item)

Logga un item precedentemente generato.

func (*Logger) NewErrorItem added in v1.0.0

func (l *Logger) NewErrorItem(err error) *Item

Genera un nuovo item di livello errore. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func (*Logger) NewErrorItemf added in v1.0.0

func (l *Logger) NewErrorItemf(format string, a ...any) *Item

Genera un nuovo item di livello errore. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func (*Logger) NewItem added in v1.0.0

func (l *Logger) NewItem(level Level, args ...any) *Item

Genera un nuovo item di livello specifico. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func (*Logger) NewItemf added in v1.0.0

func (l *Logger) NewItemf(level Level, format string, args ...any) *Item

Genera un nuovo item di livello specifico. Eredita una copia del payload dal logger che può essere ulteriormente customizzata.

func (*Logger) SetInitItemFunc added in v1.0.0

func (l *Logger) SetInitItemFunc(f InitItemF)

Imposta una funzione di inizializzazione per ogni item allocato dal logger.

func (*Logger) SetPayload added in v1.0.0

func (l *Logger) SetPayload(key string, value any)

Setta un valore del payload di default.

func (*Logger) Warning added in v1.0.0

func (l *Logger) Warning(args ...any)

Logga a livello warning.

func (*Logger) Warningf added in v1.0.0

func (l *Logger) Warningf(format string, args ...any)

Logga a livello warning.

type Writer added in v1.0.0

type Writer interface {
	ID() string

	Write(*Item)

	Start() error
	Stop()
	SetFeedbackChan(chan *Item)
}

Interfaccia del writer usata dal logger.

Jump to

Keyboard shortcuts

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