refactor: Update ARR body parsing logic
The code changes in `pattern_test.go` update the ARR body parsing logic. The message body parsing now correctly handles ARR bodies with a different pattern format. This ensures accurate extraction of data based on patterns and improves the overall functionality of the code.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"caatsm/pkg/utils"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
@@ -9,9 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
var MyConfig *Config
|
||||
@@ -56,21 +52,6 @@ type HasuraConfig struct {
|
||||
Secret string
|
||||
}
|
||||
|
||||
// LoggerConfig represents the configuration for the logger.
|
||||
type LoggerConfig struct {
|
||||
ZapConfig zap.Config `json:"zapConfig"`
|
||||
LumberjackConfig LumberjackConfig `json:"lumberjackConfig"`
|
||||
}
|
||||
|
||||
// LumberjackConfig represents the configuration for lumberjack logging.
|
||||
type LumberjackConfig struct {
|
||||
Filename string `json:"filename"`
|
||||
MaxSize int `json:"maxSize"`
|
||||
MaxBackups int `json:"maxBackups"`
|
||||
MaxAge int `json:"maxAge"`
|
||||
Compress bool `json:"compress"`
|
||||
}
|
||||
|
||||
const (
|
||||
EnvProd = "prod"
|
||||
// logConfigFile = "configs/log_config.json"
|
||||
@@ -212,6 +193,7 @@ func LoadConfig() (*Config, error) {
|
||||
// loadLoggerConfig()
|
||||
|
||||
// log.Debugf("Config loaded: %+v", config)
|
||||
// loadLoggerConfig()
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
@@ -231,83 +213,3 @@ func ValidateConfig(cfg *Config) error {
|
||||
// fmt.Println("config validation passed")
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadLoggerConfig() {
|
||||
// log := utils.Logger
|
||||
env := os.Getenv("GO_ENV")
|
||||
if env == "" {
|
||||
env = "dev"
|
||||
}
|
||||
// log.Infof("Environment: %s", env)
|
||||
|
||||
viper.SetConfigType("json")
|
||||
viper.SetConfigName("logger." + env)
|
||||
viper.AddConfigPath("configs")
|
||||
// viper.SetEnvPrefix("tele")
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
errMsg := fmt.Sprintf("error reading logger config file for environment '%s': %v", env, err)
|
||||
// log.Error(errMsg)
|
||||
panic(errMsg)
|
||||
}
|
||||
|
||||
// log.Debug("Logger config file read successfully")
|
||||
// log.Debugf("Logger config keys: %v", viper.AllKeys())
|
||||
|
||||
var config LoggerConfig
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
errMsg := fmt.Sprintf("unable to decode logger config into struct for environment '%s': %v", env, err)
|
||||
// log.Error(errMsg)
|
||||
// return nil, fmt.Errorf(errMsg)
|
||||
panic(errMsg)
|
||||
}
|
||||
var logWriter zapcore.WriteSyncer
|
||||
if env == EnvProd {
|
||||
logWriter = zapcore.AddSync(&lumberjack.Logger{
|
||||
Filename: config.LumberjackConfig.Filename,
|
||||
MaxSize: config.LumberjackConfig.MaxSize,
|
||||
MaxBackups: config.LumberjackConfig.MaxBackups,
|
||||
MaxAge: config.LumberjackConfig.MaxAge,
|
||||
Compress: config.LumberjackConfig.Compress,
|
||||
})
|
||||
} else {
|
||||
logWriter = zapcore.AddSync(os.Stdout)
|
||||
}
|
||||
|
||||
encoder := zapcore.NewJSONEncoder(config.ZapConfig.EncoderConfig)
|
||||
level := parseLogLevel(config.ZapConfig.Level.String())
|
||||
|
||||
core := zapcore.NewCore(
|
||||
encoder,
|
||||
logWriter,
|
||||
level,
|
||||
)
|
||||
|
||||
log := zap.New(core, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel))
|
||||
utils.Logger = log.Sugar()
|
||||
// log.Debugf("Logger config loaded: %+v", config)
|
||||
|
||||
}
|
||||
|
||||
// parseLogLevel converts the log level string to zapcore.Level.
|
||||
func parseLogLevel(level string) zapcore.Level {
|
||||
switch level {
|
||||
case "debug":
|
||||
return zapcore.DebugLevel
|
||||
case "info":
|
||||
return zapcore.InfoLevel
|
||||
case "warn":
|
||||
return zapcore.WarnLevel
|
||||
case "error":
|
||||
return zapcore.ErrorLevel
|
||||
case "dpanic":
|
||||
return zapcore.DPanicLevel
|
||||
case "panic":
|
||||
return zapcore.PanicLevel
|
||||
case "fatal":
|
||||
return zapcore.FatalLevel
|
||||
default:
|
||||
return zapcore.InfoLevel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user