-
Notifications
You must be signed in to change notification settings - Fork 42
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 #426 from outr/level-filtering-fixes
Began testing of level filtering
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 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
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
64 changes: 64 additions & 0 deletions
64
core/shared/src/test/scala/specs/LoggingLevelFilteringSpec.scala
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,64 @@ | ||
package specs | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import scribe.filter._ | ||
import scribe.{Level, Logger} | ||
import scribe.writer.CacheWriter | ||
|
||
class LoggingLevelFilteringSpec extends AnyWordSpec with Matchers { | ||
private lazy val errorWriter = new CacheWriter() | ||
private lazy val traceWriter = new CacheWriter() | ||
private lazy val debugWriter = new CacheWriter() | ||
|
||
private val pkg1 = "specs" | ||
private val pkg2 = "com.foo" | ||
|
||
"Logging Level Filtering" should { | ||
"configure the loggers" in { | ||
Logger.reset() | ||
Logger.root | ||
.clearHandlers() | ||
.withMinimumLevel(Level.Info) | ||
.withHandler(writer = errorWriter, minimumLevel = Some(Level.Error)) | ||
.withHandler( | ||
writer = traceWriter, | ||
modifiers = List( | ||
select(packageName(pkg1), packageName(pkg2)) | ||
.include(level === Level.Trace) | ||
.excludeUnselected | ||
) | ||
) | ||
.withHandler(writer = debugWriter, minimumLevel = Some(Level.Debug)) | ||
.replace() | ||
Logger(pkg1).withMinimumLevel(Level.Trace).replace() | ||
} | ||
"verify an error gets logged" in { | ||
scribe.error("Error1") | ||
errorWriter.consumeMessages { list => | ||
list should be(List("Error1")) | ||
} | ||
traceWriter.consumeMessages { list => | ||
list should be(Nil) | ||
} | ||
debugWriter.consumeMessages { list => | ||
list should be(List("Error1")) | ||
} | ||
} | ||
"verify a trace message gets logged" in { | ||
scribe.trace("Trace1") | ||
errorWriter.consumeMessages { list => | ||
list should be(Nil) | ||
} | ||
traceWriter.consumeMessages { list => | ||
list should be(List("Trace1")) | ||
} | ||
debugWriter.consumeMessages { list => | ||
list should be(Nil) | ||
} | ||
} | ||
"reset the root logger" in { | ||
Logger.root.reset() | ||
} | ||
} | ||
} |