-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from ipfs/fix/log-level
Fix log level handling
- Loading branch information
Showing
3 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package log | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"testing" | ||
) | ||
|
||
func TestLogLevel(t *testing.T) { | ||
const subsystem = "log-level-test" | ||
logger := Logger(subsystem) | ||
reader := NewPipeReader() | ||
done := make(chan struct{}) | ||
go func() { | ||
defer close(done) | ||
decoder := json.NewDecoder(reader) | ||
for { | ||
var entry struct { | ||
Message string `json:"msg"` | ||
} | ||
err := decoder.Decode(&entry) | ||
switch err { | ||
default: | ||
t.Error(err) | ||
return | ||
case io.EOF: | ||
return | ||
case nil: | ||
} | ||
if entry.Message != "bar" { | ||
t.Errorf("unexpected message: %s", entry.Message) | ||
} | ||
} | ||
}() | ||
logger.Debugw("foo") | ||
SetLogLevel(subsystem, "debug") | ||
logger.Debugw("bar") | ||
SetAllLoggers(LevelInfo) | ||
logger.Debugw("baz") | ||
logger.Sync() | ||
reader.Close() | ||
<-done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters