Documentation
¶
Overview ¶
Package log implements the functions, types, and contracts for the module.
Package log contains generated code by adptool.
Package log acts as a bridge to the Kratos logging library. The adptool directives below generate wrapper code, making Kratos's logging functions and types directly available in this package without non-idiomatic prefixes.
Package log implements the functions, types, and contracts for the module.
Package log implements the functions, types, and contracts for the module.
Index ¶
- Constants
- Variables
- func Caller(depth int) kratoslog.Valuer
- func Context(ctx context.Context) *kratoslog.Helper
- func Debug(a ...any)
- func Debugf(format string, a ...any)
- func Debugw(keyvals ...any)
- func Error(a ...any)
- func Errorf(format string, a ...any)
- func Errorw(keyvals ...any)
- func Fatal(a ...any)
- func Fatalf(format string, a ...any)
- func Fatalw(keyvals ...any)
- func FilterFunc(f func(level kratoslog.Level, keyvals ...any) bool) kratoslog.FilterOption
- func FilterKey(key ...string) kratoslog.FilterOption
- func FilterLevel(level kratoslog.Level) kratoslog.FilterOption
- func FilterValue(value ...string) kratoslog.FilterOption
- func GetLogger() kratoslog.Logger
- func GetSlogLogger() *slogx.Logger
- func Info(a ...any)
- func Infof(format string, a ...any)
- func Infow(keyvals ...any)
- func LevelOption(level string) slogx.Option
- func Log(level kratoslog.Level, keyvals ...any)
- func NewDiscard() kratoslog.Logger
- func NewFilter(logger kratoslog.Logger, opts ...kratoslog.FilterOption) *kratoslog.Filter
- func NewHelper(logger kratoslog.Logger, opts ...kratoslog.Option) *kratoslog.Helper
- func NewStdLogger(w io.Writer) kratoslog.Logger
- func NewWriter(logger kratoslog.Logger, opts ...kratoslog.WriterOptionFn) io.Writer
- func ParseLevel(s string) kratoslog.Level
- func Resolve(ctx context.Context, source any, opts *component.LoadOptions) (*component.ModuleConfig, error)
- func SetLogger(logger kratoslog.Logger)
- func SetSlogLogger(logger *slogx.Logger)
- func Timestamp(layout string) kratoslog.Valuer
- func Value(ctx context.Context, v any) any
- func Warn(a ...any)
- func Warnf(format string, a ...any)
- func Warnw(keyvals ...any)
- func With(l kratoslog.Logger, kv ...any) kratoslog.Logger
- func WithContext(ctx context.Context, l kratoslog.Logger) kratoslog.Logger
- func WithDecorate(l kratoslog.Logger, info *appv1.App) kratoslog.Logger
- func WithLogger(logger Logger) options.Option
- func WithMessageKey(k string) kratoslog.Option
- func WithSprint(sprint func(...any) string) kratoslog.Option
- func WithSprintf(sprintf func(format string, a ...any) string) kratoslog.Option
- func WithWriteMessageKey(key string) kratoslog.WriterOptionFn
- func WithWriterLevel(level kratoslog.Level) kratoslog.WriterOptionFn
- type DiscardLogger
- func (d DiscardLogger) Debug(msg string, keyvals ...interface{})
- func (d DiscardLogger) Error(msg string, keyvals ...interface{})
- func (d DiscardLogger) Info(msg string, keyvals ...interface{})
- func (d DiscardLogger) Log(level kratoslog.Level, keyvals ...interface{}) error
- func (d DiscardLogger) Warn(msg string, keyvals ...interface{})
- type Filter
- type FilterOption
- type Helper
- type Level
- type Logger
- type Option
- type Valuer
- type WriterOptionFn
Constants ¶
const ( LevelDebug = kratoslog.LevelDebug LevelError = kratoslog.LevelError LevelFatal = kratoslog.LevelFatal LevelInfo = kratoslog.LevelInfo LevelKey = kratoslog.LevelKey LevelWarn = kratoslog.LevelWarn )
Variables ¶
var ( DefaultCaller = kratoslog.DefaultCaller DefaultLogger = kratoslog.DefaultLogger DefaultMessageKey = kratoslog.DefaultMessageKey DefaultTimestamp = kratoslog.DefaultTimestamp )
var DefaultProvider component.Provider = func(ctx context.Context, h component.Handle) (any, error) { cfg, err := comp.AsConfig[loggerv1.Logger](h) if err != nil { return nil, err } if cfg == nil { log.Context(ctx).Warnf("logger: no config found, using default logger") return DefaultLogger, nil } return NewLogger(cfg), nil }
DefaultProvider is the engine-compatible provider for logger components.
var (
DefaultSlogLogger = slogx.New(slogx.WithFormat(slogx.FormatDev), slogx.WithConsole(true))
)
Functions ¶
func FilterFunc ¶
func FilterKey ¶
func FilterKey(key ...string) kratoslog.FilterOption
func FilterLevel ¶
func FilterLevel(level kratoslog.Level) kratoslog.FilterOption
func FilterValue ¶
func FilterValue(value ...string) kratoslog.FilterOption
func GetSlogLogger ¶ added in v0.2.19
GetSlogLogger returns global logger appliance as logger in current process.
func LevelOption ¶ added in v0.2.0
LevelOption converts a string level to a slogx.Option.
func NewDiscard ¶ added in v0.2.0
func ParseLevel ¶
func Resolve ¶ added in v0.2.19
func Resolve(ctx context.Context, source any, opts *component.LoadOptions) (*component.ModuleConfig, error)
Resolve resolves the logger configuration.
func SetSlogLogger ¶ added in v0.2.19
SetSlogLogger should be called before any other log call. And it is NOT THREAD SAFE.
func WithDecorate ¶ added in v0.2.13
WithDecorate decorates a kratos logger with common service information. It adds fields like service ID, name, version, timestamp, caller, trace ID, and span ID.
func WithLogger ¶ added in v0.2.6
func WithMessageKey ¶
func WithWriteMessageKey ¶
func WithWriteMessageKey(key string) kratoslog.WriterOptionFn
func WithWriterLevel ¶
func WithWriterLevel(level kratoslog.Level) kratoslog.WriterOptionFn
Types ¶
type DiscardLogger ¶ added in v0.2.0
type DiscardLogger struct{}
func (DiscardLogger) Debug ¶ added in v0.2.0
func (d DiscardLogger) Debug(msg string, keyvals ...interface{})
func (DiscardLogger) Error ¶ added in v0.2.0
func (d DiscardLogger) Error(msg string, keyvals ...interface{})
func (DiscardLogger) Info ¶ added in v0.2.0
func (d DiscardLogger) Info(msg string, keyvals ...interface{})
func (DiscardLogger) Log ¶ added in v0.2.0
func (d DiscardLogger) Log(level kratoslog.Level, keyvals ...interface{}) error
func (DiscardLogger) Warn ¶ added in v0.2.0
func (d DiscardLogger) Warn(msg string, keyvals ...interface{})
type FilterOption ¶
type FilterOption = kratoslog.FilterOption
type WriterOptionFn ¶
type WriterOptionFn = kratoslog.WriterOptionFn