Skip to content

Commit

Permalink
airspec (deprecated): Require a space in -L (pattern)=(loglevel) opti…
Browse files Browse the repository at this point in the history
…on (#3631)

Closes #3617
  • Loading branch information
xerial authored Sep 9, 2024
1 parent cebf01f commit ce49e44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
27 changes: 21 additions & 6 deletions airspec/src/main/scala/wvlet/airspec/runner/AirSpecSbtRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,40 @@ private[airspec] object AirSpecSbtRunner extends LogSupport {
var i = 0
var logLevel: LogLevel = Logger.getDefaultLogLevel
val additionalLogLevels = Map.newBuilder[String, LogLevel]

def parseAdditionalLogLevel(s: String): Unit = {
s.split("=") match {
case Array(pkg, level) =>
additionalLogLevels += pkg -> LogLevel(level)
case _ =>
warn(s"Ignoring invalid argument: ${s}. Use -L (package)=(log level) to set log levels")
}
}

var warnings: Set[String] = Set.empty

while (i < args.length) {
args(i) match {
case "-l" if i < args.length - 1 =>
// Set the default log level for the test spec
logLevel = LogLevel(args(i + 1))
i += 1
case "-L" if i < args.length - 1 =>
parseAdditionalLogLevel(args(i + 1))
i += 1
case arg if arg.startsWith("-L") =>
arg.stripPrefix("-L").split("=") match {
case Array(pkg, level) =>
additionalLogLevels += pkg -> LogLevel(level)
case _ =>
warn(s"Ignoring invalid argument: ${arg}. Use -L(package)=(log level) to set log levels")
}
warnings += s"-L(package)=(log level) syntax is deprecated. Use -L (package)=(log level)"
parseAdditionalLogLevel(arg.stripPrefix("-L"))
case other =>
remaining += other
}
i += 1
}

if (warnings.nonEmpty) {
warn(warnings.mkString("\n"))
}

remainingArgs = remaining.result()
_defaultLogLevel = logLevel
_additionalLogLevels = additionalLogLevels.result()
Expand Down
10 changes: 5 additions & 5 deletions docs/airspec.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ $ sbt

# Configure log levels of airframe-log
> testOnly -- -l (level) # Set the log level for the test target classes
> testOnly -- -L(package)=(level) # Set log level for a specific package or class
> testOnly -- -L (package)=(level) # Set log level for a specific package or class

# sbt's default test functionalities:
> testQuick # Run only previously failed test specs
Expand Down Expand Up @@ -257,17 +257,17 @@ AirSpec natively supports [airframe-log](https://wvlet.org/airframe/docs/airfram
This will set the log level to debug for all test classes.


To change the log level only for a specific package or a class, use `-L(package or class)=(log level)` option:
To change the log level only for a specific package or a class, use `-L (package or class)=(log level)` option:

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

You can also use wildcard `*` with `-L` option for the ease of setting log levels for specific classes:
```scala
> testOnly -- -Lmyapp.*=debug
> testOnly -- -L*.MyClass=debug
> testOnly -- -L myapp.*=debug
> testOnly -- -L *.MyClass=debug
```

### Configure Log Levels in log-test.properties
Expand Down

0 comments on commit ce49e44

Please sign in to comment.