forked from toolshed/abra
refactor: use central logger
This commit is contained in:
@ -5,7 +5,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@ -16,13 +16,13 @@ func LoadAbraConfig() Abra {
|
||||
wd, _ := os.Getwd()
|
||||
configFile := findAbraConfig(wd)
|
||||
if configFile == "" {
|
||||
logrus.Debugf("no config file found")
|
||||
log.Debugf("no config file found")
|
||||
return Abra{}
|
||||
}
|
||||
data, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
// Do nothing, when an error occurs
|
||||
logrus.Debugf("error reading config file: %s", err)
|
||||
log.Debugf("error reading config file: %s", err)
|
||||
return Abra{}
|
||||
}
|
||||
|
||||
@ -30,10 +30,10 @@ func LoadAbraConfig() Abra {
|
||||
err = yaml.Unmarshal(data, &config)
|
||||
if err != nil {
|
||||
// Do nothing, when an error occurs
|
||||
logrus.Debugf("error loading config file: %s", err)
|
||||
log.Debugf("error loading config file: %s", err)
|
||||
return Abra{}
|
||||
}
|
||||
logrus.Debugf("config file loaded from: %s", configFile)
|
||||
log.Debugf("config file loaded from: %s", configFile)
|
||||
config.configPath = configFile
|
||||
return config
|
||||
}
|
||||
@ -73,18 +73,18 @@ type Abra struct {
|
||||
// 3. use $HOME/.abra when above two options failed
|
||||
func (a Abra) GetAbraDir() string {
|
||||
if dir, exists := os.LookupEnv("ABRA_DIR"); exists && dir != "" {
|
||||
logrus.Debug("read abra dir from $ABRA_DIR")
|
||||
log.Debug("read abra dir from $ABRA_DIR")
|
||||
return dir
|
||||
}
|
||||
if a.AbraDir != "" {
|
||||
logrus.Debug("read abra dir from config file")
|
||||
log.Debug("read abra dir from config file")
|
||||
if path.IsAbs(a.AbraDir) {
|
||||
return a.AbraDir
|
||||
}
|
||||
// Make the path absolute
|
||||
return path.Join(a.configPath, a.AbraDir)
|
||||
}
|
||||
logrus.Debug("using default abra dir")
|
||||
log.Debug("using default abra dir")
|
||||
return os.ExpandEnv("$HOME/.abra")
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
)
|
||||
|
||||
const MAX_SANITISED_APP_NAME_LENGTH = 45
|
||||
@ -26,7 +26,7 @@ func GetServers() ([]string, error) {
|
||||
return servers, err
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved %v servers: %s", len(servers), servers)
|
||||
log.Debugf("retrieved %v servers: %s", len(servers), servers)
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
@ -39,7 +39,7 @@ func ReadServerNames() ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR)
|
||||
log.Debugf("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR)
|
||||
|
||||
return serverNames, nil
|
||||
}
|
||||
@ -63,7 +63,7 @@ func GetAllFilesInDirectory(directory string) ([]fs.FileInfo, error) {
|
||||
|
||||
realPath, err := filepath.EvalSymlinks(filePath)
|
||||
if err != nil {
|
||||
logrus.Warningf("broken symlink in your abra config folders: %s", filePath)
|
||||
log.Warnf("broken symlink in your abra config folders: %s", filePath)
|
||||
} else {
|
||||
realFile, err := os.Stat(realPath)
|
||||
if err != nil {
|
||||
@ -96,7 +96,7 @@ func GetAllFoldersInDirectory(directory string) ([]string, error) {
|
||||
filePath := path.Join(directory, file.Name())
|
||||
realDir, err := filepath.EvalSymlinks(filePath)
|
||||
if err != nil {
|
||||
logrus.Warningf("broken symlink in your abra config folders: %s", filePath)
|
||||
log.Warnf("broken symlink in your abra config folders: %s", filePath)
|
||||
} else if stat, err := os.Stat(realDir); err == nil && stat.IsDir() {
|
||||
// path is a directory
|
||||
folders = append(folders, file.Name())
|
||||
|
Reference in New Issue
Block a user