Documentation
¶
Index ¶
- Constants
- func AnyFieldToZeroLogContext(c zerolog.Context, key string, value any) zerolog.Context
- func AnyFieldToZeroLogEvent(c *zerolog.Event, key string, value any) *zerolog.Event
- func AnyFieldsToContext(c zerolog.Context, m map[string]any) zerolog.Context
- func AnyFieldsToEvent(c *zerolog.Event, m map[string]any) *zerolog.Event
- func FormatDuration(d time.Duration) string
- func Msgf(ctx context.Context, msg string, args ...any) string
- func NewZeroLog(opts ...LogOptionFn) zerolog.Logger
- func PgxQueryName(ctx context.Context, name string) context.Context
- func SetupFxLogger(logger *DebugLogger) fxevent.Logger
- type CtxKey
- type DebugLogger
- type Entry
- type FxZeroLogger
- type IOLogger
- type LogArrayMarshaler
- type LogObjectMarshaler
- type LogOptionFn
- func SetField(key string, val any) LogOptionFn
- func SetLogConsoleDisabled(v bool) LogOptionFn
- func SetLogConsoleLevel(lvl int) LogOptionFn
- func SetLogConsoleOutput(out io.Writer) LogOptionFn
- func SetLogFileDisabled(v bool) LogOptionFn
- func SetLogFileLevel(lvl int) LogOptionFn
- func SetLogFileOutput(out io.Writer) LogOptionFn
- func SetLogHook(v ...zerolog.Hook) LogOptionFn
- type LogOptions
- type Logger
- type MultiLogger
- type Option
- func WithLevel(lvl zerolog.Level) Option
- func WithLogEnabled(v bool) Option
- func WithLogWriterDisabled(v bool) Option
- func WithLoggerProvider(provider log.LoggerProvider) Option
- func WithSchemaURL(schemaURL string) Option
- func WithServerAddress(serverAddres string) Option
- func WithServerName(serverName string) Option
- func WithVersion(version string) Option
- type OtelHook
- type PgxLogger
- type SingleLogger
- type TrxLogger
- type ZeroLogger
- func (zl *ZeroLogger) Debug(ctx context.Context, msg string, fields ...any)
- func (zl *ZeroLogger) Error(ctx context.Context, msg string, fields ...any)
- func (zl *ZeroLogger) Fatal(ctx context.Context, msg string, fields ...any)
- func (zl *ZeroLogger) Info(ctx context.Context, msg string, fields ...any)
- func (zl *ZeroLogger) Panic(ctx context.Context, msg string, fields ...any)
- func (zl *ZeroLogger) Trace(ctx context.Context, msg string, fields ...any)
- func (zl *ZeroLogger) Warn(ctx context.Context, msg string, fields ...any)
Constants ¶
const ( XLOG_TRACE_ID_KEY string = "XLOG_TRACE_ID_KEY" XLOG_KEY string = "XLOG_KEY" )
Variables ¶
This section is empty.
Functions ¶
func AnyFieldToZeroLogContext ¶ added in v0.5.0
func AnyFieldToZeroLogEvent ¶ added in v0.5.0
func AnyFieldsToContext ¶ added in v0.5.0
func AnyFieldsToEvent ¶ added in v0.5.0
func FormatDuration ¶ added in v0.5.0
FormatDuration dynamically formats time.Duration into ns, µs, ms, s, m, h, or d
func NewZeroLog ¶
func NewZeroLog(opts ...LogOptionFn) zerolog.Logger
func PgxQueryName ¶ added in v0.5.0
func SetupFxLogger ¶
func SetupFxLogger(logger *DebugLogger) fxevent.Logger
Types ¶
type CtxKey ¶ added in v0.4.0
type CtxKey string
const (
XLOG_REQ_TRACE_ID_CTX_KEY CtxKey = "XLOG_REQ_TRACE_ID_CTX_KEY"
)
type DebugLogger ¶
type DebugLogger struct {
SingleLogger
}
type Entry ¶
type Entry struct { Options LogOptions // contains filtered or unexported fields }
Multi Logger ¶
func NewEntry ¶
func NewEntry(key string, rotation *lumberjack.Logger, opts ...LogOptionFn) Entry
Note:
- SetLogFileOutput(io.Writer) this option is not used in this option.
type FxZeroLogger ¶
type FxZeroLogger struct {
DebugLog *DebugLogger
}
ZeroLogger is an Fx event logger that logs events to Zero.
func (*FxZeroLogger) LogEvent ¶
func (l *FxZeroLogger) LogEvent(event fxevent.Event)
LogEvent logs the given event to the provided Zap logger.
type IOLogger ¶
type IOLogger struct {
SingleLogger
}
type LogArrayMarshaler ¶ added in v0.5.0
type LogObjectMarshaler ¶ added in v0.5.0
type LogOptionFn ¶
type LogOptionFn func(opt *LogOptions)
func SetField ¶
func SetField(key string, val any) LogOptionFn
func SetLogConsoleDisabled ¶
func SetLogConsoleDisabled(v bool) LogOptionFn
func SetLogConsoleLevel ¶
func SetLogConsoleLevel(lvl int) LogOptionFn
func SetLogConsoleOutput ¶
func SetLogConsoleOutput(out io.Writer) LogOptionFn
func SetLogFileDisabled ¶
func SetLogFileDisabled(v bool) LogOptionFn
func SetLogFileLevel ¶
func SetLogFileLevel(lvl int) LogOptionFn
func SetLogFileOutput ¶
func SetLogFileOutput(out io.Writer) LogOptionFn
func SetLogHook ¶ added in v0.5.0
func SetLogHook(v ...zerolog.Hook) LogOptionFn
type LogOptions ¶
type Logger ¶
type Logger interface { /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Trace(ctx, "hello", "first", first, "second", second) <Imported_Log>.Trace(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Trace(ctx, "oh snap! got error", "error", err) */ Trace(ctx context.Context, msg string, fields ...any) /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Debug(ctx, "hello", "first", first, "second", second) <Imported_Log>.Debug(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Debug(ctx, "oh snap! got error", "error", err) */ Debug(ctx context.Context, msg string, fields ...any) /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Info(ctx, "hello", "first", first, "second", second) <Imported_Log>.Info(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Info(ctx, "oh snap! got error", "error", err) */ Info(ctx context.Context, msg string, fields ...any) /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Warn(ctx, "hello", "first", first, "second", second) <Imported_Log>.Warn(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Warn(ctx, "oh snap! got error", "error", err) */ Warn(ctx context.Context, msg string, fields ...any) /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Error(ctx, "hello", "first", first, "second", second) <Imported_Log>.Error(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Error(ctx, "oh snap! got error", "error", err) */ Error(ctx context.Context, msg string, fields ...any) /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Fatal(ctx, "hello", "first", first, "second", second) <Imported_Log>.Fatal(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Fatal(ctx, "oh snap! got error", "error", err) */ Fatal(ctx context.Context, msg string, fields ...any) /* Fields is a helper function to use a map or slice to set fields using type assertion. []any must alternate string keys and arbitrary values, and extraneous ones are ignored. i.e: With Request HTTP Context: var ( first = "first value" second = "second value" ) <Imported_Log>.Panic(ctx, "hello", "first", first, "second", second) <Imported_Log>.Panic(ctx, xlog.Msgf("hello %s", "world!"), "first", first, "second", second) <Imported_Log>.Panic(ctx, "oh snap! got error", "error", err) */ Panic(ctx context.Context, msg string, fields ...any) }
type MultiLogger ¶
type MultiLogger struct {
// contains filtered or unexported fields
}
func NewMultiLogging ¶
func NewMultiLogging(entries ...Entry) MultiLogger
func (*MultiLogger) Close ¶
func (c *MultiLogger) Close()
func (*MultiLogger) Rotate ¶
func (c *MultiLogger) Rotate() error
func (*MultiLogger) RotateBy ¶
func (c *MultiLogger) RotateBy(key string) error
type Option ¶ added in v0.5.0
type Option interface {
// contains filtered or unexported methods
}
Option configures a Hook.
func WithLevel ¶ added in v0.5.0
WithLevel returns an Option that configures the version of the log.Logger used by a [OtelLogger]. The version should be the version of the package that is being logged.
func WithLogEnabled ¶ added in v0.5.0
func WithLogWriterDisabled ¶ added in v0.5.0
func WithLoggerProvider ¶ added in v0.5.0
func WithLoggerProvider(provider log.LoggerProvider) Option
WithLoggerProvider returns an Option that configures log.LoggerProvider
By default if this Option is not provided, the Logger will use the global LoggerProvider.
func WithSchemaURL ¶ added in v0.5.0
WithSchemaURL returns an Option that configures the semantic convention schema URL of the log.Logger used by a [OtelLogger]. The schemaURL should be the schema URL for the semantic conventions used in log records.
func WithServerAddress ¶ added in v0.5.0
WithServerAddress returns an Option that configures the semantic convention Server Address of the log.Logger used by a [OtelLogger]. The Server Address should be the Server Address for the semantic conventions used in log records.
func WithServerName ¶ added in v0.5.0
WithServerName returns an Option that configures the semantic convention Server Name of the log.Logger used by a [OtelLogger]. The Server Name should be the Server Name for the semantic conventions used in log records.
func WithVersion ¶ added in v0.5.0
WithVersion returns an Option that configures the version of the log.Logger used by a [OtelLogger]. The version should be the version of the package that is being logged.
type OtelHook ¶ added in v0.5.0
type OtelHook struct {
// contains filtered or unexported fields
}
Hook is a zerolog.Hook that sends all logging records it receives to OpenTelemetry. See package documentation for how conversions are made.
func NewOtelHook ¶ added in v0.5.0
NewHook returns a new [Hook] to be used as a [Zerolog.Hook]. If WithLoggerProvider is not provided, the returned Hook will use the global LoggerProvider.
type PgxLogger ¶ added in v0.5.0
type PgxLogger struct {
Log Logger
}
PgxLogger is a custom QueryTracer implementation for pgx using zerolog.
func (*PgxLogger) TraceQueryEnd ¶ added in v0.5.0
TraceQueryEnd logs the end of a query.
type SingleLogger ¶
func NoopSingleLogger ¶
func NoopSingleLogger() SingleLogger
type TrxLogger ¶
type TrxLogger struct {
MultiLogger
}
type ZeroLogger ¶
type ZeroLogger struct {
// contains filtered or unexported fields
}
func (*ZeroLogger) Debug ¶
func (zl *ZeroLogger) Debug(ctx context.Context, msg string, fields ...any)
func (*ZeroLogger) Error ¶
func (zl *ZeroLogger) Error(ctx context.Context, msg string, fields ...any)
func (*ZeroLogger) Fatal ¶
func (zl *ZeroLogger) Fatal(ctx context.Context, msg string, fields ...any)
func (*ZeroLogger) Info ¶
func (zl *ZeroLogger) Info(ctx context.Context, msg string, fields ...any)
func (*ZeroLogger) Panic ¶
func (zl *ZeroLogger) Panic(ctx context.Context, msg string, fields ...any)