diff --git a/airspec/src/main/scala/wvlet/airspec/runner/AirSpecSbtRunner.scala b/airspec/src/main/scala/wvlet/airspec/runner/AirSpecSbtRunner.scala index 6697c9aeb..061c05133 100644 --- a/airspec/src/main/scala/wvlet/airspec/runner/AirSpecSbtRunner.scala +++ b/airspec/src/main/scala/wvlet/airspec/runner/AirSpecSbtRunner.scala @@ -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() diff --git a/docs/airspec.md b/docs/airspec.md index 5e50e7d2a..53a44b7c7 100644 --- a/docs/airspec.md +++ b/docs/airspec.md @@ -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 @@ -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