added colorized logging on Windows, minor tweaks

This commit is contained in:
Jarek Kowalski
2018-01-06 12:04:39 -08:00
parent 7a97f22df4
commit 9bf5d4a8c2
3 changed files with 12 additions and 8 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
}