Skip to content

Commit 62ce2c2

Browse files
committed
Change logging system
1 parent faf3ecc commit 62ce2c2

File tree

6 files changed

+22
-96
lines changed

6 files changed

+22
-96
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,4 @@ In scala-native-cli their value is defined as follows:
3333

3434
## Logging
3535

36-
For logging purposes, a default Scala Native logger is used. It is possible to specify which messages to log by filtering out the unnecessary ones with the following options:
37-
38-
* `--disable-debug`
39-
* `--disable-info`
40-
* `--disable-warn`
41-
* `--disable-error`
36+
For logging purposes, a default Scala Native logger is used. By default it will only show `Error` messages, but its verbosity can be increased with a -v flag.

cli/src/main/scala/scala/scalanative/cli/options/LoggerOptions.scala

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,9 @@ import caseapp._
44

55
case class LoggerOptions(
66
@Group("Logger")
7+
@ExtraName("v")
78
@HelpMessage(
8-
"Filter out `debug` logs from the default Scala Native logger. [false]"
9+
"Increase verbosity of internal logger. Can be specified multiple times."
910
)
10-
disableDebug: Boolean = false,
11-
@Group("Logger")
12-
@HelpMessage(
13-
"Filter out `info` logs from the default Scala Native logger. [false]"
14-
)
15-
disableInfo: Boolean = false,
16-
@Group("Logger")
17-
@HelpMessage(
18-
"Filter out `warn` logs from the default Scala Native logger. [false]"
19-
)
20-
disableWarn: Boolean = false,
21-
@Group("Logger")
22-
@HelpMessage(
23-
"Filter out `error` logs from the default Scala Native logger. [false]"
24-
)
25-
disableError: Boolean = false
11+
verbose: Int @@ Counter = Tag.of(0)
2612
)

cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.nio.file.Paths
77
import java.nio.file.Path
88
import scala.util.Try
99
import scala.scalanative.cli.options.CliOptions
10+
import caseapp.Tag
1011

1112
case class BuildOptions(
1213
config: Config,
@@ -86,13 +87,9 @@ object ConfigConverter {
8687
.withCompilerConfig(nativeConfig)
8788
.withClassPath(classPath)
8889
.withMainClass(main)
89-
val logger =
90-
new FilteredLogger(
91-
logDebug = !options.logger.disableDebug,
92-
logInfo = !options.logger.disableInfo,
93-
logWarn = !options.logger.disableWarn,
94-
logError = !options.logger.disableError
95-
)
90+
91+
val verbosity = Tag.unwrap(options.logger.verbose)
92+
val logger = new FilteredLogger(verbosity)
9693
config.withLogger(logger)
9794
}
9895
}

cli/src/main/scala/scala/scalanative/cli/utils/FilteredLogger.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@ package scala.scalanative.cli.utils
33
import scala.scalanative.build.Logger
44

55
class FilteredLogger(
6-
private val logDebug: Boolean,
7-
private val logInfo: Boolean,
8-
private val logWarn: Boolean,
9-
private val logError: Boolean
6+
private val verbosity: Int
107
) extends Logger {
118

129
private val underlying = Logger.default
1310

1411
override def trace(msg: Throwable): Unit = underlying.trace(msg)
1512
override def debug(msg: String): Unit =
16-
if (logDebug) underlying.debug(msg)
13+
if (verbosity >= 3) underlying.debug(msg)
1714
override def info(msg: String): Unit =
18-
if (logInfo) underlying.info(msg)
15+
if (verbosity >= 2) underlying.info(msg)
1916
override def warn(msg: String): Unit =
20-
if (logWarn) underlying.warn(msg)
17+
if (verbosity >= 1) underlying.warn(msg)
2118
override def error(msg: String): Unit =
22-
if (logError) underlying.error(msg)
19+
underlying.error(msg)
2320

2421
override def equals(other: Any): Boolean = {
2522
if (other.isInstanceOf[FilteredLogger]) {
2623
val that = other.asInstanceOf[FilteredLogger]
27-
this.logDebug == that.logDebug && this.logInfo == that.logInfo && this.logWarn == that.logWarn && this.logError == that.logError
24+
this.verbosity == that.verbosity
2825
} else {
2926
false
3027
}

cli/src/test/scala/scala/scalanative/cli/ConfigConverterTest.scala

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ConfigConverterTest extends AnyFlatSpec {
2020
val dummyArguments =
2121
Seq("$Main", "A.nir", "B.nir")
2222

23-
val dummyCliOptions: CliOptions = CliOptions(
23+
val dummyCliOptions = CliOptions(
2424
config = dummyConfigOptions,
2525
nativeConfig = dummyNativeConfigOptions,
2626
logger = dummyLoggerOptions
@@ -118,55 +118,6 @@ class ConfigConverterTest extends AnyFlatSpec {
118118
ltoAssertion("full", LTO.full)
119119
}
120120

121-
// it should "parse log level options correctly" in {
122-
// def logLevelAssertion(
123-
// logLevelOptions: Array[String],
124-
// expectedLogger: FilteredLogger
125-
// ) = {
126-
// val options = dummyOptions ++ logLevelOptions
127-
128-
// val obtained = BuildOptionsParser(options).right.get.get.config
129-
// assert(obtained.logger == expectedLogger)
130-
// }
131-
132-
// logLevelAssertion(
133-
// Array("--disable-error"),
134-
// new FilteredLogger(
135-
// logDebug = true,
136-
// logInfo = true,
137-
// logWarn = true,
138-
// logError = false
139-
// )
140-
// )
141-
// logLevelAssertion(
142-
// Array("--disable-warn"),
143-
// new FilteredLogger(
144-
// logDebug = true,
145-
// logInfo = true,
146-
// logWarn = false,
147-
// logError = true
148-
// )
149-
// )
150-
// logLevelAssertion(
151-
// Array("--disable-info"),
152-
// new FilteredLogger(
153-
// logDebug = true,
154-
// logInfo = false,
155-
// logWarn = true,
156-
// logError = true
157-
// )
158-
// )
159-
// logLevelAssertion(
160-
// Array("--disable-debug"),
161-
// new FilteredLogger(
162-
// logDebug = false,
163-
// logInfo = true,
164-
// logWarn = true,
165-
// logError = true
166-
// )
167-
// )
168-
// }
169-
170121
it should "set clang and clang++ correctly" in {
171122
val clangString = "/tmp/clang"
172123
val clangPPString = "tmp/clang++"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
> compile
22
# -- Link and check if outpath exists
3-
> runTest --outpath target/out1 --disable-debug Main$
3+
> runTest --outpath target/out1 -v -v Main$
44
$ exists target/out1
55

66
# -- Fail to link without main specified
7-
> runTest --outpath target/out2 --disable-debug
7+
> runTest --outpath target/out2 -v -v
88
-$ exists target/out2
99

1010
# -- Fail to link with an incorrect option
11-
> runTest --outpath target/out3 --disable-debug --gc fast Main$
11+
> runTest --outpath target/out3 -v -v --gc fast Main$
1212
-$ exists target/out3
1313

1414
# -- Fail to link with an unspecified option
15-
> runTest --outpath target/out4 --disable-debug --unspecified Main$
15+
> runTest --outpath target/out4 -v -v --unspecified Main$
1616
-$ exists target/out4
1717

1818
# -- Do not write nir files if not specified
19-
> runTest --outpath target/out5 --disable-debug Main$
19+
> runTest --outpath target/out5 -v -v Main$
2020
-$ exists optimized.hnir
2121
$ exists target/out5
2222

2323
# -- Write nir files to workdir if specified
2424
$ mkdir native-dir
25-
> runTest --outpath target/out6 --disable-debug --workdir native-dir --dump Main$
25+
> runTest --outpath target/out6 -v -v --workdir native-dir --dump Main$
2626
$ exists native-dir/optimized.hnir
2727
$ exists target/out6
2828

2929
# -- Fail on an incorrect link-time property
30-
> runTest --outpath target/out7 --disable-debug --ltp key=ok Main$
30+
> runTest --outpath target/out7 -v -v --ltp key=ok Main$
3131
-$ exists target/out7

0 commit comments

Comments
 (0)