Replace even more zap occurences

This commit is contained in:
Dane Everitt
2020-06-13 10:26:35 -07:00
parent 0ae286d617
commit 198a22f446
12 changed files with 80 additions and 125 deletions

View File

@@ -3,10 +3,10 @@ package parser
import (
"bytes"
"github.com/Jeffail/gabs/v2"
"github.com/apex/log"
"github.com/buger/jsonparser"
"github.com/iancoleman/strcase"
"github.com/pkg/errors"
"go.uber.org/zap"
"io/ioutil"
"os"
"regexp"
@@ -120,11 +120,9 @@ func (cfr *ConfigurationFileReplacement) SetAtPathway(c *gabs.Container, path st
// We're doing some regex here.
r, err := regexp.Compile(strings.TrimPrefix(cfr.IfValue, "regex:"))
if err != nil {
zap.S().Warnw(
"configuration if_value using invalid regexp, cannot do replacement",
zap.String("if_value", strings.TrimPrefix(cfr.IfValue, "regex:")),
zap.Error(err),
)
log.WithFields(log.Fields{"if_value": strings.TrimPrefix(cfr.IfValue, "regex:"), "error": err}).
Warn("configuration if_value using invalid regexp, cannot perform replacement")
return nil
}
@@ -179,11 +177,7 @@ func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplac
return match, errors.WithStack(err)
}
zap.S().Debugw(
"attempted to load a configuration value that does not exist",
zap.Strings("path", path),
zap.String("filename", f.FileName),
)
log.WithFields(log.Fields{"path": path, "filename": f.FileName}).Debug("attempted to load a configuration value that does not exist")
// If there is no key, keep the original value intact, that way it is obvious there
// is a replace issue at play.

View File

@@ -3,13 +3,13 @@ package parser
import (
"bufio"
"encoding/json"
"github.com/apex/log"
"github.com/beevik/etree"
"github.com/buger/jsonparser"
"github.com/icza/dyno"
"github.com/magiconair/properties"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"gopkg.in/ini.v1"
"gopkg.in/yaml.v2"
"io/ioutil"
@@ -30,6 +30,10 @@ const (
type ConfigurationParser string
func (cp ConfigurationParser) String() string {
return string(cp)
}
// Defines a configuration file for the server startup. These will be looped over
// and modified before the server finishes booting.
type ConfigurationFile struct {
@@ -63,11 +67,7 @@ func (f *ConfigurationFile) UnmarshalJSON(data []byte) error {
}
if err := json.Unmarshal(*m["replace"], &f.Replace); err != nil {
zap.S().Warnw(
"failed to unmarshal configuration file replacement",
zap.String("file", f.FileName),
zap.Error(err),
)
log.WithField("file", f.FileName).WithField("error", err).Warn("failed to unmarshal configuration file replacement")
f.Replace = []ConfigurationFileReplacement{}
}
@@ -131,7 +131,7 @@ func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error {
// Parses a given configuration file and updates all of the values within as defined
// in the API response from the Panel.
func (f *ConfigurationFile) Parse(path string, internal bool) error {
zap.S().Debugw("parsing configuration file", zap.String("path", path), zap.String("parser", string(f.Parser)))
log.WithField("path", path).WithField("parser", f.Parser.String()).Debug("parsing server configuration file")
if mb, err := json.Marshal(config.Get()); err != nil {
return err