picgo/corelib/log.go

104 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package corelib
//import (
// "go.uber.org/zap"
// "go.uber.org/zap/zapcore"
//)
//var Logger *zap.SugaredLogger
//
//func NewLogger() {
// writeSyncer := getLogWriter()
// encoder := getEncoder()
// core := zapcore.NewCore(encoder, writeSyncer, zapcore.DebugLevel)
// logger := zap.New(core, zap.AddCaller())
// Logger = logger.Sugar()
//}
//
//func getEncoder() zapcore.Encoder {
// encoderConfig := zap.NewProductionEncoderConfig()
// encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
// encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
// return zapcore.NewConsoleEncoder(encoderConfig)
//}
//
//func getLogWriter() zapcore.WriteSyncer {
// var (
// err error
// currentDir string
// )
// // 获取当前工作目录
// if currentDir, err = os.Getwd(); err != nil {
// log.Panic("获取当前工作目录失败: ", err)
// }
// logPath := path.Join(currentDir, configs.Settings.Server.LogPath)
// // Filename: 日志文件的位置
// // MaxSize在进行切割之前日志文件的最大大小以 MB 为单位)
// // MaxBackups保留旧文件的最大个数
// // MaxAges保留旧文件的最大天数
// // Compress是否压缩 / 归档旧文件
// lumberJackLogger := &lumberjack.Logger{
// Filename: logPath,
// MaxSize: 50,
// MaxBackups: 10,
// MaxAge: 1,
// Compress: false,
// }
// return zapcore.AddSync(lumberJackLogger)
//}
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var Logger *zap.SugaredLogger
func NewLogger() {
config := zap.NewProductionConfig()
config.OutputPaths = []string{
"stdout",
"tmp/picgo-info.log",
}
config.ErrorOutputPaths = []string{
"stderr",
"tmp/picgo-error.log",
}
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
logger, err := config.Build()
if err != nil {
panic(err)
}
Logger = logger.Sugar()
}
func Panic(args ...interface{}) {
Logger.Panic(args...)
}
func Debug(args ...interface{}) {
Logger.Debug(args...)
}
func Info(args ...interface{}) {
Logger.Info(args...)
}
func Warn(args ...interface{}) {
Logger.Warn(args...)
}
func Error(args ...interface{}) {
Logger.Error(args...)
}
func Fatal(args ...interface{}) {
Logger.Fatal(args...)
}
func Sync() {
Logger.Sync()
}