Start to add zap logger everywhere
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -19,10 +20,14 @@ type ConfigInterface interface {
|
||||
MeetsConditions(directory, torrentID, torrentName string, fileNames []string) bool
|
||||
GetOnLibraryUpdate() string
|
||||
GetNetworkBufferSize() int
|
||||
GetMountPath() string
|
||||
GetMountPoint() string
|
||||
}
|
||||
|
||||
func LoadZurgConfig(filename string) (ConfigInterface, error) {
|
||||
rlog := logutil.NewLogger()
|
||||
log := rlog.Named("config")
|
||||
|
||||
log.Debug("Loading config file", filename)
|
||||
content, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -35,6 +40,7 @@ func LoadZurgConfig(filename string) (ConfigInterface, error) {
|
||||
|
||||
switch initialConfig.Version {
|
||||
case "v1":
|
||||
log.Debug("Detected config version: v1")
|
||||
return loadV1Config(content)
|
||||
|
||||
default:
|
||||
|
||||
@@ -10,7 +10,7 @@ type ZurgConfig struct {
|
||||
CanRepair bool `yaml:"enable_repair"`
|
||||
OnLibraryUpdate string `yaml:"on_library_update"`
|
||||
NetworkBufferSize int `yaml:"network_buffer_size"`
|
||||
MountPath string `yaml:"mount_path"`
|
||||
MountPoint string `yaml:"mount_point"`
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) GetToken() string {
|
||||
@@ -57,6 +57,6 @@ func (z *ZurgConfig) GetNetworkBufferSize() int {
|
||||
return z.NetworkBufferSize
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) GetMountPath() string {
|
||||
return z.MountPath
|
||||
func (z *ZurgConfig) GetMountPoint() string {
|
||||
return z.MountPoint
|
||||
}
|
||||
|
||||
@@ -5,14 +5,19 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func loadV1Config(content []byte) (*ZurgConfigV1, error) {
|
||||
rlog := logutil.NewLogger()
|
||||
log := rlog.Named("config")
|
||||
|
||||
var configV1 ZurgConfigV1
|
||||
if err := yaml.Unmarshal(content, &configV1); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug("V1 config loaded successfully")
|
||||
|
||||
return &configV1, nil
|
||||
}
|
||||
@@ -22,9 +27,13 @@ func (z *ZurgConfigV1) GetVersion() string {
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetDirectories() []string {
|
||||
rlog := logutil.NewLogger()
|
||||
log := rlog.Named("config")
|
||||
|
||||
rootDirectories := make([]string, len(z.Directories))
|
||||
i := 0
|
||||
for directory := range z.Directories {
|
||||
log.Debug("Adding to rootDirectories", directory)
|
||||
rootDirectories[i] = directory
|
||||
i++
|
||||
}
|
||||
@@ -32,6 +41,12 @@ func (z *ZurgConfigV1) GetDirectories() []string {
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
// Obtain a new sugared logger instance
|
||||
rlog := logutil.NewLogger()
|
||||
log := rlog.Named("config")
|
||||
|
||||
log.Debug("Starting to build the group map from directories")
|
||||
|
||||
var groupMap = make(map[string][]string)
|
||||
var groupOrderMap = make(map[string]int) // To store GroupOrder for each directory
|
||||
|
||||
@@ -39,6 +54,7 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
for directory, val := range z.Directories {
|
||||
groupMap[val.Group] = append(groupMap[val.Group], directory)
|
||||
groupOrderMap[directory] = val.GroupOrder
|
||||
log.Debugf("Added directory to group: %s, group: %s, groupOrder: %d", directory, val.Group, val.GroupOrder)
|
||||
}
|
||||
|
||||
// Sort the slice based on GroupOrder and then directory name for deterministic order
|
||||
@@ -50,6 +66,7 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
return groupOrderMap[dirs[i]] < groupOrderMap[dirs[j]]
|
||||
})
|
||||
groupMap[group] = dirs
|
||||
log.Debugf("Sorted directories within a group: %s, sortedDirectories: %v", group, dirs)
|
||||
}
|
||||
|
||||
// Return a deep copy of the map
|
||||
|
||||
Reference in New Issue
Block a user