mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-12-21 12:57:25 +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
@@ -4,17 +4,15 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"net/rpc"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/vault/helper/logformat"
|
||||
log "github.com/mgutz/logxi/v1"
|
||||
)
|
||||
"github.com/hashicorp/go-hclog"
|
||||
|
||||
func TestLogger_impl(t *testing.T) {
|
||||
var _ log.Logger = new(LoggerClient)
|
||||
}
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/vault/helper/logging"
|
||||
)
|
||||
|
||||
func TestLogger_levels(t *testing.T) {
|
||||
client, server := plugin.TestRPCConn(t)
|
||||
@@ -23,14 +21,14 @@ func TestLogger_levels(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
writer := bufio.NewWriter(&buf)
|
||||
|
||||
l := logformat.NewVaultLoggerWithWriter(writer, log.LevelTrace)
|
||||
l := logging.NewVaultLoggerWithWriter(writer, hclog.Trace)
|
||||
|
||||
server.RegisterName("Plugin", &LoggerServer{
|
||||
logger: l,
|
||||
})
|
||||
|
||||
expected := "foobar"
|
||||
testLogger := &LoggerClient{client: client}
|
||||
testLogger := &deprecatedLoggerClient{client: client}
|
||||
|
||||
// Test trace
|
||||
testLogger.Trace(expected)
|
||||
@@ -103,13 +101,13 @@ func TestLogger_isLevels(t *testing.T) {
|
||||
client, server := plugin.TestRPCConn(t)
|
||||
defer client.Close()
|
||||
|
||||
l := logformat.NewVaultLoggerWithWriter(ioutil.Discard, log.LevelAll)
|
||||
l := logging.NewVaultLoggerWithWriter(ioutil.Discard, hclog.Trace)
|
||||
|
||||
server.RegisterName("Plugin", &LoggerServer{
|
||||
logger: l,
|
||||
})
|
||||
|
||||
testLogger := &LoggerClient{client: client}
|
||||
testLogger := &deprecatedLoggerClient{client: client}
|
||||
|
||||
if !testLogger.IsDebug() || !testLogger.IsInfo() || !testLogger.IsTrace() || !testLogger.IsWarn() {
|
||||
t.Fatal("expected logger to return true for all logger level checks")
|
||||
@@ -123,17 +121,17 @@ func TestLogger_log(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
writer := bufio.NewWriter(&buf)
|
||||
|
||||
l := logformat.NewVaultLoggerWithWriter(writer, log.LevelTrace)
|
||||
l := logging.NewVaultLoggerWithWriter(writer, hclog.Trace)
|
||||
|
||||
server.RegisterName("Plugin", &LoggerServer{
|
||||
logger: l,
|
||||
})
|
||||
|
||||
expected := "foobar"
|
||||
testLogger := &LoggerClient{client: client}
|
||||
testLogger := &deprecatedLoggerClient{client: client}
|
||||
|
||||
// Test trace
|
||||
testLogger.Log(log.LevelInfo, expected, nil)
|
||||
// Test trace 6 = logxi.LevelInfo
|
||||
testLogger.Log(6, expected, nil)
|
||||
if err := writer.Flush(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -148,16 +146,117 @@ func TestLogger_setLevel(t *testing.T) {
|
||||
client, server := plugin.TestRPCConn(t)
|
||||
defer client.Close()
|
||||
|
||||
l := log.NewLogger(ioutil.Discard, "test-logger")
|
||||
l := hclog.New(&hclog.LoggerOptions{Output: ioutil.Discard})
|
||||
|
||||
server.RegisterName("Plugin", &LoggerServer{
|
||||
logger: l,
|
||||
})
|
||||
|
||||
testLogger := &LoggerClient{client: client}
|
||||
testLogger.SetLevel(log.LevelWarn)
|
||||
testLogger := &deprecatedLoggerClient{client: client}
|
||||
testLogger.SetLevel(4) // 4 == logxi.LevelWarn
|
||||
|
||||
if !testLogger.IsWarn() {
|
||||
t.Fatal("expected logger to support warn level")
|
||||
}
|
||||
}
|
||||
|
||||
type deprecatedLoggerClient struct {
|
||||
client *rpc.Client
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) Trace(msg string, args ...interface{}) {
|
||||
cArgs := &LoggerArgs{
|
||||
Msg: msg,
|
||||
Args: args,
|
||||
}
|
||||
l.client.Call("Plugin.Trace", cArgs, &struct{}{})
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) Debug(msg string, args ...interface{}) {
|
||||
cArgs := &LoggerArgs{
|
||||
Msg: msg,
|
||||
Args: args,
|
||||
}
|
||||
l.client.Call("Plugin.Debug", cArgs, &struct{}{})
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) Info(msg string, args ...interface{}) {
|
||||
cArgs := &LoggerArgs{
|
||||
Msg: msg,
|
||||
Args: args,
|
||||
}
|
||||
l.client.Call("Plugin.Info", cArgs, &struct{}{})
|
||||
}
|
||||
func (l *deprecatedLoggerClient) Warn(msg string, args ...interface{}) error {
|
||||
var reply LoggerReply
|
||||
cArgs := &LoggerArgs{
|
||||
Msg: msg,
|
||||
Args: args,
|
||||
}
|
||||
err := l.client.Call("Plugin.Warn", cArgs, &reply)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if reply.Error != nil {
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (l *deprecatedLoggerClient) Error(msg string, args ...interface{}) error {
|
||||
var reply LoggerReply
|
||||
cArgs := &LoggerArgs{
|
||||
Msg: msg,
|
||||
Args: args,
|
||||
}
|
||||
err := l.client.Call("Plugin.Error", cArgs, &reply)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if reply.Error != nil {
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) Fatal(msg string, args ...interface{}) {
|
||||
// NOOP since it's not actually used within vault
|
||||
return
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) Log(level int, msg string, args []interface{}) {
|
||||
cArgs := &LoggerArgs{
|
||||
Level: level,
|
||||
Msg: msg,
|
||||
Args: args,
|
||||
}
|
||||
l.client.Call("Plugin.Log", cArgs, &struct{}{})
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) SetLevel(level int) {
|
||||
l.client.Call("Plugin.SetLevel", level, &struct{}{})
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) IsTrace() bool {
|
||||
var reply LoggerReply
|
||||
l.client.Call("Plugin.IsTrace", new(interface{}), &reply)
|
||||
return reply.IsTrue
|
||||
}
|
||||
func (l *deprecatedLoggerClient) IsDebug() bool {
|
||||
var reply LoggerReply
|
||||
l.client.Call("Plugin.IsDebug", new(interface{}), &reply)
|
||||
return reply.IsTrue
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) IsInfo() bool {
|
||||
var reply LoggerReply
|
||||
l.client.Call("Plugin.IsInfo", new(interface{}), &reply)
|
||||
return reply.IsTrue
|
||||
}
|
||||
|
||||
func (l *deprecatedLoggerClient) IsWarn() bool {
|
||||
var reply LoggerReply
|
||||
l.client.Call("Plugin.IsWarn", new(interface{}), &reply)
|
||||
return reply.IsTrue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user