// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package parser import ( "adm-task/config" "fmt" "git.getensh.com/common/gopkgsv2/logger" "git.getensh.com/common/gopkgsv2/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.Rpc.AdmTask.LogStacktrace logLevel := conf.Rpc.AdmTask.LogLevel if logLevel == "" { logLevel = conf.Log.Level } ms, _ := conf.Log.MaxSize.Int64() mb, _ := conf.Log.MaxBackups.Int64() ma, _ := conf.Log.MaxAge.Int64() maxSize := int(ms) maxBackups := int(mb) maxAge := int(ma) disableStacktrace := (logStacktrace == "true") // 新建全局日志器 logger.New(conf.RunMode, logLevel, fmt.Sprintf("%s/%s.log", conf.Log.Path, conf.Rpc.AdmTask.ServiceName), maxSize, maxBackups, maxAge, disableStacktrace, true) // access日志器 accessLogger := logger.New(conf.RunMode, logLevel, fmt.Sprintf("%s/%s-access.log", conf.Log.Path, conf.Rpc.AdmTask.ServiceName), maxSize, maxBackups, maxAge, disableStacktrace, false) // 设置访问日志 tasker.SetLogger(accessLogger) logConfig = conf.Log }