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 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 Fields
- 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) SetConfig(config *Config) error
- func (l *Logger) SetConfigWithMap(configMap map[string]any) error
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Warn(ctx context.Context, v ...any)
- func (l *Logger) Warnf(ctx context.Context, format string, v ...any)
- func (l *Logger) WithComponent(component string) *Logger
- func (l *Logger) WithField(key string, value any) *Logger
- func (l *Logger) WithFields(fields logrus.Fields) *Logger
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 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 is the log level.
Level Level `mconv:"level"`
// TimeFormat is the log time format.
TimeFormat string `mconv:"time_format"`
// Format is the log format.
Format string `mconv:"format"`
// Caller is the add caller.
// If true, the caller will be added to the log.
Caller bool `mconv:"caller"`
// Path is the log file path.
// e.g., /var/log/app.log or /var/log/app.{YYYYmmdd}.log
Filepath string `mconv:"filepath"`
// MaxSize is the maximum size in megabytes of the log file before it gets rotated.
// It is only applicable for 'size' rotation type.
MaxSize int `mconv:"max_size"` // (MB)
// MaxBackups is the maximum number of old log files to retain.
// It is only applicable for 'size' rotation type.
MaxBackups int `mconv:"max_backups"` // (files)
// MaxAge is the maximum number of days to retain old log files.
// It is applicable for both 'size' and 'date' rotation types.
MaxAge int `mconv:"max_age"` // (days)
// Stdout is the stdout print.
Stdout bool `mconv:"stdout"`
// CtxKeys is the context keys to extract.
CtxKeys []string `mconv:"ctx_keys"`
}
func ConfigFromMap ¶ added in v0.1.2
ConfigFromMap parses and returns config from given map.
type Entry ¶
type Entry struct {
// log level
Level Level
// log message
Message string
// log fields
Data map[string]interface{}
// Context
Context context.Context
// 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 Level ¶
type Level int
func ParseLevel ¶ added in v0.1.4
ParseLevel parses a string level and returns the Level value.
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) WithComponent ¶ added in v0.1.4
WithComponent adds a component field to the logger.