Documentation
¶
Index ¶
- Constants
- func Debug(ctx context.Context, v ...interface{})
- func Debugf(ctx context.Context, format string, v ...interface{})
- func Error(ctx context.Context, v ...interface{})
- func Errorf(ctx context.Context, format string, v ...interface{})
- func Fatal(ctx context.Context, v ...interface{})
- func Fatalf(ctx context.Context, format string, v ...interface{})
- func Info(ctx context.Context, v ...interface{})
- func Infof(ctx context.Context, format string, v ...interface{})
- func IsDatePattern(pattern string) bool
- func Panic(ctx context.Context, v ...interface{})
- func Panicf(ctx context.Context, format string, v ...interface{})
- func Print(ctx context.Context, v ...interface{})
- func Printf(ctx context.Context, format string, v ...interface{})
- func SetAutoClean(days int)
- func SetConfig(config Config) error
- func SetCtxKeys(keys []string)
- func SetDefaultLogger(l *Logger)
- func SetFile(file string)
- func SetFormat(format string)
- func SetPath(path string)
- func SetStdoutPrint(enabled bool)
- func SetTimeFormat(timeFormat string)
- func Warn(ctx context.Context, v ...interface{})
- func Warnf(ctx context.Context, format string, v ...interface{})
- type Config
- type Entry
- type Hook
- type ILogger
- type Level
- type Logger
- func (l *Logger) AddHook(hook Hook)
- func (l *Logger) Debug(ctx context.Context, v ...any)
- func (l *Logger) Debugf(ctx context.Context, format string, v ...any)
- func (l *Logger) Error(ctx context.Context, v ...any)
- func (l *Logger) Errorf(ctx context.Context, format string, v ...any)
- func (l *Logger) Fatal(ctx context.Context, v ...any)
- func (l *Logger) Fatalf(ctx context.Context, format string, v ...any)
- func (l *Logger) GetLevel() Level
- func (l *Logger) Info(ctx context.Context, v ...any)
- func (l *Logger) Infof(ctx context.Context, format string, v ...any)
- func (l *Logger) Panic(ctx context.Context, v ...any)
- func (l *Logger) Panicf(ctx context.Context, format string, v ...any)
- func (l *Logger) Print(ctx context.Context, v ...any)
- func (l *Logger) Printf(ctx context.Context, format string, v ...any)
- func (l *Logger) RemoveHookByType(hookType Hook)
- func (l *Logger) SetAutoClean(autoClean int)
- func (l *Logger) SetConfig(config Config) error
- func (l *Logger) SetConfigWithMap(config map[string]any) error
- func (l *Logger) SetCtxKeys(keys []string)
- func (l *Logger) SetFile(file string)
- func (l *Logger) SetFormat(format string)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetPath(path string)
- func (l *Logger) SetStdoutPrint(enabled bool)
- func (l *Logger) SetTimeFormat(timeFormat string)
- func (l *Logger) Warn(ctx context.Context, v ...any)
- func (l *Logger) Warnf(ctx context.Context, format string, v ...any)
Constants ¶
const (
DefaultName = "default"
)
Variables ¶
This section is empty.
Functions ¶
func Error ¶
Error prints the logging content with [ERRO] header and newline. It also prints caller stack info if stack feature is enabled.
func Errorf ¶
Errorf prints the logging content with [ERRO] header, custom format and newline. It also prints caller stack info if stack feature is enabled.
func Fatal ¶
Fatal prints the logging content with [FATA] header and newline, then exit the current process.
func Fatalf ¶
Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
func IsDatePattern ¶
IsDatePattern checks if a file pattern contains date placeholders.
func Panicf ¶
Panicf prints the logging content with [PANI] header, custom format and newline, then panics.
func Print ¶
Print prints `v` with newline using fmt.Sprintln. The parameter `v` can be multiple variables.
func Printf ¶
Printf prints `v` with format `format` using fmt.Sprintf. The parameter `v` can be multiple variables.
func SetAutoClean ¶
func SetAutoClean(days int)
SetAutoClean sets the number of days to keep log files.
func SetCtxKeys ¶
func SetCtxKeys(keys []string)
SetCtxKeys sets the context keys to extract values from.
func SetDefaultLogger ¶
func SetDefaultLogger(l *Logger)
SetDefaultLogger sets the default logger for package glog. Note that there might be concurrent safety issue if calls this function in different goroutines.
Types ¶
type Config ¶
type Config struct {
Level Level `json:"level"`
Path string `json:"path"`
File string `json:"file"`
TimeFormat string `json:"time_format"`
Format string `json:"format"`
Stdout bool `json:"stdout"`
AutoClean int `json:"auto_clean"`
CtxKeys []string `json:"ctx_keys"`
}
func ConfigFromMap ¶ added in v0.1.2
ConfigFromMap parses and returns config from given map.
func DefaultConfig ¶
func DefaultConfig() Config
type Entry ¶
type Entry struct {
// log level
Level Level
// log message
Message string
// log fields
Data map[string]interface{}
// contains filtered or unexported fields
}
Entry represents a log entry.
type Hook ¶
type Hook interface {
// Levels returns the log levels that the hook applies to.
Levels() []Level
// Fire executes the hook when a log entry is written.
Fire(entry *Entry) error
}
Hook defines the log hook interface.
type ILogger ¶
type ILogger interface {
Print(ctx context.Context, v ...any) // Print logs a message at level Info.
Printf(ctx context.Context, format string, v ...any) // Printf logs a message at level Info.
Debug(ctx context.Context, v ...any) // Debug logs a message at level Debug.
Debugf(ctx context.Context, format string, v ...any) // Debugf logs a message at level Debug.
Info(ctx context.Context, v ...any) // Info logs a message at level Info.
Infof(ctx context.Context, format string, v ...any) // Infof logs a message at level Info.
Warn(ctx context.Context, v ...any) // Warn logs a message at level Warn.
Warnf(ctx context.Context, format string, v ...any) // Warnf logs a message at level Warn.
Error(ctx context.Context, v ...any) // Error logs a message at level Error.
Errorf(ctx context.Context, format string, v ...any) // Errorf logs a message at level Error.
Fatal(ctx context.Context, v ...any) // Fatal logs a message at level Fatal.
Fatalf(ctx context.Context, format string, v ...any) // Fatalf logs a message at level Fatal.
Panic(ctx context.Context, v ...any) // Panic logs a message at level Panic.
Panicf(ctx context.Context, format string, v ...any) // Panicf logs a message at level Panic.
}
ILogger is the interface for the logger.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the struct for logging management.
func (*Logger) RemoveHookByType ¶
RemoveHookByType removes hooks of a specific type. It compares the type of the hook with the provided hook type.
func (*Logger) SetAutoClean ¶
SetAutoClean sets the auto clean days.
func (*Logger) SetConfigWithMap ¶
SetConfigWithMap sets the logger configuration using a map.
func (*Logger) SetCtxKeys ¶
SetCtxKeys sets the context keys to extract.
func (*Logger) SetStdoutPrint ¶
SetStdoutPrint sets the stdout print.
func (*Logger) SetTimeFormat ¶
SetTimeFormat sets the log time format.