feat: 修改config文件

This commit is contained in:
zhengkunwang223 2022-12-08 21:40:53 +08:00 committed by zhengkunwang223
parent eaada87313
commit 46201cc169
4 changed files with 25 additions and 20 deletions

View File

@ -3,6 +3,8 @@ package log
import (
"fmt"
"github.com/1Panel-dev/1Panel/backend/log"
"io"
"os"
"strings"
"time"
@ -12,20 +14,26 @@ import (
"github.com/sirupsen/logrus"
)
const (
TimeFormat = "2006-01-02 15:04:05"
RollingTimePattern = "0 0 * * *"
)
func Init() {
l := logrus.New()
setOutput(l, global.CONF.LogConfig)
global.LOG = l
global.LOG.Info("init success")
global.LOG.Info("init logger successfully")
}
func setOutput(logger *logrus.Logger, config configs.LogConfig) {
writer, err := log.NewWriterFromConfig(&log.Config{
LogPath: config.Path,
FileName: config.LogName,
TimeTagFormat: "2006-01-02-15-04-05",
MaxRemain: config.LogBackup,
LogPath: config.Path,
FileName: config.LogName,
TimeTagFormat: TimeFormat,
MaxRemain: config.LogBackup,
RollingTimePattern: RollingTimePattern,
})
if err != nil {
panic(err)
@ -34,15 +42,15 @@ func setOutput(logger *logrus.Logger, config configs.LogConfig) {
if err != nil {
panic(err)
}
logger.SetOutput(writer)
fileAndStdoutWriter := io.MultiWriter(writer, os.Stdout)
logger.SetOutput(fileAndStdoutWriter)
logger.SetLevel(level)
logger.SetFormatter(new(MineFormatter))
}
type MineFormatter struct{}
const TimeFormat = "2006-01-02 15:04:05"
func (s *MineFormatter) Format(entry *logrus.Entry) ([]byte, error) {
var cstSh, _ = time.LoadLocation(global.CONF.LogConfig.TimeZone)
detailInfo := ""

View File

@ -38,8 +38,8 @@ func setWebStatic(rootRouter *gin.Engine) {
func Routers() *gin.Engine {
Router := gin.Default()
//Router.Use(middleware.CSRF())
//Router.Use(middleware.LoadCsrfToken())
Router.Use(middleware.CSRF())
Router.Use(middleware.LoadCsrfToken())
setWebStatic(Router)
docs.SwaggerInfo.BasePath = "/api/v1"
@ -64,7 +64,7 @@ func Routers() *gin.Engine {
}
PrivateGroup := Router.Group("/api/v1")
// PrivateGroup.Use(middleware.SafetyAuth())
//PrivateGroup.Use(middleware.SafetyAuth())
{
systemRouter.InitBaseRouter(PrivateGroup)
systemRouter.InitDashboardRouter(PrivateGroup)

View File

@ -7,10 +7,6 @@ import (
"path"
)
const (
RollingTimePattern = "0 0 * * *"
)
var (
BufferSize = 0x100000
DefaultFileMode = os.FileMode(0644)
@ -21,10 +17,11 @@ var (
)
type Config struct {
TimeTagFormat string
LogPath string
FileName string
MaxRemain int
TimeTagFormat string
LogPath string
FileName string
MaxRemain int
RollingTimePattern string
}
type Manager interface {

View File

@ -35,7 +35,7 @@ func NewManager(c *Config) (Manager, error) {
wg: sync.WaitGroup{},
}
if _, err := m.cr.AddFunc(RollingTimePattern, func() {
if _, err := m.cr.AddFunc(c.RollingTimePattern, func() {
m.fire <- m.GenLogFileName(c)
}); err != nil {
return nil, err