Skip to content

Commit 5b376b4

Browse files
authored
Merge pull request #67 from ipfs/fix/make-env-vars-backwards-compat
add IPFS_* env vars back for transitionary release of go-log
2 parents a609c1a + 9ce8380 commit 5b376b4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ require (
99
go.uber.org/multierr v1.1.0 // indirect
1010
go.uber.org/zap v1.10.0
1111
)
12+
13+
go 1.12

oldlog.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ func init() {
2222

2323
// Logging environment variables
2424
const (
25+
// IPFS_* prefixed env vars kept for backwards compatibility
26+
// for this release. They will not be available in the next
27+
// release.
28+
//
29+
// GOLOG_* env vars take precedences over IPFS_* env vars.
30+
envIPFSLogging = "IPFS_LOGGING"
31+
envIPFSLoggingFmt = "IPFS_LOGGING_FMT"
32+
2533
envLogging = "GOLOG_LOG_LEVEL"
2634
envLoggingFmt = "GOLOG_LOG_FMT"
2735

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

4654
func SetupLogging() {
47-
55+
loggingFmt := os.Getenv(envLoggingFmt)
56+
if loggingFmt == "" {
57+
loggingFmt = os.Getenv(envIPFSLoggingFmt)
58+
}
4859
// colorful or plain
49-
switch os.Getenv(envLoggingFmt) {
60+
switch loggingFmt {
5061
case "nocolor":
5162
zapCfg.Encoding = "console"
5263
zapCfg.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
@@ -69,7 +80,12 @@ func SetupLogging() {
6980
// set the backend(s)
7081
lvl := LevelError
7182

72-
if logenv := os.Getenv(envLogging); logenv != "" {
83+
logenv := os.Getenv(envLogging)
84+
if logenv == "" {
85+
logenv = os.Getenv(envIPFSLogging)
86+
}
87+
88+
if logenv != "" {
7389
var err error
7490
lvl, err = LevelFromString(logenv)
7591
if err != nil {

0 commit comments

Comments
 (0)