mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat: first pass at improving logging (#1956)
Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com>
This commit is contained in:
parent
3851b51d98
commit
b85dad0286
13 changed files with 53 additions and 43 deletions
|
@ -2,21 +2,22 @@ package utils
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func SaveConfig(filePath, fileName string, obj any) {
|
||||
file, err := json.MarshalIndent(obj, "", " ")
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to JSON marshal the uploadedFiles: %s", err)
|
||||
log.Error().Err(err).Msg("failed to JSON marshal the uploadedFiles")
|
||||
}
|
||||
|
||||
absolutePath := filepath.Join(filePath, fileName)
|
||||
err = os.WriteFile(absolutePath, file, 0644)
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to save configuration file to %s: %s", absolutePath, err)
|
||||
log.Error().Err(err).Str("filepath", absolutePath).Msg("failed to save configuration file")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,11 +32,11 @@ func LoadConfig(filePath, fileName string, obj interface{}) {
|
|||
|
||||
file, err := os.ReadFile(uploadFilePath)
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to read file: %s", err)
|
||||
log.Error().Err(err).Str("filepath", uploadFilePath).Msg("failed to read file")
|
||||
} else {
|
||||
err = json.Unmarshal(file, &obj)
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to JSON unmarshal the file %s: %v", uploadFilePath, err)
|
||||
log.Error().Err(err).Str("filepath", uploadFilePath).Msg("failed to parse file as JSON")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue