123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package parser
- import (
- "fmt"
- "smart-site-management-gateway/config"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker"
- )
- var logConfig config.LogConfig
- func LoggerHandler(conf *config.Configure) {
- // logConfig.Path 不为空表示已经初始化
- if logConfig.Path != "" {
- if logConfig.Path == conf.Log.Path {
- return
- } else {
- // 刷盘
- // logger.Sync()
- }
- }
- // 取出Stacktrace和Level
- logStacktrace := conf.SmartSiteManagementGateway.LogStacktrace
- logLevel := conf.SmartSiteManagementGateway.LogLevel
- if logLevel == "" {
- logLevel = conf.Log.Level
- }
- // 新建全局日志器
- logger.New(conf.RunMode,
- logLevel,
- fmt.Sprintf("%s/%s.log", conf.Log.Path, conf.SmartSiteManagementGateway.ServiceName),
- conf.Log.MaxSize,
- conf.Log.MaxBackups,
- conf.Log.MaxAge,
- logStacktrace,
- true)
- // access日志器
- accessLogger := logger.New(conf.RunMode,
- logLevel,
- fmt.Sprintf("%s/%s-access.log", conf.Log.Path, conf.SmartSiteManagementGateway.ServiceName),
- conf.Log.MaxSize,
- conf.Log.MaxBackups,
- conf.Log.MaxAge,
- logStacktrace,
- false)
- // 设置访问日志
- tasker.SetLogger(accessLogger)
- logConfig = conf.Log
- }
|