Skip to content

Commit f35a3b7

Browse files
Send logging to stderr (#25)
As scala-native-cli may be launched as a sub-process by other tools, what it prints to stdout might pollute what the other tool is sending to stdout. Better send its log messages to stderr straightaway.
1 parent dc09218 commit f35a3b7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ object ScalaNativeLd {
5353
case _: BuildTarget.Library => false
5454
}
5555
if (needsMain && options.config.main.isEmpty) {
56-
println("Required option not specified: --main")
56+
System.err.println("Required option not specified: --main")
5757
sys.exit(1)
5858
} else {
5959
val (ignoredArgs, classpath) =
6060
options.classpath.partition(_.startsWith("-"))
6161
ignoredArgs.foreach { arg =>
62-
println(s"Unrecognised argument: ${arg}")
62+
System.err.println(s"Unrecognised argument: ${arg}")
6363
}
6464
val main = options.config.main
6565
val buildOptionsMaybe = ConfigConverter.convert(options, main, classpath)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
package scala.scalanative.cli.utils
22

3+
import java.lang.System.err
4+
35
import scala.scalanative.build.Logger
46

57
class FilteredLogger(
68
private val verbosity: Int
79
) extends Logger {
810

9-
private val underlying = Logger.default
11+
private val underlying: Logger =
12+
// Like Logger.default, but sending everything to stderr
13+
new Logger {
14+
def trace(msg: Throwable): Unit = err.println(s"[trace] $msg")
15+
def debug(msg: String): Unit = err.println(s"[debug] $msg")
16+
def info(msg: String): Unit = err.println(s"[info] $msg")
17+
def warn(msg: String): Unit = err.println(s"[warn] $msg")
18+
def error(msg: String): Unit = err.println(s"[error] $msg")
19+
}
1020

1121
override def trace(msg: Throwable): Unit = underlying.trace(msg)
1222
override def debug(msg: String): Unit =

0 commit comments

Comments
 (0)