1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

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

View File

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

View File

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

View File

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