Skip to content

Commit

Permalink
Allow users to tweak default log level via ALMOND_LOG_LEVEL (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Jun 29, 2023
1 parent 61e92f0 commit 7898655
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final case class Options(
@HelpMessage("Enable Maven profile (start with ! to disable)")
profile: List[String] = Nil,
@HelpMessage("Log level (one of none, error, warn, info, debug)")
log: String = "warn",
log: Option[String] = None,
@HelpMessage("Send log to a file rather than stderr")
@ValueDescription("/path/to/log-file")
logTo: Option[String] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@ object ScalaKernel extends CaseApp[Options] {
// Enable ANSI output in Windows terminal
coursier.jniutils.WindowsAnsiTerminal.enableAnsiOutput()

val logCtx = Level.fromString(options.log) match {
def logLevelFromEnv =
Option(System.getenv("ALMOND_LOG_LEVEL")).flatMap { str =>
Level.fromString(str) match {
case Left(err) =>
Console.err.println(
s"Error parsing log level from environment variable ALMOND_LOG_LEVEL: $err, ignoring it"
)
None
case other =>
Some(other)
}
}
val maybeLogLevel = options.log
.map(Level.fromString)
.orElse(logLevelFromEnv)
.getOrElse(Right(Level.Warning))
val logCtx = maybeLogLevel match {
case Left(err) =>
Console.err.println(err)
sys.exit(1)
Expand Down

0 comments on commit 7898655

Please sign in to comment.