Documentation ¶
Index ¶
- Variables
- func AddLevelWriter(level Level, w Writer)
- func AddLevelsWriter(levels []Level, w Writer)
- func AddWriter(w Writer)
- func Debug(args ...any)
- func Debugf(format string, args ...any)
- func EnableLevelsStackTrace(levels []Level)
- func Error(args ...any)
- func Errorf(format string, args ...any)
- func Fatal(args ...any)
- func Fatalf(format string, args ...any)
- func Info(args ...any)
- func Infof(format string, args ...any)
- func InitDefaultLogger(defaultWriter Writer)
- func LogItem(item *Item)
- func Mute(level Level, state bool)
- func ResetLevelWriters(level Level, defaultW Writer)
- func ResetLevelsWriters(levels []Level, defaultW Writer)
- func ResetWriters(defaultW Writer)
- func SetInitItemFunc(f InitItemF)
- func SetPayload(name string, value any)
- func StartDefaultLogger()
- func StartPanicWatcher()
- func StopDefaultLogger()
- func Warning(args ...any)
- func Warningf(format string, args ...any)
- type InitItemF
- type Item
- type Level
- type Logger
- func (l *Logger) Debug(args ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Error(args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Fatal(args ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) Info(args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) LogItem(item *Item)
- func (l *Logger) NewErrorItem(err error) *Item
- func (l *Logger) NewErrorItemf(format string, a ...any) *Item
- func (l *Logger) NewItem(level Level, args ...any) *Item
- func (l *Logger) NewItemf(level Level, format string, args ...any) *Item
- func (l *Logger) SetInitItemFunc(f InitItemF)
- func (l *Logger) SetPayload(key string, value any)
- func (l *Logger) Warning(args ...any)
- func (l *Logger) Warningf(format string, args ...any)
- type Writer
Constants ¶
This section is empty.
Variables ¶
var CriticalLevels = []Level{FatalLevel, ErrorLevel, WarningLevel}
CriticalLevels lists critical levels.
var FatalExitCode = 1
Exit Code generato da Fatal() e Fatalf().
var Levels = [LevelsCount]Level{ FatalLevel, ErrorLevel, WarningLevel, InfoLevel, DebugLevel, }
Levels is a constant of all logging levels.
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.
var LevelsString = [LevelsCount]string{
"fatal", "error", "warning", "info", "debug",
}
LevelsString is a constant of all logging levels names.
Functions ¶
func AddLevelWriter ¶
Associa un writer a uno specifico livello. NON thread safe.
func AddLevelsWriter ¶
Associa un writer a un set di livelli. NON thread safe.
func EnableLevelsStackTrace ¶ added in v1.0.0
func EnableLevelsStackTrace(levels []Level)
Attiva lo stacktrace per specifici livelli. NON thread safe.
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 ResetLevelWriters ¶
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 ¶
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
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.
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
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
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 ¶
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 ¶
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
GenerateStackTrace assign the stack trace of current position to the item.
func (*Item) SetPayload ¶ added in v1.0.0
Setta un valore del payload.
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 ¶
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) Fatal ¶ added in v1.0.0
Logga a livello fatale effetuando anche os.Exit(FatalExitCode)
func (*Logger) Fatalf ¶ added in v1.0.0
Logga a livello fatale effetuando anche os.Exit(FatalExitCode)
func (*Logger) NewErrorItem ¶ added in v1.0.0
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
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
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
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
Imposta una funzione di inizializzazione per ogni item allocato dal logger.
func (*Logger) SetPayload ¶ added in v1.0.0
Setta un valore del payload di default.