mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 03:58:01 +00:00
Move to "github.com/hashicorp/go-hclog" (#4227)
* logbridge with hclog and identical output * Initial search & replace This compiles, but there is a fair amount of TODO and commented out code, especially around the plugin logclient/logserver code. * strip logbridge * fix majority of tests * update logxi aliases * WIP fixing tests * more test fixes * Update test to hclog * Fix format * Rename hclog -> log * WIP making hclog and logxi love each other * update logger_test.go * clean up merged comments * Replace RawLogger interface with a Logger * Add some logger names * Replace Trace with Debug * update builtin logical logging patterns * Fix build errors * More log updates * update log approach in command and builtin * More log updates * update helper, http, and logical directories * Update loggers * Log updates * Update logging * Update logging * Update logging * Update logging * update logging in physical * prefixing and lowercase * Update logging * Move phyisical logging name to server command * Fix som tests * address jims feedback so far * incorporate brians feedback so far * strip comments * move vault.go to logging package * update Debug to Trace * Update go-plugin deps * Update logging based on review comments * Updates from review * Unvendor logxi * Remove null_logger.go
This commit is contained in:
committed by
Brian Kassouf
parent
ecdd877bf4
commit
792d219aa9
@@ -21,7 +21,6 @@ import (
|
||||
"time"
|
||||
|
||||
colorable "github.com/mattn/go-colorable"
|
||||
log "github.com/mgutz/logxi/v1"
|
||||
"github.com/mitchellh/cli"
|
||||
testing "github.com/mitchellh/go-testing-interface"
|
||||
"github.com/posener/complete"
|
||||
@@ -32,13 +31,12 @@ import (
|
||||
"github.com/armon/go-metrics/circonus"
|
||||
"github.com/armon/go-metrics/datadog"
|
||||
"github.com/hashicorp/errwrap"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/vault/audit"
|
||||
"github.com/hashicorp/vault/command/server"
|
||||
"github.com/hashicorp/vault/helper/gated-writer"
|
||||
"github.com/hashicorp/vault/helper/logbridge"
|
||||
"github.com/hashicorp/vault/helper/logformat"
|
||||
"github.com/hashicorp/vault/helper/logging"
|
||||
"github.com/hashicorp/vault/helper/mlock"
|
||||
"github.com/hashicorp/vault/helper/parseutil"
|
||||
"github.com/hashicorp/vault/helper/reload"
|
||||
@@ -288,21 +286,19 @@ func (c *ServerCommand) Run(args []string) int {
|
||||
// Create a logger. We wrap it in a gated writer so that it doesn't
|
||||
// start logging too early.
|
||||
c.logGate = &gatedwriter.Writer{Writer: colorable.NewColorable(os.Stderr)}
|
||||
var level int
|
||||
var level log.Level
|
||||
c.flagLogLevel = strings.ToLower(strings.TrimSpace(c.flagLogLevel))
|
||||
switch c.flagLogLevel {
|
||||
case "trace":
|
||||
level = log.LevelTrace
|
||||
level = log.Trace
|
||||
case "debug":
|
||||
level = log.LevelDebug
|
||||
case "info", "":
|
||||
level = log.LevelInfo
|
||||
case "notice":
|
||||
level = log.LevelNotice
|
||||
level = log.Debug
|
||||
case "notice", "info", "":
|
||||
level = log.Info
|
||||
case "warn", "warning":
|
||||
level = log.LevelWarn
|
||||
level = log.Warn
|
||||
case "err", "error":
|
||||
level = log.LevelError
|
||||
level = log.Error
|
||||
default:
|
||||
c.UI.Error(fmt.Sprintf("Unknown log level: %s", c.flagLogLevel))
|
||||
return 1
|
||||
@@ -315,20 +311,20 @@ func (c *ServerCommand) Run(args []string) int {
|
||||
switch strings.ToLower(logFormat) {
|
||||
case "vault", "vault_json", "vault-json", "vaultjson", "json", "":
|
||||
if c.flagDevThreeNode || c.flagDevFourCluster {
|
||||
c.logger = logbridge.NewLogger(hclog.New(&hclog.LoggerOptions{
|
||||
c.logger = log.New(&log.LoggerOptions{
|
||||
Mutex: &sync.Mutex{},
|
||||
Output: c.logGate,
|
||||
Level: hclog.Trace,
|
||||
})).LogxiLogger()
|
||||
Level: log.Trace,
|
||||
})
|
||||
} else {
|
||||
c.logger = logformat.NewVaultLoggerWithWriter(c.logGate, level)
|
||||
c.logger = logging.NewVaultLoggerWithWriter(c.logGate, level)
|
||||
}
|
||||
default:
|
||||
c.logger = log.NewLogger(c.logGate, "vault")
|
||||
c.logger.SetLevel(level)
|
||||
c.logger = logging.NewVaultLoggerWithWriter(c.logGate, level)
|
||||
}
|
||||
|
||||
grpclog.SetLogger(&grpclogFaker{
|
||||
logger: c.logger,
|
||||
logger: c.logger.Named("grpclogfaker"),
|
||||
log: os.Getenv("VAULT_GRPC_LOGGING") != "",
|
||||
})
|
||||
|
||||
@@ -412,7 +408,7 @@ func (c *ServerCommand) Run(args []string) int {
|
||||
c.UI.Error(fmt.Sprintf("Unknown storage type %s", config.Storage.Type))
|
||||
return 1
|
||||
}
|
||||
backend, err := factory(config.Storage.Config, c.logger)
|
||||
backend, err := factory(config.Storage.Config, c.logger.ResetNamed("storage."+config.Storage.Type))
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error initializing storage of type %s: %s", config.Storage.Type, err))
|
||||
return 1
|
||||
@@ -718,8 +714,8 @@ CLUSTER_SYNTHESIS_COMPLETE:
|
||||
}
|
||||
c.reloadFuncsLock.Unlock()
|
||||
if !disableClustering {
|
||||
if c.logger.IsTrace() {
|
||||
c.logger.Trace("cluster listener addresses synthesized", "cluster_addresses", clusterAddrs)
|
||||
if c.logger.IsDebug() {
|
||||
c.logger.Debug("cluster listener addresses synthesized", "cluster_addresses", clusterAddrs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1095,7 +1091,7 @@ func (c *ServerCommand) enableThreeNodeDevCluster(base *vault.CoreConfig, info m
|
||||
testCluster := vault.NewTestCluster(&testing.RuntimeT{}, base, &vault.TestClusterOptions{
|
||||
HandlerFunc: vaulthttp.Handler,
|
||||
BaseListenAddress: c.flagDevListenAddr,
|
||||
RawLogger: c.logger,
|
||||
Logger: c.logger,
|
||||
TempDir: tempDir,
|
||||
})
|
||||
defer c.cleanupGuard.Do(testCluster.Cleanup)
|
||||
@@ -1577,19 +1573,19 @@ func (g *grpclogFaker) Fatalln(args ...interface{}) {
|
||||
}
|
||||
|
||||
func (g *grpclogFaker) Print(args ...interface{}) {
|
||||
if g.log && g.logger.IsTrace() {
|
||||
g.logger.Trace(fmt.Sprint(args...))
|
||||
if g.log && g.logger.IsDebug() {
|
||||
g.logger.Debug(fmt.Sprint(args...))
|
||||
}
|
||||
}
|
||||
|
||||
func (g *grpclogFaker) Printf(format string, args ...interface{}) {
|
||||
if g.log && g.logger.IsTrace() {
|
||||
g.logger.Trace(fmt.Sprintf(format, args...))
|
||||
if g.log && g.logger.IsDebug() {
|
||||
g.logger.Debug(fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
func (g *grpclogFaker) Println(args ...interface{}) {
|
||||
if g.log && g.logger.IsTrace() {
|
||||
g.logger.Trace(fmt.Sprintln(args...))
|
||||
if g.log && g.logger.IsDebug() {
|
||||
g.logger.Debug(fmt.Sprintln(args...))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user