Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(args ...interface{})
- func DebugWithContext(ctx context.Context, args ...interface{})
- func Error(args ...interface{})
- func ErrorWithContext(ctx context.Context, args ...interface{})
- func Fatal(args ...interface{})
- func FatalWithContext(ctx context.Context, args ...interface{})
- func GetLogFieldFromContext(ctx context.Context) map[string]interface{}
- func GetTimestampFormat() string
- func Info(args ...interface{})
- func InfoWithContext(ctx context.Context, args ...interface{})
- func LogWithContext(ctx context.Context, content ...interface{})
- func LogWithEchoContext(c echo.Context, content ...interface{})
- func NewEchoLoggerMiddleware() echo.MiddlewareFunc
- func Panic(args ...interface{})
- func PanicWithContext(ctx context.Context, args ...interface{})
- func RemoveLogKey(key string)
- func SetContext(ctx context.Context) *log.Entry
- func SetCustomLogField(ctx context.Context, logKey string, value interface{}) context.Context
- func SetDefaultFields(fields map[string]interface{})
- func SetFormatter(logFormat LogFormat)
- func SetIgnoredPaths(paths []string)
- func SetLevel(level Level)
- func SetLogConsole()
- func SetLogFile()
- func SetLogger(logger *Logger)
- func SetTimestampFormat(timestampFormat string)
- func Trace(args ...interface{})
- func TraceWithContext(ctx context.Context, args ...interface{})
- func Warn(args ...interface{})
- func WarnWithContext(ctx context.Context, args ...interface{})
- type Config
- type EchoLogger
- func (l *EchoLogger) Debug(i ...interface{})
- func (l *EchoLogger) Debugf(format string, args ...interface{})
- func (l *EchoLogger) Debugj(j log.JSON)
- func (l *EchoLogger) Error(i ...interface{})
- func (l *EchoLogger) Errorf(format string, args ...interface{})
- func (l *EchoLogger) Errorj(j log.JSON)
- func (l *EchoLogger) Fatal(i ...interface{})
- func (l *EchoLogger) Fatalf(format string, args ...interface{})
- func (l *EchoLogger) Fatalj(j log.JSON)
- func (l *EchoLogger) Formatter() logrus.Formatter
- func (l *EchoLogger) Info(i ...interface{})
- func (l *EchoLogger) Infof(format string, args ...interface{})
- func (l *EchoLogger) Infoj(j log.JSON)
- func (l *EchoLogger) Level() log.Lvl
- func (l *EchoLogger) Output() io.Writer
- func (l *EchoLogger) Panic(i ...interface{})
- func (l *EchoLogger) Panicf(format string, args ...interface{})
- func (l *EchoLogger) Panicj(j log.JSON)
- func (l *EchoLogger) Prefix() string
- func (l *EchoLogger) Print(i ...interface{})
- func (l *EchoLogger) Printf(format string, args ...interface{})
- func (l *EchoLogger) Printj(j log.JSON)
- func (l *EchoLogger) SetFormatter(formatter logrus.Formatter)
- func (l *EchoLogger) SetHeader(h string)
- func (l *EchoLogger) SetLevel(v log.Lvl)
- func (l *EchoLogger) SetOutput(w io.Writer)
- func (l *EchoLogger) SetPrefix(p string)
- func (l *EchoLogger) Warn(i ...interface{})
- func (l *EchoLogger) Warnf(format string, args ...interface{})
- func (l *EchoLogger) Warnj(j log.JSON)
- type FileConfig
- type GormLogger
- func (l *GormLogger) Error(ctx context.Context, s string, args ...interface{})
- func (l *GormLogger) Info(ctx context.Context, s string, args ...interface{})
- func (l *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *GormLogger) Warn(ctx context.Context, s string, args ...interface{})
- type HeaderKey
- type Level
- type LogFormat
- type LogKey
- type Logger
- func (l *Logger) GetLogFieldFromContext(ctx context.Context) map[string]interface{}
- func (l *Logger) RemoveLogKey(key string)
- func (l *Logger) SetContext(ctx context.Context) *log.Entry
- func (l *Logger) SetCustomLogField(ctx context.Context, logKey string, value interface{}) context.Context
- func (l *Logger) SetDefaultFields(fields map[string]interface{})
- func (l *Logger) SetFormatter(logFormat LogFormat)
- func (l *Logger) SetIgnoredPaths(paths []string)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetLogConsole()
- func (l *Logger) SetLogFile()
- func (l *Logger) SetLogFileWithConfig(fileConfig *FileConfig)
- func (l *Logger) SetTimestampFormat(timestampFormat string)
Constants ¶
const ( LogTypeAPI = "api" LogTypeRequest = "request" LogTypeResponse = "response" LogTypeError = "error" LogTypeDebug = "debug" LogTypeInfo = "info" LogTypeWarn = "warn" LogTypeSQL = "sql" LogTypeTrace = "trace" )
custom logtype
const ( DefaultTimestampFormat = "2006-01-02 15:04:05.00000" DefaultPrefix = "LogAdapter_" DefaultSourceField = "stack_trace" )
custom constants
Variables ¶
var (
DefaultLogKeys []LogKey = []LogKey{CorrelationIDLogKey, RequestIDLogKey, UserInfoLogKey}
)
Export default LogKeyMap
Functions ¶
func DebugWithContext ¶ added in v1.0.11
DebugWithContext log with debug level
func ErrorWithContext ¶ added in v1.0.11
ErrorWithContext log with error level
func FatalWithContext ¶ added in v1.0.11
FatalWithContext log with fatal level
func GetLogFieldFromContext ¶ added in v1.0.11
GetLogFieldFromContext gets log field from context for log field
func GetTimestampFormat ¶ added in v1.0.9
func GetTimestampFormat() string
GetTimestampFormat get timestamp format
func InfoWithContext ¶ added in v1.0.11
InfoWithContext log with info level
func LogWithContext ¶ added in v1.0.11
LogWithContext log content with context content[0] : message -> interface{}, content[1] : log type -> string, content[2] : log field -> map[string]interface{}
func LogWithEchoContext ¶
func LogWithEchoContext(c echo.Context, content ...interface{})
LogWithEchoContext log content with echo context content[0] : message -> interface{}, content[1] : log type -> string, content[2] : log field -> map[string]interface{}
func NewEchoLoggerMiddleware ¶
func NewEchoLoggerMiddleware() echo.MiddlewareFunc
NewEchoLoggerMiddleware returns a middleware that logs HTTP requests.
func PanicWithContext ¶ added in v1.0.11
PanicWithContext log with panic level
func RemoveLogKey ¶ added in v1.0.11
func RemoveLogKey(key string)
RemoveLogKey export remove a log key will not log this key
func SetContext ¶ added in v1.0.12
SetContext set log with context
func SetCustomLogField ¶ added in v1.0.11
SetCustomLogField set custom log field for always log this field, return new context
func SetDefaultFields ¶ added in v1.0.12
func SetDefaultFields(fields map[string]interface{})
SetDefaultFields set default fields for all log
func SetFormatter ¶ added in v1.0.9
func SetFormatter(logFormat LogFormat)
SetFormatter set logger formatter
func SetIgnoredPaths ¶ added in v1.1.0
func SetIgnoredPaths(paths []string)
SetIgnoredPaths for ignored path in stack trace field. By default logadapter print stacktrace with log has lever higher than WARN, always print stack trace with gorm_adapter Not to print file path has "runtime/" in stack trace. We use logadapter.UpdateIgnoredPaths([]string{"runtime/"})
func SetLogFile ¶ added in v1.0.9
func SetLogFile()
SetLogFile set log file, log file will be storaged in logs folder
func SetTimestampFormat ¶ added in v1.0.9
func SetTimestampFormat(timestampFormat string)
SetTimestampFormat set timestamp format
func TraceWithContext ¶ added in v1.0.11
TraceWithContext log with trace level
func WarnWithContext ¶ added in v1.0.11
WarnWithContext log with warn level
Types ¶
type Config ¶
type Config struct { IsUseLogFile bool // set true if write to file FileConfig *FileConfig // ignore if IsUseLogFile = false, set null if use default log file config LogLevel Level LogFormat LogFormat TimestampFormat string // if empty, use default timestamp format }
Config config instance log
type EchoLogger ¶ added in v1.0.9
type EchoLogger struct {
*Logger
}
EchoLogger extend logrus.Logger
func NewEchoLogger ¶ added in v1.0.9
func NewEchoLogger() *EchoLogger
NewEchoLogger return singleton logger
func (*EchoLogger) Debug ¶ added in v1.0.9
func (l *EchoLogger) Debug(i ...interface{})
Debug output message of debug level
func (*EchoLogger) Debugf ¶ added in v1.0.9
func (l *EchoLogger) Debugf(format string, args ...interface{})
Debugf output format message of debug level
func (*EchoLogger) Debugj ¶ added in v1.0.9
func (l *EchoLogger) Debugj(j log.JSON)
Debugj output message of debug level
func (*EchoLogger) Error ¶ added in v1.0.9
func (l *EchoLogger) Error(i ...interface{})
Error output message of error level
func (*EchoLogger) Errorf ¶ added in v1.0.9
func (l *EchoLogger) Errorf(format string, args ...interface{})
Errorf output format message of error level
func (*EchoLogger) Errorj ¶ added in v1.0.9
func (l *EchoLogger) Errorj(j log.JSON)
Errorj output json of error level
func (*EchoLogger) Fatal ¶ added in v1.0.9
func (l *EchoLogger) Fatal(i ...interface{})
Fatal output message of fatal level
func (*EchoLogger) Fatalf ¶ added in v1.0.9
func (l *EchoLogger) Fatalf(format string, args ...interface{})
Fatalf output format message of fatal level
func (*EchoLogger) Fatalj ¶ added in v1.0.9
func (l *EchoLogger) Fatalj(j log.JSON)
Fatalj output json of fatal level
func (*EchoLogger) Formatter ¶ added in v1.0.9
func (l *EchoLogger) Formatter() logrus.Formatter
Formatter return logger formatter
func (*EchoLogger) Info ¶ added in v1.0.9
func (l *EchoLogger) Info(i ...interface{})
Info output message of info level
func (*EchoLogger) Infof ¶ added in v1.0.9
func (l *EchoLogger) Infof(format string, args ...interface{})
Infof output format message of info level
func (*EchoLogger) Infoj ¶ added in v1.0.9
func (l *EchoLogger) Infoj(j log.JSON)
Infoj output json of info level
func (*EchoLogger) Level ¶ added in v1.0.9
func (l *EchoLogger) Level() log.Lvl
Level return logger level
func (*EchoLogger) Output ¶ added in v1.0.9
func (l *EchoLogger) Output() io.Writer
Output return logger io.Writer
func (*EchoLogger) Panic ¶ added in v1.0.9
func (l *EchoLogger) Panic(i ...interface{})
Panic output message of panic level
func (*EchoLogger) Panicf ¶ added in v1.0.9
func (l *EchoLogger) Panicf(format string, args ...interface{})
Panicf output format message of panic level
func (*EchoLogger) Panicj ¶ added in v1.0.9
func (l *EchoLogger) Panicj(j log.JSON)
Panicj output json of panic level
func (*EchoLogger) Prefix ¶ added in v1.0.9
func (l *EchoLogger) Prefix() string
Prefix return logger prefix This function do nothing
func (*EchoLogger) Print ¶ added in v1.0.9
func (l *EchoLogger) Print(i ...interface{})
Print output message of print level
func (*EchoLogger) Printf ¶ added in v1.0.9
func (l *EchoLogger) Printf(format string, args ...interface{})
Printf output format message of print level
func (*EchoLogger) Printj ¶ added in v1.0.9
func (l *EchoLogger) Printj(j log.JSON)
Printj output json of print level
func (*EchoLogger) SetFormatter ¶ added in v1.0.9
func (l *EchoLogger) SetFormatter(formatter logrus.Formatter)
SetFormatter logger formatter Only support logrus formatter
func (*EchoLogger) SetHeader ¶ added in v1.0.9
func (l *EchoLogger) SetHeader(h string)
SetHeader logger header Managed by Logrus itself This function do nothing
func (*EchoLogger) SetLevel ¶ added in v1.0.9
func (l *EchoLogger) SetLevel(v log.Lvl)
SetLevel logger level
func (*EchoLogger) SetOutput ¶ added in v1.0.9
func (l *EchoLogger) SetOutput(w io.Writer)
SetOutput logger io.Writer
func (*EchoLogger) SetPrefix ¶ added in v1.0.9
func (l *EchoLogger) SetPrefix(p string)
SetPrefix logger prefix This function do nothing
func (*EchoLogger) Warn ¶ added in v1.0.9
func (l *EchoLogger) Warn(i ...interface{})
Warn output message of warn level
func (*EchoLogger) Warnf ¶ added in v1.0.9
func (l *EchoLogger) Warnf(format string, args ...interface{})
Warnf output format message of warn level
func (*EchoLogger) Warnj ¶ added in v1.0.9
func (l *EchoLogger) Warnj(j log.JSON)
Warnj output json of warn level
type FileConfig ¶
type FileConfig struct { Filename string MaxSize int // megabytes MaxBackups int // number of log files MaxAge int // days IsCompress bool IsUseLocalTime bool }
FileConfig config for write log to file
type GormLogger ¶ added in v1.0.9
type GormLogger struct { *Logger SlowThreshold time.Duration SourceField string SkipErrRecordNotFound bool Debug bool }
GormLogger model
func (*GormLogger) Error ¶ added in v1.0.9
func (l *GormLogger) Error(ctx context.Context, s string, args ...interface{})
Error log error
func (*GormLogger) Info ¶ added in v1.0.9
func (l *GormLogger) Info(ctx context.Context, s string, args ...interface{})
Info log infor
func (*GormLogger) LogMode ¶ added in v1.0.9
func (l *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
LogMode get log mode, should set to Silent level in production
type Level ¶
type Level uint32
Level log level
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
type Logger ¶ added in v1.0.1
Logger instance
func New ¶ added in v1.0.9
func New() *Logger
New returns a logger instance with default configuration
func NewWithConfig ¶ added in v1.0.9
NewWithConfig returns a logger instance with custom configuration
func (*Logger) GetLogFieldFromContext ¶ added in v1.0.11
GetLogFieldFromContext gets log field from context for log field
func (*Logger) RemoveLogKey ¶ added in v1.0.11
RemoveLogKey remove a log key will not log this key
func (*Logger) SetContext ¶ added in v1.0.11
SetContext set log with context
func (*Logger) SetCustomLogField ¶ added in v1.0.11
func (l *Logger) SetCustomLogField(ctx context.Context, logKey string, value interface{}) context.Context
SetCustomLogField set custom log field for always log this field, return new context
func (*Logger) SetDefaultFields ¶ added in v1.0.12
SetDefaultFields set default fields for all log
func (*Logger) SetFormatter ¶ added in v1.0.1
SetFormatter set logger formatter
func (*Logger) SetIgnoredPaths ¶ added in v1.1.0
SetIgnoredPaths for ignored path in stack trace field. By default logadapter print stacktrace with log has lever higher than WARN, always print stack trace with gorm_adapter Not to print file path has "runtime/" in stack trace. We use logadapter.UpdateIgnoredPaths([]string{"runtime/"})
func (*Logger) SetLogConsole ¶ added in v1.0.1
func (l *Logger) SetLogConsole()
SetLogConsole set log console
func (*Logger) SetLogFile ¶ added in v1.0.1
func (l *Logger) SetLogFile()
SetLogFile set log file, log file will be storaged in logs folder
func (*Logger) SetLogFileWithConfig ¶ added in v1.0.10
func (l *Logger) SetLogFileWithConfig(fileConfig *FileConfig)
SetLogFileWithConfig set log file with file config
func (*Logger) SetTimestampFormat ¶ added in v1.0.2
SetTimestampFormat set timestamp format