Documentation
¶
Index ¶
- func Close() error
- func Debug(msg string, args ...any)
- func Error(msg string, args ...any)
- func Info(msg string, args ...any)
- func NewContext(ctx context.Context, logger *Logger) context.Context
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func SetDefault(logger *Logger)
- func Sync() error
- func Warn(msg string, args ...any)
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugEnabled() bool
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorEnabled() bool
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoEnabled() bool
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) PrintEnabled() bool
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) Sync() error
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnEnabled() bool
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- type Option
- func ProductionOptions() []Option
- func WithBatch(batchSize uint64) Option
- func WithBuffer(bufferSize uint64) Option
- func WithDebugLevel() Option
- func WithErrorLevel() Option
- func WithFile(path string) Option
- func WithHandler(handler string) Option
- func WithInfoLevel() Option
- func WithJsonHandler() Option
- func WithPID() Option
- func WithReplaceAttr(replaceAttr func(groups []string, attr slog.Attr) slog.Attr) Option
- func WithRotateFile(path string, opts ...rotate.Option) Option
- func WithSource() Option
- func WithStderr() Option
- func WithStdout() Option
- func WithSyncTimer(d time.Duration) Option
- func WithTapeHandler() Option
- func WithTextHandler() Option
- func WithWarnLevel() Option
- func WithWriter(w io.Writer) Option
- type Syncer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶ added in v0.6.0
func Close() error
Close closes the default logger and returns an error if failed.
func NewContext ¶ added in v0.4.10
NewContext wraps context with logger and returns a new context.
func Print ¶ added in v0.6.0
func Print(args ...interface{})
Print logs a log with args in print level. It a old-school way to log.
func Printf ¶ added in v0.6.0
func Printf(format string, args ...interface{})
Printf logs a log with format and args in print level. It a old-school way to log.
func Println ¶ added in v0.6.0
func Println(args ...interface{})
Println logs a log with args in print level. It a old-school way to log.
func SetDefault ¶ added in v1.5.10
func SetDefault(logger *Logger)
SetDefault sets logger as the default logger.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the entry of logging in logit. It has several levels including debug, info, warn and error. It's also a syncer or closer if handler is a syncer or closer.
func FromContext ¶ added in v0.4.10
FromContext gets logger from context and returns the default logger if missed.
func NewLogger ¶
NewLogger creates a logger with given options or panics if failed. If you don't want to panic on failing, use NewLoggerGracefully instead.
func NewLoggerGracefully ¶ added in v1.5.10
NewLoggerGracefully creates a logger with given options or returns an error if failed. It's a more graceful way to create a logger than NewLogger function.
func (*Logger) DebugEnabled ¶ added in v1.5.10
DebugEnabled reports whether the logger should ignore logs whose level is lower than debug.
func (*Logger) ErrorEnabled ¶ added in v1.5.10
ErrorEnabled reports whether the logger should ignore logs whose level is lower than error.
func (*Logger) InfoEnabled ¶ added in v1.5.10
InfoEnabled reports whether the logger should ignore logs whose level is lower than info.
func (*Logger) Print ¶ added in v0.4.15
func (l *Logger) Print(args ...interface{})
Print logs a log with args in print level. It a old-school way to log.
func (*Logger) PrintEnabled ¶ added in v1.5.10
PrintEnabled reports whether the logger should ignore logs whose level is lower than print.
func (*Logger) Printf ¶ added in v0.4.15
Printf logs a log with format and args in print level. It a old-school way to log.
func (*Logger) Println ¶ added in v0.4.15
func (l *Logger) Println(args ...interface{})
Println logs a log with args in print level. It a old-school way to log.
func (*Logger) WarnEnabled ¶ added in v1.5.10
WarnEnabled reports whether the logger should ignore logs whose level is lower than warn.
type Option ¶ added in v0.4.10
type Option func(conf *config)
func ProductionOptions ¶ added in v1.5.10
func ProductionOptions() []Option
ProductionOptions returns some options that we think they are useful in production. We recommend you to use them, so we provide this convenient way to create such a logger.
func WithBatch ¶ added in v1.5.10
WithBatch sets a batch writer to config. You should specify a batch size in count. The remained logs in batch may discard if you kill the process without syncing or closing the logger.
func WithBuffer ¶ added in v1.5.10
WithBuffer sets a buffer writer to config. You should specify a buffer size in bytes. The remained data in buffer may discard if you kill the process without syncing or closing the logger.
func WithDebugLevel ¶ added in v1.5.10
func WithDebugLevel() Option
WithDebugLevel sets debug level to config.
func WithErrorLevel ¶ added in v1.5.10
func WithErrorLevel() Option
WithErrorLevel sets error level to config.
func WithFile ¶ added in v1.5.10
WithFile sets file to config. All logs will be written to a file in path. It will create all directories in path if not existed. The permission bits can be specified by defaults package. See defaults.FileDirMode and defaults.FileMode. If you want to customize the way open dir or file, see defaults.OpenFileDir and defaults.OpenFile.
func WithHandler ¶ added in v1.5.10
WithHandler sets handler to config. See RegisterHandler.
func WithInfoLevel ¶ added in v1.5.10
func WithInfoLevel() Option
WithInfoLevel sets info level to config.
func WithJsonHandler ¶ added in v1.5.10
func WithJsonHandler() Option
WithJsonHandler sets json handler to config.
func WithPID ¶ added in v1.5.10
func WithPID() Option
WithPID sets withPID=true to config. All logs will carry the process id.
func WithReplaceAttr ¶ added in v1.5.10
WithReplaceAttr sets replaceAttr to config.
func WithRotateFile ¶ added in v1.5.10
WithRotateFile sets rotate file to config. All logs will be written to a rotate file in path. A rotate file is useful in production, see rotate.File. The permission bits can be specified by defaults package. See defaults.FileDirMode and defaults.FileMode. Use rotate.Option to customize your rotate file.
func WithSource ¶ added in v1.5.10
func WithSource() Option
WithSource sets withSource=true to config. All logs will carry their caller information like file and line.
func WithStderr ¶ added in v1.5.10
func WithStderr() Option
WithStderr sets os.Stderr to config. All logs will be written to stderr.
func WithStdout ¶ added in v1.5.10
func WithStdout() Option
WithStdout sets os.Stdout to config. All logs will be written to stdout.
func WithSyncTimer ¶ added in v1.5.10
WithSyncTimer sets a sync timer duration to config. It will call Sync() so it depends on the handler used by logger.
func WithTapeHandler ¶ added in v1.5.10
func WithTapeHandler() Option
WithTapeHandler sets tape handler to config.
func WithTextHandler ¶ added in v1.5.10
func WithTextHandler() Option
WithTextHandler sets text handler to config.
func WithWarnLevel ¶ added in v1.5.10
func WithWarnLevel() Option
WithWarnLevel sets warn level to config.
func WithWriter ¶ added in v1.5.10
WithWriter sets writer to config. The writer is for writing logs.