Include more (and customizable) context with backup logs

This commit is contained in:
Dane Everitt
2020-12-27 16:16:40 -08:00
parent b26db99ee7
commit 902f9f5944
6 changed files with 65 additions and 51 deletions

View File

@@ -2,7 +2,6 @@ package backup
import (
"errors"
"github.com/apex/log"
"github.com/pterodactyl/wings/server/filesystem"
"os"
)
@@ -40,6 +39,11 @@ func (b *LocalBackup) Remove() error {
return os.Remove(b.Path())
}
// Attaches additional context to the log output for this backup.
func (b *LocalBackup) WithLogContext(c map[string]interface{}) {
b.logContext = c
}
// Generates a backup of the selected files and pushes it to the defined location
// for this instance.
func (b *LocalBackup) Generate(basePath, ignore string) (*ArchiveDetails, error) {
@@ -48,16 +52,11 @@ func (b *LocalBackup) Generate(basePath, ignore string) (*ArchiveDetails, error)
Ignore: ignore,
}
l := log.WithFields(log.Fields{
"backup_id": b.Uuid,
"adapter": "local",
})
l.Info("creating backup for server...")
b.log().Info("creating backup for server...")
if err := a.Create(b.Path()); err != nil {
return nil, err
}
l.Info("created backup successfully")
b.log().Info("created backup successfully")
return b.Details(), nil
}