Skip to content

Commit

Permalink
adjust env vars, add regex based level setting
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Sep 19, 2019
1 parent 62f287c commit e926694
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions oldlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"regexp"
"sync"

tracer "github.com/ipfs/go-log/tracer"
Expand All @@ -21,10 +22,8 @@ func init() {

// Logging environment variables
const (
// TODO these env names should be more general, IPFS is not the only project to
// use go-log
envLogging = "IPFS_LOGGING"
envLoggingFmt = "IPFS_LOGGING_FMT"
envLogging = "GOLOG_LOG_LEVEL"
envLoggingFmt = "GOLOG_LOG_FMT"

envLoggingFile = "GOLOG_FILE" // /path/to/file
envTracingFile = "GOLOG_TRACING_FILE" // /path/to/file
Expand Down Expand Up @@ -139,6 +138,29 @@ func SetLogLevel(name, level string) error {
return nil
}

// SetLogLevelRegex sets all loggers to level `l` that match expression `e`.
// An error is returned if `e` fails to compile.
func SetLogLevelRegex(e, l string) error {
lvl, err := LevelFromString(l)
if err != nil {
return err
}

rem, err := regexp.Compile(e)
if err != nil {
return err
}

loggerMutex.Lock()
defer loggerMutex.Unlock()
for name := range loggers {
if rem.MatchString(name) {
levels[name].SetLevel(zapcore.Level(lvl))
}
}
return nil
}

// GetSubsystems returns a slice containing the
// names of the current loggers
func GetSubsystems() []string {
Expand Down

0 comments on commit e926694

Please sign in to comment.