Documentation ¶
Index ¶
- Constants
- func GetCorrelationID(ctx context.Context) string
- func GetLogFile() string
- func LogWithEchoContext(c echo.Context, content ...interface{})
- func NewEchoLoggerMiddleware() echo.MiddlewareFunc
- type Config
- type EchoLogAdapter
- func (l *EchoLogAdapter) Debug(i ...interface{})
- func (l *EchoLogAdapter) Debugf(format string, args ...interface{})
- func (l *EchoLogAdapter) Debugj(j log.JSON)
- func (l *EchoLogAdapter) Error(i ...interface{})
- func (l *EchoLogAdapter) Errorf(format string, args ...interface{})
- func (l *EchoLogAdapter) Errorj(j log.JSON)
- func (l *EchoLogAdapter) Fatal(i ...interface{})
- func (l *EchoLogAdapter) Fatalf(format string, args ...interface{})
- func (l *EchoLogAdapter) Fatalj(j log.JSON)
- func (l *EchoLogAdapter) Formatter() logrus.Formatter
- func (l *EchoLogAdapter) Info(i ...interface{})
- func (l *EchoLogAdapter) Infof(format string, args ...interface{})
- func (l *EchoLogAdapter) Infoj(j log.JSON)
- func (l *EchoLogAdapter) Level() log.Lvl
- func (l *EchoLogAdapter) Output() io.Writer
- func (l *EchoLogAdapter) Panic(i ...interface{})
- func (l *EchoLogAdapter) Panicf(format string, args ...interface{})
- func (l *EchoLogAdapter) Panicj(j log.JSON)
- func (l *EchoLogAdapter) Prefix() string
- func (l *EchoLogAdapter) Print(i ...interface{})
- func (l *EchoLogAdapter) Printf(format string, args ...interface{})
- func (l *EchoLogAdapter) Printj(j log.JSON)
- func (l *EchoLogAdapter) SetFormatter(formatter logrus.Formatter)
- func (l *EchoLogAdapter) SetHeader(h string)
- func (l *EchoLogAdapter) SetLevel(v log.Lvl)
- func (l *EchoLogAdapter) SetOutput(w io.Writer)
- func (l *EchoLogAdapter) SetPrefix(p string)
- func (l *EchoLogAdapter) Warn(i ...interface{})
- func (l *EchoLogAdapter) Warnf(format string, args ...interface{})
- func (l *EchoLogAdapter) Warnj(j log.JSON)
- type FileConfig
- type GormLogAdapter
- func (l *GormLogAdapter) Error(ctx context.Context, s string, args ...interface{})
- func (l *GormLogAdapter) Info(ctx context.Context, s string, args ...interface{})
- func (l *GormLogAdapter) LogMode(gormlogger.LogLevel) gormlogger.Interface
- func (l *GormLogAdapter) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *GormLogAdapter) Warn(ctx context.Context, s string, args ...interface{})
- type Key
- type Level
- type LogFormat
- type Logger
Constants ¶
const ( LogTypeAPI = "api" LogTypeRequest = "request" LogTypeResponse = "response" LogTypeError = "error" LogTypeDebug = "debug" LogTypeSQL = "sql" LogTypeTrace = "trace" )
custom logtype
const ( DefaultTimestampFormat = "2006-01-02T15:04:05.00000Z07:00" DefaultGormSourceField = "source" )
custom constants
Variables ¶
This section is empty.
Functions ¶
func GetCorrelationID ¶
GetCorrelationID return correlation id
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.
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 EchoLogAdapter ¶
type EchoLogAdapter struct {
*Logger
}
EchoLogAdapter extend logrus.Logger
func NewEchoLogAdapter ¶
func NewEchoLogAdapter(logger *Logger) *EchoLogAdapter
NewEchoLogAdapter return singleton logger
func (*EchoLogAdapter) Debug ¶
func (l *EchoLogAdapter) Debug(i ...interface{})
Debug output message of debug level
func (*EchoLogAdapter) Debugf ¶
func (l *EchoLogAdapter) Debugf(format string, args ...interface{})
Debugf output format message of debug level
func (*EchoLogAdapter) Debugj ¶
func (l *EchoLogAdapter) Debugj(j log.JSON)
Debugj output message of debug level
func (*EchoLogAdapter) Error ¶
func (l *EchoLogAdapter) Error(i ...interface{})
Error output message of error level
func (*EchoLogAdapter) Errorf ¶
func (l *EchoLogAdapter) Errorf(format string, args ...interface{})
Errorf output format message of error level
func (*EchoLogAdapter) Errorj ¶
func (l *EchoLogAdapter) Errorj(j log.JSON)
Errorj output json of error level
func (*EchoLogAdapter) Fatal ¶
func (l *EchoLogAdapter) Fatal(i ...interface{})
Fatal output message of fatal level
func (*EchoLogAdapter) Fatalf ¶
func (l *EchoLogAdapter) Fatalf(format string, args ...interface{})
Fatalf output format message of fatal level
func (*EchoLogAdapter) Fatalj ¶
func (l *EchoLogAdapter) Fatalj(j log.JSON)
Fatalj output json of fatal level
func (*EchoLogAdapter) Formatter ¶
func (l *EchoLogAdapter) Formatter() logrus.Formatter
Formatter return logger formatter
func (*EchoLogAdapter) Info ¶
func (l *EchoLogAdapter) Info(i ...interface{})
Info output message of info level
func (*EchoLogAdapter) Infof ¶
func (l *EchoLogAdapter) Infof(format string, args ...interface{})
Infof output format message of info level
func (*EchoLogAdapter) Infoj ¶
func (l *EchoLogAdapter) Infoj(j log.JSON)
Infoj output json of info level
func (*EchoLogAdapter) Output ¶
func (l *EchoLogAdapter) Output() io.Writer
Output return logger io.Writer
func (*EchoLogAdapter) Panic ¶
func (l *EchoLogAdapter) Panic(i ...interface{})
Panic output message of panic level
func (*EchoLogAdapter) Panicf ¶
func (l *EchoLogAdapter) Panicf(format string, args ...interface{})
Panicf output format message of panic level
func (*EchoLogAdapter) Panicj ¶
func (l *EchoLogAdapter) Panicj(j log.JSON)
Panicj output json of panic level
func (*EchoLogAdapter) Prefix ¶
func (l *EchoLogAdapter) Prefix() string
Prefix return logger prefix This function do nothing
func (*EchoLogAdapter) Print ¶
func (l *EchoLogAdapter) Print(i ...interface{})
Print output message of print level
func (*EchoLogAdapter) Printf ¶
func (l *EchoLogAdapter) Printf(format string, args ...interface{})
Printf output format message of print level
func (*EchoLogAdapter) Printj ¶
func (l *EchoLogAdapter) Printj(j log.JSON)
Printj output json of print level
func (*EchoLogAdapter) SetFormatter ¶
func (l *EchoLogAdapter) SetFormatter(formatter logrus.Formatter)
SetFormatter logger formatter Only support logrus formatter
func (*EchoLogAdapter) SetHeader ¶
func (l *EchoLogAdapter) SetHeader(h string)
SetHeader logger header Managed by Logrus itself This function do nothing
func (*EchoLogAdapter) SetLevel ¶
func (l *EchoLogAdapter) SetLevel(v log.Lvl)
SetLevel logger level
func (*EchoLogAdapter) SetOutput ¶
func (l *EchoLogAdapter) SetOutput(w io.Writer)
SetOutput logger io.Writer
func (*EchoLogAdapter) SetPrefix ¶
func (l *EchoLogAdapter) SetPrefix(p string)
SetPrefix logger prefix This function do nothing
func (*EchoLogAdapter) Warn ¶
func (l *EchoLogAdapter) Warn(i ...interface{})
Warn output message of warn level
func (*EchoLogAdapter) Warnf ¶
func (l *EchoLogAdapter) Warnf(format string, args ...interface{})
Warnf output format message of warn level
func (*EchoLogAdapter) Warnj ¶
func (l *EchoLogAdapter) 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 GormLogAdapter ¶
type GormLogAdapter struct { *Logger SlowThreshold time.Duration SourceField string SkipErrRecordNotFound bool Debug bool }
GormLogAdapter model
func NewGormLogAdapter ¶
func NewGormLogAdapter(log *Logger) *GormLogAdapter
NewGormLogAdapter gorm logrus GormLogAdapter
func (*GormLogAdapter) Error ¶
func (l *GormLogAdapter) Error(ctx context.Context, s string, args ...interface{})
Error function
func (*GormLogAdapter) Info ¶
func (l *GormLogAdapter) Info(ctx context.Context, s string, args ...interface{})
Info function
func (*GormLogAdapter) LogMode ¶
func (l *GormLogAdapter) LogMode(gormlogger.LogLevel) gormlogger.Interface
LogMode function
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 NewLogger ¶ added in v1.0.1
func NewLogger() *Logger
NewLogger returns a logger instance with default configuration
func NewLoggerWithConfig ¶ added in v1.0.1
NewLoggerWithConfig returns a logger instance with custom configuration
func (*Logger) SetFormatter ¶ added in v1.0.1
SetFormatter logger formatter
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(fileConfig *FileConfig)
SetLogFile set log file
func (*Logger) SetTimestampFormat ¶ added in v1.0.2
SetTimestampFormat set timestamp format