mirror of
https://github.com/kopia/kopia.git
synced 2026-03-13 11:46:55 -04:00
added colorized logging on Windows, minor tweaks
This commit is contained in:
6
main.go
6
main.go
@@ -12,7 +12,8 @@
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/mattn/go-colorable"
|
||||
|
||||
"github.com/kopia/kopia/cli"
|
||||
"github.com/kopia/kopia/repo"
|
||||
@@ -49,7 +50,8 @@ func initializeLogging(ctx *kingpin.ParseContext) error {
|
||||
|
||||
log.Logger = log.Output(lf)
|
||||
} else {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, NoColor: runtime.GOOS == "windows"})
|
||||
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: colorable.NewColorableStderr()})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -232,9 +232,7 @@ func (m *Manager) loadManifestBlocks(blocks []block.Info) error {
|
||||
defer wg.Done()
|
||||
|
||||
for blk := range blockIDs {
|
||||
//t0 := time.Now()
|
||||
man, err := m.loadManifestBlock(blk)
|
||||
//log.Debug().Dur("duration", time.Since(t0)).Str("block", blk).Msg("loaded")
|
||||
if err != nil {
|
||||
errors <- err
|
||||
} else {
|
||||
@@ -254,7 +252,7 @@ func (m *Manager) loadManifestBlocks(blocks []block.Info) error {
|
||||
wg.Wait()
|
||||
close(errors)
|
||||
close(manifests)
|
||||
log.Debug().Dur("duration", time.Since(t0)).Msgf("finished loading blocks.")
|
||||
log.Debug().Dur("duration_ms", time.Since(t0)).Msgf("finished loading blocks.")
|
||||
// if there was any error, forward it
|
||||
if err := <-errors; err != nil {
|
||||
return err
|
||||
|
||||
10
repo/open.go
10
repo/open.go
@@ -39,18 +39,22 @@ type Options struct {
|
||||
}
|
||||
|
||||
// Open opens a Repository specified in the configuration file.
|
||||
func Open(ctx context.Context, configFile string, options *Options) (*Repository, error) {
|
||||
func Open(ctx context.Context, configFile string, options *Options) (rep *Repository, err error) {
|
||||
t0 := time.Now()
|
||||
log.Debug().Msgf("opening repository from %v", configFile)
|
||||
defer func() {
|
||||
log.Debug().Dur("duration", time.Since(t0)).Msg("opened repository")
|
||||
if err == nil {
|
||||
log.Debug().Dur("duration_ms", time.Since(t0)).Msg("opened repository")
|
||||
} else {
|
||||
log.Error().Dur("duration_ms", time.Since(t0)).Msg("failed to open repository")
|
||||
}
|
||||
}()
|
||||
|
||||
if options == nil {
|
||||
options = &Options{}
|
||||
}
|
||||
|
||||
configFile, err := filepath.Abs(configFile)
|
||||
configFile, err = filepath.Abs(configFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user