dataRT/config/log.go

138 lines
2.7 KiB
Go

package config
import (
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
type logConfig struct {
lumberjack.Logger
// DebugLevel, -1, logs are typically voluminous, and are usually disabled in
// production.
//
// InfoLevel, 0, is the default logging priority.
//
// WarnLevel, 1, logs are more important than Info, but don't need individual
// human review.
//
// ErrorLevel, 2, logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
//
// DPanicLevel, 3, logs are particularly important errors. In development the
// logger panics after writing the message.
//
// PanicLevel, 4, logs a message, then panics.
//
// FatalLevel, 5, logs a message, then calls os.Exit(1).
LogLevel int8 `json:"loglevel" yaml:"loglevel"`
}
func NewLogCinfig() *logConfig {
return new(logConfig)
}
func (conf *logConfig) GetFileName() string {
if conf == nil {
panic("log config is nil")
}
return conf.Filename
}
func (conf *logConfig) SetFileName(fileName string) {
if conf == nil {
panic("log config is nil")
}
conf.Filename = fileName
}
func (conf *logConfig) GetMaxSize() int {
if conf == nil {
panic("log config is nil")
}
return conf.MaxSize
}
func (conf *logConfig) SetMaxSize(maxSize int) {
if conf == nil {
panic("log config is nil")
}
conf.MaxSize = maxSize
}
func (conf *logConfig) GetMaxAge() int {
if conf == nil {
panic("log config is nil")
}
return conf.MaxAge
}
func (conf *logConfig) SetMaxAge(maxAge int) {
if conf == nil {
panic("log config is nil")
}
conf.MaxAge = maxAge
}
func (conf *logConfig) GetMaxBackups() int {
if conf == nil {
panic("log config is nil")
}
return conf.MaxBackups
}
func (conf *logConfig) SetMaxBackups(maxBackups int) {
if conf == nil {
panic("log config is nil")
}
conf.MaxBackups = maxBackups
}
func (conf *logConfig) GetLocalTime() bool {
if conf == nil {
panic("log config is nil")
}
return conf.LocalTime
}
func (conf *logConfig) SetLocalTime(useLocalTime bool) {
if conf == nil {
panic("log config is nil")
}
conf.LocalTime = useLocalTime
}
func (conf *logConfig) GetCompress() bool {
if conf == nil {
panic("log config is nil")
}
return conf.Compress
}
func (conf *logConfig) SetCompress(doCompress bool) {
if conf == nil {
panic("log config is nil")
}
conf.Compress = doCompress
}
func (conf *logConfig) GetLogLevel() zapcore.Level {
if conf == nil {
panic("log config is nil")
}
return zapcore.Level(conf.LogLevel)
}
func (conf *logConfig) SetLogLevel(logLevel zapcore.Level) {
if conf == nil {
panic("log config is nil")
}
if logLevel < -1 || logLevel > 5 {
panic("logLevel is invalid")
}
conf.LogLevel = int8(logLevel)
}
func logConfigName() string {
return "log.json"
}