Documentation ¶
Index ¶
- Variables
- func Debug(fields Fields)
- func Debugf(fields Fields, format string, args ...any)
- func Error(fields Fields)
- func Errorf(fields Fields, format string, args ...any)
- func Fatal(fields Fields)
- func Fatalf(fields Fields, format string, args ...any)
- func Info(fields Fields)
- func Infof(fields Fields, format string, args ...any)
- func Log(level Level, fields Fields)
- func Logf(level Level, fields Fields, format string, args ...any)
- func Panic(fields Fields)
- func Panicf(fields Fields, format string, args ...any)
- func Warn(fields Fields)
- func Warnf(fields Fields, format string, args ...any)
- type Entry
- type Fields
- type Level
- type Logger
- type Option
- func WithAttachFields(fields Fields) Option
- func WithCustomWriterOpts(writer Writer) Option
- func WithFileWriterOpts(file string) Option
- func WithHookOpts(hook func(Fields), levels ...Level) Option
- func WithJsonFormatOpts() Option
- func WithLevelOpts(level Level) Option
- func WithStdWriterOpts() Option
- type Writer
Constants ¶
This section is empty.
Variables ¶
var (
LevelValueMap = map[Level]int{LevelDebug: 0, LevelInfo: 1, LevelWarn: 2, LevelError: 3, LevelFatal: 4, LevelPanic: 5}
)
Functions ¶
func Debug ¶
func Debug(fields Fields)
Debug logs a message at the Debug level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message.
func Debugf ¶
Debugf logs a formatted message at the Debug level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message. format (string): The format string for the log message. args (...any): The arguments for the format string.
func Error ¶
func Error(fields Fields)
Error logs a message at the Error level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message.
func Errorf ¶
Errorf logs a formatted message at the Error level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message. format (string): The format string for the log message. args (...any): The arguments for the format string.
func Fatal ¶
func Fatal(fields Fields)
Fatal logs a message at the Fatal level with the given fields and then exits the application.
Parameters:
fields (Fields): The fields to include in the log message.
func Fatalf ¶
Fatalf logs a formatted message at the Fatal level with the given fields and then exits the application.
Parameters:
fields (Fields): The fields to include in the log message. format (string): The format string for the log message. args (...any): The arguments for the format string.
func Info ¶
func Info(fields Fields)
Info logs a message at the Info level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message.
func Infof ¶
Infof logs a formatted message at the Info level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message. format (string): The format string for the log message. args (...any): The arguments for the format string.
func Log ¶
Log logs a message at the specified level with the given fields.
Parameters:
level (Level): The log level (e.g., Debug, Info, Warn, Error, Fatal, Panic). fields (Fields): The fields to include in the log message.
func Logf ¶
Logf logs a formatted message at the specified level with the given fields.
Parameters:
level (Level): The log level (e.g., Debug, Info, Warn, Error, Fatal, Panic). fields (Fields): The fields to include in the log message. format (string): The format string for the log message. args (...any): The arguments for the format string.
func Panic ¶
func Panic(fields Fields)
Panic logs a message at the Panic level with the given fields and then panics.
Parameters:
fields (Fields): The fields to include in the log message.
func Panicf ¶
Panicf logs a formatted message at the Panic level with the given fields and then panics.
Parameters:
fields (Fields): The fields to include in the log message. format (string): The format string for the log message. args (...any): The arguments for the format string.
func Warn ¶
func Warn(fields Fields)
Warn logs a message at the Warn level with the given fields.
Parameters:
fields (Fields): The fields to include in the log message.
Types ¶
type Entry ¶
type Entry struct { File string `json:"file" yaml:"file" xml:"file"` Level string `json:"level" yaml:"level" xml:"level"` Service string `json:"service" yaml:"service" xml:"service"` TraceID string `json:"trace_id" yaml:"trace_id" xml:"trace_id"` CallTime string `json:"call_time" yaml:"call_time" xml:"call_time"` Data any `json:"data,omitempty" yaml:"data,omitempty" xml:"data,omitempty"` Extra map[string]any `json:"extra,omitempty" yaml:"extra,omitempty" xml:"extra,omitempty"` Message string `json:"message,omitempty" yaml:"message,omitempty" xml:"message,omitempty"` // contains filtered or unexported fields }
type Fields ¶
type Fields interface { Export() *Entry WithTraceID(traceID string) Fields WithMessage(message string) Fields WithData(data any) Fields WithField(key string, value any) Fields WithLevel(level Level) Fields WithService(service string) Fields WithCallTime(callTime time.Time) Fields WithBaseFields(base Fields) Fields WithAttachFields(attach Fields) Fields // contains filtered or unexported methods }
type Logger ¶
type Logger interface { Debug(fields Fields) Info(fields Fields) Warn(fields Fields) Error(fields Fields) Fatal(fields Fields) Panic(fields Fields) Log(level Level, fields Fields) Logf(level Level, fields Fields, format string, args ...any) Debugf(fields Fields, format string, args ...any) Infof(fields Fields, format string, args ...any) Warnf(fields Fields, format string, args ...any) Errorf(fields Fields, format string, args ...any) Fatalf(fields Fields, format string, args ...any) Panicf(fields Fields, format string, args ...any) }
func NewCustomLoggerWithOpts ¶ added in v1.2.17
NewCustomLoggerWithOpts creates and returns a new custom logger instance with the specified options. This function initializes a custom logger with default values and then applies the provided options to it.
The logger is configured with default options for standard writer, JSON formatting, and log level set to Info. Additional options can be passed and will be applied in the order they are provided.
Parameters:
opts (...Option): A variadic parameter that allows passing multiple Option functions to customize the logger.
Returns:
Logger: A configured logger instance with applied options.
type Option ¶ added in v1.2.17
type Option func(*customLogger)
func WithAttachFields ¶ added in v1.2.17
func WithCustomWriterOpts ¶ added in v1.2.17
func WithFileWriterOpts ¶ added in v1.2.17
func WithHookOpts ¶ added in v1.2.17
func WithJsonFormatOpts ¶ added in v1.2.17
func WithJsonFormatOpts() Option
func WithLevelOpts ¶ added in v1.2.17
func WithStdWriterOpts ¶ added in v1.2.17
func WithStdWriterOpts() Option
type Writer ¶
type Writer interface { Write(data []byte) Close() }
func NewFileWriter ¶ added in v1.2.17
func NewMultiWriter ¶ added in v1.2.17
func NewStderrConsoleWriter ¶ added in v1.2.17
func NewStderrConsoleWriter() Writer
func NewStdoutConsoleWriter ¶ added in v1.2.17
func NewStdoutConsoleWriter() Writer