Documentation
¶
Overview ¶
Package core provides the fundamental logging abstractions and implementations.
Package core contém funcionalidades centrais do logz.
Index ¶
- Constants
- func DefaultEntryDecoder(defaultLevel kbx.Level) func([]byte) (kbx.LogzEntry, error)
- func LoadFromEnvTyped(key string, defaultValue any) any
- func NewKbxEntry(level kbx.Level) (kbx.LogzEntry, error)
- func NewLogzEntry(level kbx.Level) kbx.LogzEntry
- func RegisterOptionSetter(key string, setter ConfigSetter)
- type ConfigSetter
- type Entry
- func (e *Entry) CaptureCaller(skip int) kbx.Entry
- func (e *Entry) Clone() kbx.Entry
- func (e *Entry) Field(k string, v any) kbx.Entry
- func (e *Entry) GetCaller() string
- func (e *Entry) GetContext() string
- func (e *Entry) GetFields() map[string]any
- func (e *Entry) GetFormat() string
- func (e *Entry) GetLevel() kbx.Level
- func (e *Entry) GetMessage() string
- func (e *Entry) GetPrefix() string
- func (e *Entry) GetShowCaller() bool
- func (e *Entry) GetShowColor() bool
- func (e *Entry) GetShowFields() bool
- func (e *Entry) GetShowIcon() bool
- func (e *Entry) GetShowStack() bool
- func (e *Entry) GetShowTraceID() bool
- func (e *Entry) GetTags() map[string]string
- func (e *Entry) GetTimestamp() time.Time
- func (e *Entry) GetTraceID() string
- func (e *Entry) String() string
- func (e *Entry) Tag(k, v string) kbx.LogzEntry
- func (e *Entry) Validate() error
- func (e *Entry) WithCaller(c string) kbx.LogzEntry
- func (e *Entry) WithColor(color bool) kbx.LogzEntry
- func (e *Entry) WithContext(ctx string) kbx.LogzEntry
- func (e *Entry) WithData(data any) kbx.LogzEntry
- func (e *Entry) WithError(err error) kbx.LogzEntry
- func (e *Entry) WithField(key string, value any) kbx.LogzEntry
- func (e *Entry) WithFields(fields map[string]any) kbx.LogzEntry
- func (e *Entry) WithFormat(format string) kbx.LogzEntry
- func (e *Entry) WithIcon(icon bool) kbx.LogzEntry
- func (e *Entry) WithLevel(l kbx.Level) kbx.LogzEntry
- func (e *Entry) WithMessage(msg string) kbx.LogzEntry
- func (e *Entry) WithShowCaller(show bool) kbx.LogzEntry
- func (e *Entry) WithShowFields(show bool) kbx.LogzEntry
- func (e *Entry) WithShowTraceID(show bool) kbx.LogzEntry
- func (e *Entry) WithSource(src string) kbx.LogzEntry
- func (e *Entry) WithStack(show bool) kbx.LogzEntry
- func (e *Entry) WithTraceID(id string) kbx.LogzEntry
- type IOBridge
- type Logger
- func (l *Logger) AddHook(h interfaces.Hook)
- func (l *Logger) Enabled(level kbx.Level) bool
- func (l *Logger) GetConfig() *LoggerOptionsImpl
- func (l *Logger) GetLevel() kbx.Level
- func (l *Logger) GetMinLevel() kbx.Level
- func (l *Logger) Log(lvl kbx.Level, rec ...any) error
- func (l *Logger) LogAny(level kbx.Level, args ...any) error
- func (l *Logger) SetBufferSize(size int)
- func (l *Logger) SetCompress(compress bool)
- func (l *Logger) SetConfig(opts *kbx.LogzConfig)
- func (l *Logger) SetFlushInterval(interval time.Duration)
- func (l *Logger) SetFormatter(f formatter.Formatter)
- func (l *Logger) SetHooks(hooks []interfaces.Hook)
- func (l *Logger) SetLHooks(hooks interfaces.LHook[any])
- func (l *Logger) SetMetadata(metadata map[string]any)
- func (l *Logger) SetMinLevel(min kbx.Level)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetRotate(rotate bool)
- func (l *Logger) SetRotateMaxAge(age int64)
- func (l *Logger) SetRotateMaxBack(back int64)
- func (l *Logger) SetRotateMaxSize(size int64)
- type LoggerConfig
- type LoggerOptionsImpl
- func (o *LoggerOptionsImpl) ApplyOptions(logger *Logger)
- func (o *LoggerOptionsImpl) Clone() *LoggerOptionsImpl
- func (o *LoggerOptionsImpl) Get(key string) any
- func (o *LoggerOptionsImpl) Hydrate(prefix string) *LoggerOptionsImpl
- func (o *LoggerOptionsImpl) Inherit(parent *LoggerOptionsImpl) *LoggerOptionsImpl
- func (o *LoggerOptionsImpl) Merge(override *LoggerOptionsImpl) *LoggerOptionsImpl
- func (o *LoggerOptionsImpl) Set(key string, value any)
- func (o *LoggerOptionsImpl) WithDefaults(def *LoggerOptionsImpl) *LoggerOptionsImpl
- type LoggerZ
- func (l *LoggerZ[T]) Alert(msg ...any)
- func (l *LoggerZ[T]) Alertf(format string, args ...any)
- func (l *LoggerZ[T]) Answer(msg ...any)
- func (l *LoggerZ[T]) Answerf(format string, args ...any)
- func (l *LoggerZ[T]) Bug(msg ...any)
- func (l *LoggerZ[T]) Bugf(format string, args ...any)
- func (l *LoggerZ[T]) Clone() *LoggerZ[T]
- func (l *LoggerZ[T]) Critical(msg ...any)
- func (l *LoggerZ[T]) Criticalf(format string, args ...any)
- func (l *LoggerZ[T]) Debug(msg ...any)
- func (l *LoggerZ[T]) Debugf(format string, args ...any)
- func (l *LoggerZ[T]) Error(msg ...any) error
- func (l *LoggerZ[T]) Errorf(format string, args ...any) error
- func (l *LoggerZ[T]) Fatal(msg ...any)
- func (l *LoggerZ[T]) Fatalf(format string, args ...any)
- func (l *LoggerZ[T]) Info(msg ...any)
- func (l *LoggerZ[T]) Infof(format string, args ...any)
- func (l *LoggerZ[T]) Notice(msg ...any)
- func (l *LoggerZ[T]) Noticef(format string, args ...any)
- func (l *LoggerZ[T]) Panic(msg ...any)
- func (l *LoggerZ[T]) Panicf(format string, args ...any)
- func (l *LoggerZ[T]) Printf(format string, args ...any)
- func (l *LoggerZ[T]) Println(msg ...any)
- func (l *LoggerZ[T]) SetDebugMode(debug bool)
- func (l *LoggerZ[T]) Success(msg ...any)
- func (l *LoggerZ[T]) Successf(format string, args ...any)
- func (l *LoggerZ[T]) Trace(msg ...any)
- func (l *LoggerZ[T]) Tracef(format string, args ...any)
- func (l *LoggerZ[T]) Warn(msg ...any)
- func (l *LoggerZ[T]) Warnf(format string, args ...any)
- type LogzAdvancedOptions
Constants ¶
const ( LevelNotice kbx.Level = "notice" LevelDebug kbx.Level = "debug" LevelTrace kbx.Level = "trace" LevelSuccess kbx.Level = "success" LevelInfo kbx.Level = "info" LevelWarn kbx.Level = "warn" LevelError kbx.Level = "error" LevelFatal kbx.Level = "fatal" LevelSilent kbx.Level = "silent" LevelAlert kbx.Level = "alert" LevelCritical kbx.Level = "critical" LevelAnswer kbx.Level = "answer" LevelBug kbx.Level = "bug" LevelPanic kbx.Level = "panic" LevelNoticef kbx.Level = "notice" LevelDebugf kbx.Level = "debug" LevelTracef kbx.Level = "trace" LevelSuccessf kbx.Level = "success" LevelInfof kbx.Level = "info" LevelWarnf kbx.Level = "warn" LevelErrorf kbx.Level = "error" LevelFatalf kbx.Level = "fatal" LevelSilentf kbx.Level = "silent" LevelAlertf kbx.Level = "alert" LevelCriticalf kbx.Level = "critical" LevelAnswerf kbx.Level = "answer" LevelBugf kbx.Level = "bug" LevelPanicf kbx.Level = "panic" LevelSprintf kbx.Level = "sprintf" LevelPrintln kbx.Level = "println" LevelLog kbx.Level = "log" LevelPrint kbx.Level = "print" LevelPrintf kbx.Level = "printf" LevelLogf kbx.Level = "logf" LevelDefault kbx.Level = "info" )
Variables ¶
This section is empty.
Functions ¶
func DefaultEntryDecoder ¶ added in v1.5.6
DefaultEntryDecoder cria uma função Decode pra IOBridge[*Entry], que transforma uma linha de texto em uma Entry simples.
É uma estratégia padrão: level fixo + mensagem = linha inteira.
func LoadFromEnvTyped ¶ added in v1.5.6
func RegisterOptionSetter ¶ added in v1.5.6
func RegisterOptionSetter(key string, setter ConfigSetter)
Types ¶
type ConfigSetter ¶ added in v1.5.6
ConfigSetter aplica uma opção no logger.
type Entry ¶ added in v1.5.6
type Entry struct {
Timestamp time.Time `json:"ts" yaml:"ts" xml:"ts" mapstructure:"ts"`
Level kbx.Level `json:"level" yaml:"level" xml:"level" mapstructure:"level"`
Message string `json:"msg" yaml:"msg" xml:"msg" mapstructure:"msg"`
ShowColor bool `json:"show_color,omitempty" yaml:"show_color,omitempty" xml:"show_color,omitempty" mapstructure:"show_color,omitempty"` // Habilita cores na saída
ShowIcon bool `json:"show_icon,omitempty" yaml:"show_icon,omitempty" xml:"show_icon,omitempty" mapstructure:"show_icon,omitempty"` // Habilita ícones na saída
ShowTraceID bool `` // Habilita o ID de rastreamento na saída
/* 130-byte string literal not displayed */
ShowCaller bool `json:"show_caller,omitempty" yaml:"show_caller,omitempty" xml:"show_caller,omitempty" mapstructure:"show_caller,omitempty"` // Habilita informações do chamador na saída
ShowStack bool `json:"show_stack,omitempty" yaml:"show_stack,omitempty" xml:"show_stack,omitempty" mapstructure:"show_stack,omitempty"` // Habilita informações da pilha de chamadas na saída
ShowFields bool `json:"show_fields,omitempty" yaml:"show_fields,omitempty" xml:"show_fields,omitempty" mapstructure:"show_fields,omitempty"` // Habilita campos adicionais na saída
Format string `json:"format,omitempty" yaml:"format,omitempty" xml:"format,omitempty" mapstructure:"format,omitempty"` // json / text / xml / etc.
Context string `json:"ctx,omitempty" yaml:"ctx,omitempty" xml:"ctx,omitempty" mapstructure:"ctx,omitempty"` // ex: "auth", "db", "billing"
Source string `json:"src,omitempty" yaml:"src,omitempty" xml:"src,omitempty" mapstructure:"src,omitempty"` // componente/módulo/serviço
TraceID string `json:"trace,omitempty" yaml:"trace,omitempty" xml:"trace,omitempty" mapstructure:"trace,omitempty"` // correlação
Caller string `json:"caller,omitempty" yaml:"caller,omitempty" xml:"caller,omitempty" mapstructure:"caller,omitempty"` // arquivo:linha função
Severity int `json:"sev,omitempty" yaml:"sev,omitempty" xml:"sev,omitempty" mapstructure:"sev,omitempty"` // cache do Level.Severity()
Tags map[string]string `json:"tags,omitempty" yaml:"tags,omitempty" xml:"-" mapstructure:"tags,omitempty"` // metadados arbitrários
Fields map[string]any `json:"fields,omitempty" yaml:"fields,omitempty" xml:"-" mapstructure:"fields,omitempty"` // dados estruturados arbitrários
Error error `json:"error,omitempty"` // erro associado (se houver)
}
Entry é a unidade básica de log do sistema. Tudo no Kubex que for "log estruturado" deveria conseguir ser expresso nisso.
func NewEntryImpl ¶ added in v1.5.6
NewEntryImpl cria uma entry com: - timestamp UTC - maps inicializados - caller capturado
func (*Entry) GetContext ¶ added in v1.5.6
func (*Entry) GetMessage ¶ added in v1.5.6
func (*Entry) GetShowCaller ¶ added in v1.6.3
func (*Entry) GetShowColor ¶ added in v1.6.3
func (*Entry) GetShowFields ¶ added in v1.6.3
func (*Entry) GetShowIcon ¶ added in v1.6.3
func (*Entry) GetShowStack ¶ added in v1.6.3
func (*Entry) GetShowTraceID ¶ added in v1.6.3
func (*Entry) GetTimestamp ¶ added in v1.5.6
func (*Entry) GetTraceID ¶ added in v1.6.3
func (*Entry) WithFields ¶ added in v1.5.6
func (*Entry) WithShowCaller ¶ added in v1.6.3
func (*Entry) WithShowFields ¶ added in v1.6.3
func (*Entry) WithShowTraceID ¶ added in v1.6.3
type IOBridge ¶ added in v1.5.6
IOBridge é o adaptador que IMPLEMENTA io.Writer e empurra tudo para um Logger[T].
É aqui que o "modo B" (byte-first) entra no modo C híbrido: qualquer coisa que escreva em io.Writer pode ser redirecionada para o logger.
Exemplo de uso (lá fora, na superfície pública):
entryLogger := core.NewLogger[*core.Entry](formatter, os.Stdout, core.LevelInfo) bridge := core.NewIOBridge(entryLogger, core.DefaultEntryDecoder(core.LevelInfo)) log.SetOutput(bridge) // log stdlib cmd.Stdout = bridge // exec.Command json.NewEncoder(bridge)...
func NewIOBridge ¶ added in v1.5.6
NewIOBridge cria a ponte genérica entre io.Writer e Logger[T].
type Logger ¶ added in v1.5.6
Logger é o núcleo do pipeline:
Record (T) -> hooks -> formatter -> io.Writer
Não sabe nada de linha, arquivo, CLI, JSON, etc. Isso é responsabilidade do Formatter + destino (io.Writer).
func NewLoggerZI ¶ added in v1.5.6
func NewLoggerZI(prefix string, opts *LoggerOptionsImpl, withDefaults bool) *Logger
NewLoggerZI cria um logger genérico: - formatter: serializa Record em []byte - out: destino final (io.Writer global, arquivo, socket, etc) - min: nível mínimo
func (*Logger) AddHook ¶ added in v1.5.6
func (l *Logger) AddHook(h interfaces.Hook)
func (*Logger) GetConfig ¶ added in v1.5.6
func (l *Logger) GetConfig() *LoggerOptionsImpl
func (*Logger) GetMinLevel ¶ added in v1.5.6
func (*Logger) Log ¶ added in v1.5.6
Log é o caminho principal: recebe um Record pronto (T), dispara hooks, formata e escreve em out.
func (*Logger) SetBufferSize ¶ added in v1.5.6
SetBufferSize is the setter for setBufferSize
func (*Logger) SetCompress ¶ added in v1.5.6
SetCompress is the setter for setCompress
func (*Logger) SetConfig ¶ added in v1.6.3
func (l *Logger) SetConfig(opts *kbx.LogzConfig)
func (*Logger) SetFlushInterval ¶ added in v1.5.6
SetFlushInterval is the setter for setFlushInterval
func (*Logger) SetFormatter ¶ added in v1.5.6
func (*Logger) SetHooks ¶ added in v1.5.6
func (l *Logger) SetHooks(hooks []interfaces.Hook)
SetHooks is the setter for setHooks
func (*Logger) SetLHooks ¶ added in v1.5.6
func (l *Logger) SetLHooks(hooks interfaces.LHook[any])
SetLHooks is the setter for setLHooks
func (*Logger) SetMetadata ¶ added in v1.5.6
SetMetadata is the setter for setMetadata
func (*Logger) SetMinLevel ¶ added in v1.5.6
func (*Logger) SetRotateMaxAge ¶ added in v1.5.6
SetRotateMaxAge is the setter for setRotateMaxAge
func (*Logger) SetRotateMaxBack ¶ added in v1.5.6
SetRotateMaxBack is the setter for setRotateMaxBack
func (*Logger) SetRotateMaxSize ¶ added in v1.5.6
SetRotateMaxSize is the setter for setRotateMaxSize
type LoggerConfig ¶ added in v1.5.6
type LoggerOptionsImpl ¶ added in v1.5.6
type LoggerOptionsImpl struct {
*LoggerConfig `json:",inline" yaml:",inline" mapstructure:",squash"`
*LogzAdvancedOptions `json:",inline" yaml:",inline" mapstructure:",squash"`
}
func NewLoggerOptions ¶ added in v1.5.6
func NewLoggerOptions(initArgs *kbx.InitArgs) *LoggerOptionsImpl
func (*LoggerOptionsImpl) ApplyOptions ¶ added in v1.5.6
func (o *LoggerOptionsImpl) ApplyOptions(logger *Logger)
func (*LoggerOptionsImpl) Clone ¶ added in v1.5.6
func (o *LoggerOptionsImpl) Clone() *LoggerOptionsImpl
func (*LoggerOptionsImpl) Get ¶ added in v1.5.6
func (o *LoggerOptionsImpl) Get(key string) any
func (*LoggerOptionsImpl) Hydrate ¶ added in v1.5.6
func (o *LoggerOptionsImpl) Hydrate(prefix string) *LoggerOptionsImpl
func (*LoggerOptionsImpl) Inherit ¶ added in v1.5.6
func (o *LoggerOptionsImpl) Inherit(parent *LoggerOptionsImpl) *LoggerOptionsImpl
func (*LoggerOptionsImpl) Merge ¶ added in v1.5.6
func (o *LoggerOptionsImpl) Merge(override *LoggerOptionsImpl) *LoggerOptionsImpl
func (*LoggerOptionsImpl) Set ¶ added in v1.5.6
func (o *LoggerOptionsImpl) Set(key string, value any)
func (*LoggerOptionsImpl) WithDefaults ¶ added in v1.5.6
func (o *LoggerOptionsImpl) WithDefaults(def *LoggerOptionsImpl) *LoggerOptionsImpl
type LoggerZ ¶ added in v1.5.6
LoggerZ é o núcleo do pipeline:
Record (T) -> hooks -> formatter -> io.Writer
Não sabe nada de linha, arquivo, CLI, JSON, etc. Isso é responsabilidade do Formatter + destino (io.Writer).
func NewLoggerZ ¶ added in v1.5.6
NewLoggerZ cria um logger genérico: - formatter: serializa T em []byte - out: destino final (io.Writer global, arquivo, socket, etc) - min: nível mínimo
func (*LoggerZ[T]) Fatal ¶ added in v1.6.0
Fatal loga uma mensagem fatal e encerra o programa com exit code 1
func (*LoggerZ[T]) SetDebugMode ¶ added in v1.6.0
SetDebugMode habilita ou desabilita o modo debug do logger global. Quando debug=true, mostra logs de todos os níveis (incluindo debug e trace). Quando debug=false, mostra apenas logs de nível info ou superior.
type LogzAdvancedOptions ¶ added in v1.5.6
type LogzAdvancedOptions struct {
// Hooks
Formatter formatter.Formatter `json:"formatter,omitempty" yaml:"formatter,omitempty" mapstructure:"formatter,omitempty"`
Hooks []interfaces.Hook `json:"hooks,omitempty" yaml:"hooks,omitempty" mapstructure:"hooks,omitempty"`
LHooks interfaces.LHook[any] `json:"l_hooks,omitempty" yaml:"l_hooks,omitempty" mapstructure:"l_hooks,omitempty"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" mapstructure:"metadata,omitempty"`
}