mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
better logging
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user