123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package utils
- import (
- "github.com/sirupsen/logrus"
- "gopkg.in/natefinch/lumberjack.v2"
- "os"
- "path"
- )
- const (
- DefaultLogPath = "./rdlucklog"
- DefaultBinlogPath = "./binlog"
- DefaultBinlogFile = "binlog.log"
- )
- var FileLog = logrus.New()
- var Binlog = logrus.New()
- var ApiLog = logrus.New()
- func init() {
- logPath := LogPath
- if logPath == "" {
- logPath = DefaultLogPath
- }
- logFile := LogFile
- if logFile == "" {
- logFile = "eta_chart_lib.log"
- }
- os.MkdirAll(logPath, os.ModePerm)
-
- logFileName := path.Join(logPath, logFile)
-
- rolling(FileLog, logFileName)
-
-
- jsonFormat := new(logrus.JSONFormatter)
- jsonFormat.DisableHTMLEscape = true
- FileLog.SetFormatter(jsonFormat)
- FileLog.SetReportCaller(true)
-
-
-
-
- initBinlog()
- initApiLog()
- }
- func initBinlog() {
-
- binlogPath := BinLogPath
- if binlogPath == "" {
- binlogPath = DefaultBinlogPath
- }
- binlogFile := BinLogFile
- if binlogFile == "" {
- binlogFile = DefaultBinlogFile
- }
- os.MkdirAll(binlogPath, os.ModePerm)
-
- logFileName := path.Join(binlogPath, binlogFile)
- rolling(Binlog, logFileName)
-
-
- jsonFormat := new(logrus.JSONFormatter)
- jsonFormat.DisableHTMLEscape = true
- Binlog.SetFormatter(jsonFormat)
- }
- func initApiLog() {
- logPath := ApiLogPath
- if logPath == "" {
- if RunMode == "release" {
- logPath = `/data/rdlucklog/eta_chart_lib`
- } else {
- logPath = `./rdlucklog/api`
- }
- }
- logFile := ApiLogFile
- if logFile == "" {
- logFile = "eta_chart_lib_api.log"
- }
- os.MkdirAll(logPath, os.ModePerm)
-
- logFileName := path.Join(logPath, logFile)
-
- rolling(ApiLog, logFileName)
-
-
- jsonFormat := new(logrus.JSONFormatter)
- jsonFormat.DisableHTMLEscape = true
- ApiLog.SetFormatter(jsonFormat)
- }
- func rolling(fLog *logrus.Logger, logFile string) {
-
- fLog.SetOutput(&lumberjack.Logger{
- Filename: logFile,
- MaxSize: 500,
- MaxBackups: 3,
- MaxAge: 7,
- Compress: true,
- })
- }
|