Skip to content

Commit

Permalink
Merge pull request #67 from ipfs/fix/make-env-vars-backwards-compat
Browse files Browse the repository at this point in the history
add IPFS_* env vars back for transitionary release of go-log
  • Loading branch information
lanzafame committed Nov 21, 2019
2 parents a609c1a + 9ce8380 commit 5b376b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ require (
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0
)

go 1.12
22 changes: 19 additions & 3 deletions oldlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func init() {

// Logging environment variables
const (
// IPFS_* prefixed env vars kept for backwards compatibility
// for this release. They will not be available in the next
// release.
//
// GOLOG_* env vars take precedences over IPFS_* env vars.
envIPFSLogging = "IPFS_LOGGING"
envIPFSLoggingFmt = "IPFS_LOGGING_FMT"

envLogging = "GOLOG_LOG_LEVEL"
envLoggingFmt = "GOLOG_LOG_FMT"

Expand All @@ -44,9 +52,12 @@ var levels = make(map[string]zap.AtomicLevel)
var zapCfg = zap.NewProductionConfig()

func SetupLogging() {

loggingFmt := os.Getenv(envLoggingFmt)
if loggingFmt == "" {
loggingFmt = os.Getenv(envIPFSLoggingFmt)
}
// colorful or plain
switch os.Getenv(envLoggingFmt) {
switch loggingFmt {
case "nocolor":
zapCfg.Encoding = "console"
zapCfg.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
Expand All @@ -69,7 +80,12 @@ func SetupLogging() {
// set the backend(s)
lvl := LevelError

if logenv := os.Getenv(envLogging); logenv != "" {
logenv := os.Getenv(envLogging)
if logenv == "" {
logenv = os.Getenv(envIPFSLogging)
}

if logenv != "" {
var err error
lvl, err = LevelFromString(logenv)
if err != nil {
Expand Down

0 comments on commit 5b376b4

Please sign in to comment.