Documentation ¶
Index ¶
- func DisableQuote(logger *logrus.Logger)
- func DisableQuoteTemporarily(logger *logrus.Logger, callback func())
- func DisposeLogger(logger *logrus.Logger) error
- func EnableQuote(logger *logrus.Logger)
- func NewFileLogger(filePath string, formatter logrus.Formatter, level logrus.Level, ...) (*logrus.Logger, error)
- func NewLogger(formatter logrus.Formatter, level logrus.Level) *logrus.Logger
- func NewRotateFileLogger(filePath string, rotationTime, maxAge time.Duration, softLinkFlag bool, ...) (*logrus.Logger, error)deprecated
- func NewTextFormatter(timestampFormat string) logrus.Formatter
- func PrintBasicDetails()
- func PrintError(err error)
- func PrintErrorWithLogger(err error, logger *logrus.Logger)
- func SetConsoleLevel(level logrus.Level)
- func SetLevel(logger *logrus.Logger, level logrus.Level)
- func SetUp(config *Config)
- func StringToLevel(str string) logrus.Level
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableQuote ¶ added in v1.13.10
func DisableQuoteTemporarily ¶ added in v1.13.10
DisableQuoteTemporarily
@param logger (1) 可以为nil
(2) 只有当formatter为 *logrus.TextFormatter 类型,DisableQuote才会生效
func EnableQuote ¶ added in v1.13.10
func NewFileLogger ¶
func NewFileLogger(filePath string, formatter logrus.Formatter, level logrus.Level, toConsoleFlag bool) (*logrus.Logger, error)
NewFileLogger
PS: 如果 logger.Out 被释放后继续调用 logger 进行输出,会失败(e.g. 控制台os.Stderr有输出: Failed to write to log, write /Users/richelieu/Downloads/a.txt: file already closed).
@param filePath 内部会做处理:
(1) 会尝试创建父级目录 (2) 文件不存在,会自动创建 (3) 文件存在:是个文件,追加在最后;是个目录,返回error
@param formatter 可以为nil,此时将采用默认值 @param toConsoleFlag true: 输出到日志文件的同时,也输出到控制台; false: 只输出到文件日志
func NewRotateFileLogger
deprecated
func NewRotateFileLogger(filePath string, rotationTime, maxAge time.Duration, softLinkFlag bool, formatter logrus.Formatter, level logrus.Level, toConsoleFlag bool) (*logrus.Logger, error)
NewRotateFileLogger
Deprecated: 不推荐使用.
PS: 如果 logger.Out 被释放后继续调用 logger 进行输出,会失败(e.g. 控制台os.Stderr有输出: Failed to write to log, invalid argument).
@param filePath 内部会做处理:
(1) 会尝试创建父级目录 (2) 文件不存在,会自动创建 (3) 文件存在:是个文件,追加在最后;是个目录,返回error
func NewTextFormatter ¶
NewTextFormatter
PS: 外部在调用此方法后,建议调用: Logger.SetReportCaller(true)!!!
@param timestampFormat 可以为""(将采用默认值)
e.g. 日志输出 time=2023-03-23 16:46:23.398+08:00 level=info msg=[CHIMERA, PROCESS] pid: [8579]. func=PrintBasicDetails(logrusKit/basicDetails.go:17) time=2023-03-23 16:46:23.398+08:00 level=info msg=[CHIMERA, OS] os: [darwin]. func=PrintBasicDetails(logrusKit/basicDetails.go:20) time=2023-03-23 16:46:23.398+08:00 level=info msg=[CHIMERA, OS] arch: [arm64]. func=PrintBasicDetails(logrusKit/basicDetails.go:21)
func PrintError ¶
func PrintError(err error)
PrintError
@param err 只有通过"github.com/pkg/errors" New 或 Wrap 的error才有堆栈信息
func PrintErrorWithLogger ¶
func StringToLevel ¶
StringToLevel string => logrus.Level