Duplicate logging instead of using from shared secure libs, as it's going out of there and we'll be moving away from hclog anyways
This commit is contained in:
1 parent
5a70875726
commit
051fe60718
5 files changed
+78
-5
No files matched your search
@@ -34,7 +34,6 @@ require (
|
||||
github.com/hashicorp/hcl v1.0.0
|
||||
github.com/hashicorp/shared-secure-libs v0.0.7
|
||||
github.com/hashicorp/shared-secure-libs/base62 v0.1.0
|
||||
github.com/hashicorp/shared-secure-libs/logging v0.1.0
|
||||
github.com/hashicorp/shared-secure-libs/mlock v0.1.0
|
||||
github.com/hashicorp/shared-secure-libs/parseutil v0.1.0
|
||||
github.com/hashicorp/shared-secure-libs/password v0.1.0
|
||||
|
||||
@@ -524,8 +524,6 @@ github.com/hashicorp/shared-secure-libs v0.0.7 h1:vdoIg+ahLPlwTELM7eA4OWws54Hf0e
|
||||
github.com/hashicorp/shared-secure-libs v0.0.7/go.mod h1:PH51kNtHA6kYV5Z8E3TOJM634iyp7IIxAMfLh0Dp35o=
|
||||
github.com/hashicorp/shared-secure-libs/base62 v0.1.0 h1:MZpHgL9yms0DVhYJ+cVpQ5tp8IbyoVufyMvCi6stJnU=
|
||||
github.com/hashicorp/shared-secure-libs/base62 v0.1.0/go.mod h1:yQ1EUBxJZ654Ivhjmr1pq2wt6YCoeTCuZgX2Ysc4IMg=
|
||||
github.com/hashicorp/shared-secure-libs/logging v0.1.0 h1:a2FchfFIKU+jo0xWIjBGSA8n80af16CbvQAAcOlMejU=
|
||||
github.com/hashicorp/shared-secure-libs/logging v0.1.0/go.mod h1:ogsWOAtBzEu0YYDWKgdahFkmjnu8cKzQ+ejg5Ibm8L8=
|
||||
github.com/hashicorp/shared-secure-libs/mlock v0.1.0 h1:7xw1ZVNW41PGRiRysdA8SBaRN2bNE+Bf+Uce/+JWsu4=
|
||||
github.com/hashicorp/shared-secure-libs/mlock v0.1.0/go.mod h1:lOpv9YZPgTDtfSdhetd25YVO3uxRrD8KD0erct1PdP0=
|
||||
github.com/hashicorp/shared-secure-libs/parseutil v0.1.0 h1:R5IyN4zkqbxkPLhR7WSvF7Jhoc7AtlvlVK8QZKs8N9c=
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/cmd/base/logging"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/shared-secure-libs/logging"
|
||||
)
|
||||
|
||||
func ProcessLogLevelAndFormat(flagLogLevel, flagLogFormat, configLogLevel, configLogFormat string) (hclog.Level, logging.LogFormat, error) {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
type LogFormat int
|
||||
|
||||
const (
|
||||
UnspecifiedFormat LogFormat = iota
|
||||
StandardFormat
|
||||
JSONFormat
|
||||
)
|
||||
|
||||
// Stringer implementation
|
||||
func (l LogFormat) String() string {
|
||||
switch l {
|
||||
case UnspecifiedFormat:
|
||||
return "unspecified"
|
||||
case StandardFormat:
|
||||
return "standard"
|
||||
case JSONFormat:
|
||||
return "json"
|
||||
}
|
||||
|
||||
// unreachable
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// NewLogger creates a new logger with the specified level and a formatter
|
||||
func NewLogger(level log.Level) log.Logger {
|
||||
return NewLoggerWithWriter(log.DefaultOutput, level)
|
||||
}
|
||||
|
||||
// NewLoggerWithWriter creates a new logger with the specified level and
|
||||
// writer and a formatter
|
||||
func NewLoggerWithWriter(w io.Writer, level log.Level) log.Logger {
|
||||
opts := &log.LoggerOptions{
|
||||
Level: level,
|
||||
Output: w,
|
||||
JSONFormat: ParseEnvLogFormat() == JSONFormat,
|
||||
}
|
||||
return log.New(opts)
|
||||
}
|
||||
|
||||
// ParseLogFormat parses the log format from the provided string.
|
||||
func ParseLogFormat(format string) (LogFormat, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(format)) {
|
||||
case "":
|
||||
return UnspecifiedFormat, nil
|
||||
case "standard":
|
||||
return StandardFormat, nil
|
||||
case "json":
|
||||
return JSONFormat, nil
|
||||
default:
|
||||
return UnspecifiedFormat, fmt.Errorf("Unknown log format: %s", format)
|
||||
}
|
||||
}
|
||||
|
||||
// ParseEnvLogFormat parses the log format from an environment variable.
|
||||
func ParseEnvLogFormat() LogFormat {
|
||||
logFormat := os.Getenv("BOUNDARY_LOG_FORMAT")
|
||||
switch strings.ToLower(logFormat) {
|
||||
case "json":
|
||||
return JSONFormat
|
||||
case "standard":
|
||||
return StandardFormat
|
||||
default:
|
||||
return UnspecifiedFormat
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
berrors "github.com/hashicorp/boundary/internal/errors"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base/logging"
|
||||
"github.com/hashicorp/boundary/internal/cmd/config"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
@@ -33,7 +34,6 @@ import (
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/shared-secure-libs/configutil"
|
||||
"github.com/hashicorp/shared-secure-libs/gatedwriter"
|
||||
"github.com/hashicorp/shared-secure-libs/logging"
|
||||
"github.com/hashicorp/shared-secure-libs/mlock"
|
||||
"github.com/hashicorp/shared-secure-libs/reloadutil"
|
||||
"github.com/hashicorp/shared-secure-libs/strutil"
|
||||
|
||||
Reference in new issue
Block a user