Documentation
¶
Index ¶
- Constants
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func Info(msg string, fields ...zap.Field)
- func LevelToString(l zapcore.Level) string
- func Warn(msg string, fields ...zap.Field)
- type LoggerComponent
- type LoggerConfig
- type LoggerOption
- func WithLoggerCompress(compress bool) LoggerOption
- func WithLoggerFilename(filename string) LoggerOption
- func WithLoggerIsFile(isFile bool) LoggerOption
- func WithLoggerLevel(level string) LoggerOption
- func WithLoggerMaxAge(maxAge int) LoggerOption
- func WithLoggerMaxBackups(maxBackups int) LoggerOption
- func WithLoggerMaxSize(maxSize int) LoggerOption
- func WithLoggerStdout(isStdout bool) LoggerOption
Constants ¶
View Source
const ( DefaultFilename = "./logs/app.log" DebugLevel zapcore.Level = iota - 1 InfoLevel WarnLevel ErrorLevel )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LoggerComponent ¶
type LoggerComponent struct {
// contains filtered or unexported fields
}
LoggerComponent 日志组件
func NewLoggerComponent ¶
func NewLoggerComponent(opts ...LoggerOption) *LoggerComponent
NewLoggerComponent 创建日志组件
func (*LoggerComponent) GetLogger ¶
func (l *LoggerComponent) GetLogger() *zap.Logger
type LoggerConfig ¶
type LoggerConfig struct {
Level string // debug, info, warn, error
IsStdout bool // 是否输出到控制台
IsFile bool // 是否输出到文件
Filename string // 日志文件名
MaxSize int // MB
MaxBackups int // 最大备份数
MaxAge int // 天
Compress bool // 是否压缩
}
LoggerConfig 日志配置
type LoggerOption ¶
type LoggerOption func(*LoggerComponent)
LoggerOption 定义日志选项函数类型
func WithLoggerCompress ¶
func WithLoggerCompress(compress bool) LoggerOption
WithLoggerCompress 设置是否压缩
func WithLoggerFilename ¶
func WithLoggerFilename(filename string) LoggerOption
WithLoggerFilename 设置日志文件名
func WithLoggerMaxBackups ¶
func WithLoggerMaxBackups(maxBackups int) LoggerOption
WithLoggerMaxBackups 设置最大备份数
func WithLoggerMaxSize ¶
func WithLoggerMaxSize(maxSize int) LoggerOption
WithLoggerMaxSize 设置日志文件最大大小
func WithLoggerStdout ¶
func WithLoggerStdout(isStdout bool) LoggerOption
WithLoggerStdout 设置是否输出到控制台
Click to show internal directories.
Click to hide internal directories.