better logging

This commit is contained in:
Simon Martens
2024-11-16 17:30:14 +01:00
parent 527fbfa000
commit 84fa6f7fa4
17 changed files with 221 additions and 106 deletions

View File

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
"github.com/kelseyhightower/envconfig"
)
@@ -68,15 +69,14 @@ func (c *ConfigProvider) Validate() error {
func readSettingsFile(cfg *Config, path string) *Config {
f, err := os.Open(path)
if err != nil {
fmt.Println("Error: ", err)
fmt.Println("Coudln't open ", path)
logging.Error(err, "Error opening config file "+path)
return cfg
}
defer f.Close()
dec := json.NewDecoder(f)
err = dec.Decode(cfg)
helpers.MaybePanic(err, "Error decoding config.json")
helpers.Assert(err, "Error decoding config file")
return cfg
}

View File

@@ -6,6 +6,8 @@ import (
"io"
"os"
"sync"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
)
type KGPZXML[T any] interface {
@@ -48,7 +50,7 @@ func (l *Library) Serialize() {
err := l.Agents.Serialize()
if err != nil {
l.Agents = nil
fmt.Println(err)
}
}()
@@ -57,7 +59,7 @@ func (l *Library) Serialize() {
err := l.Places.Serialize()
if err != nil {
l.Places = nil
fmt.Println(err)
}
}()
@@ -66,7 +68,7 @@ func (l *Library) Serialize() {
err := l.Works.Serialize()
if err != nil {
l.Works = nil
fmt.Println(err)
}
}()
@@ -75,7 +77,7 @@ func (l *Library) Serialize() {
err := l.Categories.Serialize()
if err != nil {
l.Categories = nil
fmt.Println(err)
}
}()
@@ -84,7 +86,7 @@ func (l *Library) Serialize() {
err := l.Issues.Serialize()
if err != nil {
l.Issues = nil
fmt.Println(err)
}
}()
@@ -93,7 +95,7 @@ func (l *Library) Serialize() {
err := l.Pieces.Serialize()
if err != nil {
l.Pieces = nil
fmt.Println(err)
}
}()
@@ -109,7 +111,7 @@ func (p *XMLProvider[T]) Serialize() error {
defer wg.Done()
var data T
if err := UnmarshalFile(path, &data); err != nil {
fmt.Println(err)
return
}
p.mu.Lock()
@@ -131,11 +133,10 @@ func (a *XMLProvider[T]) String() string {
func UnmarshalFile[T any](filename string, data *T) error {
xmlFile, err := os.Open(filename)
if err != nil {
fmt.Println(err)
return err
}
fmt.Println("Successfully opened " + filename)
defer xmlFile.Close()
logging.Info("Opened " + filename)
byteValue, _ := io.ReadAll(xmlFile)
xml.Unmarshal(byteValue, data)