MSP-325 use new logger instead journal
This commit is contained in:
1 parent
24b22aa7f1
commit
04a07377c1
4 files changed
+86
-34
No files matched your search
@@ -2,19 +2,23 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/integration-system/go-cmp/cmp"
|
||||
"github.com/integration-system/isp-lib/v2/bootstrap"
|
||||
"github.com/integration-system/isp-lib/v2/config"
|
||||
"github.com/integration-system/isp-lib/v2/config/schema"
|
||||
"github.com/integration-system/isp-lib/v2/metric"
|
||||
"github.com/integration-system/isp-lib/v2/structure"
|
||||
"github.com/integration-system/isp-lib/v2/utils"
|
||||
logrus "github.com/integration-system/isp-log"
|
||||
"github.com/integration-system/isp-log/stdcodes"
|
||||
"github.com/pkg/errors"
|
||||
"isp-gate-service/accounting"
|
||||
"isp-gate-service/authenticate"
|
||||
"isp-gate-service/conf"
|
||||
"isp-gate-service/invoker"
|
||||
"isp-gate-service/log"
|
||||
"isp-gate-service/proxy"
|
||||
"isp-gate-service/redis"
|
||||
"isp-gate-service/repository"
|
||||
@@ -26,6 +30,8 @@ import (
|
||||
|
||||
var (
|
||||
version = "0.1.0"
|
||||
|
||||
logger *log.Adapter
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -43,7 +49,7 @@ func main() {
|
||||
|
||||
requiredModules, err := proxy.InitProxies(cfg.Locations)
|
||||
if err != nil {
|
||||
log.Fatal(stdcodes.ModuleInvalidLocalConfig, err)
|
||||
logrus.Fatal(stdcodes.ModuleInvalidLocalConfig, err)
|
||||
}
|
||||
for module, consumer := range requiredModules {
|
||||
bs.RequireModule(module, consumer, false)
|
||||
@@ -59,10 +65,7 @@ func onLocalConfigLoad(_ *conf.Configuration) {
|
||||
}
|
||||
|
||||
func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) {
|
||||
localCfg := config.Get().(*conf.Configuration)
|
||||
|
||||
repository.DbClient.ReceiveConfiguration(remoteConfig.Database)
|
||||
invoker.Journal.ReceiveConfiguration(remoteConfig.JournalSetting.Journal, localCfg.ModuleName)
|
||||
matcher.JournalMethods = matcher.NewAtLeastOneMatcher(remoteConfig.JournalSetting.MethodsPatterns)
|
||||
|
||||
redis.Client.ReceiveConfiguration(remoteConfig.Redis)
|
||||
@@ -73,7 +76,16 @@ func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) {
|
||||
metric.InitHttpServer(remoteConfig.Metrics)
|
||||
service.Metrics.Init()
|
||||
|
||||
server.Http.Init(remoteConfig.HttpSetting, oldRemoteConfig.HttpSetting)
|
||||
oldLogger := setLogger(remoteConfig.JournalSetting.Journal, oldRemoteConfig.JournalSetting.Journal)
|
||||
defer func() {
|
||||
if oldLogger != nil {
|
||||
_ = oldLogger.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
isDifferentSettingForHttpServ :=
|
||||
!cmp.Equal(remoteConfig.HttpSetting, oldRemoteConfig.HttpSetting) || oldLogger != nil
|
||||
server.Http.Init(isDifferentSettingForHttpServ, remoteConfig.HttpSetting.GetMaxRequestBodySize(), logger)
|
||||
}
|
||||
|
||||
func socketConfiguration(cfg interface{}) structure.SocketConfiguration {
|
||||
@@ -94,6 +106,9 @@ func onShutdown(_ context.Context, _ os.Signal) {
|
||||
proxy.Close()
|
||||
_ = redis.Client.Close()
|
||||
_ = invoker.Journal.Close()
|
||||
if logger != nil {
|
||||
_ = logger.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func handleRouteUpdate(configs structure.RoutingConfig) bool {
|
||||
@@ -110,3 +125,26 @@ func makeDeclaration(localConfig interface{}) bootstrap.ModuleInfo {
|
||||
Endpoints: []structure.EndpointDescriptor{},
|
||||
}
|
||||
}
|
||||
|
||||
func setLogger(loggerCfg, oldLoggerCfg conf.JorunalConfig) *log.Adapter {
|
||||
if cmp.Equal(loggerCfg, oldLoggerCfg) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
oldLogger := logger
|
||||
if utils.DEV {
|
||||
logger, err = log.New()
|
||||
} else {
|
||||
logger, err = log.New(log.WithFileRotation(log.Rotation{
|
||||
File: loggerCfg.Filename,
|
||||
MaxSizeMb: loggerCfg.MaxSizeMb,
|
||||
Compress: loggerCfg.Compress,
|
||||
}))
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Fatal(stdcodes.ModuleRunFatalError, errors.WithMessage(err, "set logger"))
|
||||
}
|
||||
|
||||
return oldLogger
|
||||
}
|
||||
Reference in new issue
Block a user