vault: pass a logger around to logical backends

This commit is contained in:
Mitchell Hashimoto
2015-04-04 11:39:58 -07:00
parent d9e38470a8
commit 0109031e63
4 changed files with 43 additions and 1 deletions

View File

@@ -2,6 +2,8 @@ package framework
import (
"fmt"
"io/ioutil"
"log"
"regexp"
"sort"
"strings"
@@ -49,6 +51,7 @@ type Backend struct {
Rollback RollbackFunc
RollbackMinAge time.Duration
logger *log.Logger
once sync.Once
pathsRe []*regexp.Regexp
}
@@ -123,6 +126,21 @@ func (b *Backend) SpecialPaths() *logical.Paths {
return b.PathsSpecial
}
// logical.Backend impl.
func (b *Backend) SetLogger(logger *log.Logger) {
b.logger = logger
}
// Logger can be used to get the logger. If no logger has been set,
// the logs will be discarded.
func (b *Backend) Logger() *log.Logger {
if b.logger != nil {
return b.logger
}
return log.New(ioutil.Discard, "", 0)
}
// Route looks up the path that would be used for a given path string.
func (b *Backend) Route(path string) *Path {
result, _ := b.route(path)