Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IPFS_* env vars back for transitionary release of go-log #67

Merged
merged 2 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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