Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to tweak default log level via ALMOND_LOG_LEVEL #1170

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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