Update logging behavior
This commit is contained in:
parent
3b78b06fff
commit
6f1ba24761
28 changed files with 176 additions and 137 deletions
|
|
@ -64,7 +64,7 @@ func (exporter *Exporter) NewBackup(ctx context.Context, progress io.Writer, des
|
|||
backup.EndTime = time.Now().UTC()
|
||||
|
||||
return nil
|
||||
}, progress, "Writing backup files")
|
||||
}, progress, ctx, "Writing backup files")
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
|
|||
}
|
||||
|
||||
return nil
|
||||
}, progress, "Backing up core components")
|
||||
}, progress, ctx, "Backing up core components")
|
||||
|
||||
// backup instances
|
||||
logging.LogOperation(func() error {
|
||||
|
|
@ -165,6 +165,6 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
|
|||
})
|
||||
|
||||
return nil
|
||||
}, progress, "Creating instance snapshots")
|
||||
}, progress, ctx, "Creating instance snapshots")
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package exporter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
|
|
@ -53,7 +52,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
}
|
||||
|
||||
// determine target paths
|
||||
logging.LogMessage(progress, "Determining target paths")
|
||||
logging.LogMessage(progress, ctx, "Determining target paths")
|
||||
var stagingDir, archivePath string
|
||||
if task.StagingOnly {
|
||||
stagingDir = task.Dest
|
||||
|
|
@ -69,11 +68,11 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
if !task.StagingOnly && archivePath == "" {
|
||||
archivePath = exporter.NewArchivePath(Slug)
|
||||
}
|
||||
fmt.Fprintf(progress, "Staging Directory: %s\n", stagingDir)
|
||||
fmt.Fprintf(progress, "Archive Path: %s\n", archivePath)
|
||||
logging.ProgressF(progress, ctx, "Staging Directory: %s\n", stagingDir)
|
||||
logging.ProgressF(progress, ctx, "Archive Path: %s\n", archivePath)
|
||||
|
||||
// create the staging directory
|
||||
logging.LogMessage(progress, "Creating staging directory")
|
||||
logging.LogMessage(progress, ctx, "Creating staging directory")
|
||||
err = exporter.Environment.Mkdir(stagingDir, environment.DefaultDirPerm)
|
||||
if !environment.IsExist(err) && err != nil {
|
||||
return err
|
||||
|
|
@ -83,7 +82,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
// we need the staging directory to be deleted at the end
|
||||
if !task.StagingOnly {
|
||||
defer func() {
|
||||
logging.LogMessage(progress, "Removing staging directory")
|
||||
logging.LogMessage(progress, ctx, "Removing staging directory")
|
||||
exporter.Environment.RemoveAll(stagingDir)
|
||||
}()
|
||||
}
|
||||
|
|
@ -109,7 +108,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
|
||||
// find the report path
|
||||
reportPath := filepath.Join(stagingDir, "report.txt")
|
||||
fmt.Fprintln(progress, reportPath)
|
||||
logging.ProgressF(progress, ctx, reportPath)
|
||||
|
||||
// create the path
|
||||
report, err := exporter.Environment.Create(reportPath, environment.DefaultFilePerm)
|
||||
|
|
@ -122,26 +121,26 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
_, err := sl.Report(report)
|
||||
return err
|
||||
}
|
||||
}, progress, "Generating %s", Title)
|
||||
}, progress, ctx, "Generating %s", Title)
|
||||
|
||||
// if we only requested staging
|
||||
// all that is left is to write the log entry
|
||||
if task.StagingOnly {
|
||||
logging.LogMessage(progress, "Writing Log Entry")
|
||||
logging.LogMessage(progress, ctx, "Writing Log Entry")
|
||||
|
||||
// write out the log entry
|
||||
entry.Path = stagingDir
|
||||
entry.Packed = false
|
||||
exporter.ExporterLogger.Add(ctx, entry)
|
||||
|
||||
fmt.Fprintf(progress, "Wrote %s\n", stagingDir)
|
||||
logging.ProgressF(progress, ctx, "Wrote %s\n", stagingDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
// package everything up as an archive!
|
||||
if err := logging.LogOperation(func() error {
|
||||
var count int64
|
||||
defer func() { fmt.Fprintf(progress, "Wrote %d byte(s) to %s\n", count, archivePath) }()
|
||||
defer func() { logging.ProgressF(progress, ctx, "Wrote %d byte(s) to %s\n", count, archivePath) }()
|
||||
|
||||
st := status.NewWithCompat(progress, 1)
|
||||
st.Start()
|
||||
|
|
@ -152,12 +151,12 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
})
|
||||
|
||||
return err
|
||||
}, progress, "Writing archive"); err != nil {
|
||||
}, progress, ctx, "Writing archive"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// write out the log entry
|
||||
logging.LogMessage(progress, "Writing Log Entry")
|
||||
logging.LogMessage(progress, ctx, "Writing Log Entry")
|
||||
entry.Path = archivePath
|
||||
entry.Packed = true
|
||||
exporter.ExporterLogger.Add(ctx, entry)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ package exporter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
)
|
||||
|
||||
// ShouldPrune determines if a file with the provided modification time should be
|
||||
|
|
@ -43,7 +44,7 @@ func (exporter *Exporter) PruneExports(ctx context.Context, progress io.Writer)
|
|||
|
||||
// assemble path, and then remove the file!
|
||||
path := filepath.Join(sPath, entry.Name())
|
||||
fmt.Fprintf(progress, "Removing %s cause it is older than %d days\n", path, exporter.Config.MaxBackupAge)
|
||||
logging.ProgressF(progress, ctx, "Removing %s cause it is older than %d days\n", path, exporter.Config.MaxBackupAge)
|
||||
|
||||
if err := exporter.Still.Environment.Remove(path); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -46,18 +46,18 @@ type Snapshot struct {
|
|||
// Snapshot creates a new snapshot of this instance into dest
|
||||
func (snapshots *Exporter) NewSnapshot(ctx context.Context, instance *wisski.WissKI, progress io.Writer, desc SnapshotDescription) (snapshot Snapshot) {
|
||||
|
||||
logging.LogMessage(progress, "Locking instance")
|
||||
logging.LogMessage(progress, ctx, "Locking instance")
|
||||
if !instance.Locker().TryLock(ctx) {
|
||||
err := locker.Locked
|
||||
fmt.Fprintln(progress, err)
|
||||
logging.LogMessage(progress, "Aborting snapshot creation")
|
||||
logging.ProgressF(progress, ctx, "%v", err)
|
||||
logging.LogMessage(progress, ctx, "Aborting snapshot creation")
|
||||
|
||||
return Snapshot{
|
||||
ErrPanic: err,
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
logging.LogMessage(progress, "Unlocking instance")
|
||||
logging.LogMessage(progress, ctx, "Unlocking instance")
|
||||
instance.Locker().Unlock(ctx)
|
||||
}()
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ func (snapshots *Exporter) NewSnapshot(ctx context.Context, instance *wisski.Wis
|
|||
|
||||
snapshot.EndTime = time.Now().UTC()
|
||||
return nil
|
||||
}, progress, "Writing snapshot files")
|
||||
}, progress, ctx, "Writing snapshot files")
|
||||
|
||||
slices.Sort(snapshot.Manifest)
|
||||
return
|
||||
|
|
@ -89,11 +89,11 @@ func (snapshot *Snapshot) makeParts(ctx context.Context, progress io.Writer, sna
|
|||
if !needsRunning && !snapshot.Description.Keepalive {
|
||||
stack := instance.Barrel().Stack()
|
||||
|
||||
logging.LogMessage(progress, "Stopping instance")
|
||||
logging.LogMessage(progress, ctx, "Stopping instance")
|
||||
snapshot.ErrStop = stack.Down(ctx, progress)
|
||||
|
||||
defer func() {
|
||||
logging.LogMessage(progress, "Starting instance")
|
||||
logging.LogMessage(progress, ctx, "Starting instance")
|
||||
snapshot.ErrStart = stack.Up(ctx, progress)
|
||||
}()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue