Skip to content

Commit

Permalink
airspec (feature): Support setting a log level with -L(package)=(leve…
Browse files Browse the repository at this point in the history
…l) option (#3332)

Closes #3305
  • Loading branch information
xerial authored Jan 10, 2024
1 parent 35c8e1f commit 09216b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 12 additions & 0 deletions airspec/src/main/scala/wvlet/airspec/runner/AirSpecSbtRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ private[airspec] class AirSpecSbtRunner(config: AirSpecConfig, val remoteArgs: A

private[airspec] object AirSpecSbtRunner extends LogSupport {
def newRunner(args: Array[String], remoteArgs: Array[String], testClassLoader: ClassLoader): AirSpecSbtRunner = {

// Set log levels given in the command line args: -L(package)=(log level)
args.filter(_.startsWith("-L")).foreach { l =>
l.stripPrefix("-L").split("=") match {
case Array(pkg, level) =>
val logLevel = wvlet.log.LogLevel(level)
wvlet.log.Logger(pkg).setLogLevel(logLevel)
case _ =>
warn(s"Ignoring invalid argument: ${l}. Use -L(package)=(log level) to set log levels")
}
}

new AirSpecSbtRunner(AirSpecConfig(args), remoteArgs, testClassLoader)
}

Expand Down
16 changes: 15 additions & 1 deletion docs/airspec.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ $ sbt
> testOnly -- (pattern) # Run all test matching the pattern
> testOnly -- (pattern)/(pattern) # Run nested tests matching the nested pattern (/ is a dlimiter)

# Configure log levels of airframe-log
> testOnly -- -L(package):(level) # Set log level for a package

# sbt's default test functionalities:
> testQuick # Run only previously failed test specs
> testOnly (class name) # Run tests only in specific classes matching a pattern (wildcard is supported)
Expand All @@ -187,6 +190,16 @@ Test names will be checked as case-insensitive partial match, so you only need t

![image](https://wvlet.org/airframe/img/airspec/airspec.png)

### Configure Log Levels

AirSpec natively supports [airframe-log](https://wvlet.org/airframe/docs/airframe-log.html) for logging. To temporally change the log level of your test classes, use `-L` option:

```scala
> testOnly -- -Lorg.mydomain.myapp:debug
```
You can use multiple `-L` options to set different log levels for multiple packages.


### Disable Parallel Test Execution

sbt 1.x or higher runs tests in parallel. This is fast, but it messes up console log messages.
Expand All @@ -195,7 +208,8 @@ If you prefer sequential test execution, set `parallelExecution in Test` to fals
```scala
parallelExecution in Test := false
```



## Running Tests with scala-cli

For quickly writing tests, you can use [scala-cli](https://scala-cli.virtuslab.org/docs/commands/test). Add AirSpec configurations with `//> using` directive as follows:
Expand Down

0 comments on commit 09216b1

Please sign in to comment.