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

Add def warn(s: String): Unit to Logger #4664

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions bsp/src/mill/bsp/BspContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private[mill] class BspContext(
}

override def info(s: String): Unit = streams.err.println(s)
override def warn(s: String): Unit = streams.err.println(s)
override def error(s: String): Unit = streams.err.println(s)
override def ticker(s: String): Unit = streams.err.println(s)

Expand Down
9 changes: 8 additions & 1 deletion core/api/src/mill/api/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ trait Logger {
*/
def debug(s: String): Unit

/**
* Prints logging output which represents warnings the user should care
* about
*/
def warn(s: String): Unit

/**
* Prints logging output which represents problems the user should care
* about
Expand Down Expand Up @@ -128,7 +134,7 @@ private[mill] object Logger {
private[mill] def enableTicker: Boolean

def infoColor: fansi.Attrs

def warnColor: fansi.Attrs
def errorColor: fansi.Attrs
def colored: Boolean
}
Expand All @@ -148,6 +154,7 @@ private[mill] object Logger {

def enableTicker: Boolean = false
def infoColor: fansi.Attrs = fansi.Attrs.Empty
def warnColor: fansi.Attrs = fansi.Attrs.Empty
def errorColor: fansi.Attrs = fansi.Attrs.Empty
def colored: Boolean = false
}
Expand Down
6 changes: 3 additions & 3 deletions core/internal/src/mill/internal/Colors.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.internal

private[mill] case class Colors(info: fansi.Attrs, error: fansi.Attrs)
private[mill] case class Colors(info: fansi.Attrs, warn: fansi.Attrs, error: fansi.Attrs)
private[mill] object Colors {
object Default extends Colors(fansi.Color.Blue, fansi.Color.Red)
object BlackWhite extends Colors(fansi.Attrs.Empty, fansi.Attrs.Empty)
object Default extends Colors(fansi.Color.Blue, fansi.Color.Yellow, fansi.Color.Red)
object BlackWhite extends Colors(fansi.Attrs.Empty, fansi.Attrs.Empty, fansi.Attrs.Empty)
}
1 change: 1 addition & 0 deletions core/internal/src/mill/internal/DummyLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private[mill] object DummyLogger extends Logger {
)

def info(s: String) = ()
def warn(s: String) = ()
def error(s: String) = ()
def ticker(s: String) = ()
def debug(s: String) = ()
Expand Down
1 change: 1 addition & 0 deletions core/internal/src/mill/internal/FileLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private[mill] class FileLogger(

val streams = new SystemStreams(fileStream, fileStream, mill.api.DummyInputStream)
def info(s: String): Unit = streams.out.println(s)
def warn(s: String): Unit = streams.out.println(s)
def error(s: String): Unit = streams.out.println(s)
def ticker(s: String): Unit = streams.out.println(s)
def debug(s: String): Unit = if (prompt.debugEnabled) streams.out.println(s)
Expand Down
6 changes: 5 additions & 1 deletion core/internal/src/mill/internal/MultiLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ private[mill] class MultiLogger(
logger1.info(s)
logger2.info(s)
}
def warn(s: String): Unit = {
logger1.warn(s)
logger2.warn(s)
}
def error(s: String): Unit = {
logger1.error(s)
logger2.error(s)
Expand Down Expand Up @@ -85,7 +89,7 @@ private[mill] class MultiLogger(
override def debugEnabled: Boolean = logger1.prompt.debugEnabled || logger2.prompt.debugEnabled

override def infoColor: Attrs = logger1.prompt.infoColor ++ logger2.prompt.infoColor

override def warnColor: Attrs = logger1.prompt.warnColor ++ logger2.prompt.warnColor
override def errorColor: Attrs = logger1.prompt.errorColor ++ logger2.prompt.errorColor
override def colored: Boolean = logger1.prompt.colored || logger2.prompt.colored
}
Expand Down
4 changes: 4 additions & 0 deletions core/internal/src/mill/internal/PrefixLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private[mill] class PrefixLogger(
prompt.reportKey(logKey)
logger0.info("" + prompt.infoColor(linePrefix) + s)
}
override def warn(s: String): Unit = {
prompt.reportKey(logKey)
logger0.warn("" + prompt.warnColor(linePrefix) + s)
}
override def error(s: String): Unit = {
prompt.reportKey(logKey)
logger0.error("" + prompt.infoColor(linePrefix) + s)
Expand Down
4 changes: 4 additions & 0 deletions core/internal/src/mill/internal/PromptLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private[mill] class PromptLogger(
colored: Boolean,
enableTicker: Boolean,
infoColor: fansi.Attrs,
warnColor: fansi.Attrs,
errorColor: fansi.Attrs,
systemStreams0: SystemStreams,
debugEnabled: Boolean,
Expand Down Expand Up @@ -96,6 +97,8 @@ private[mill] class PromptLogger(

def info(s: String): Unit = streams.err.println(s)

def warn(s: String): Unit = streams.err.println(s)

def error(s: String): Unit = streams.err.println(s)

object prompt extends Logger.Prompt {
Expand Down Expand Up @@ -147,6 +150,7 @@ private[mill] class PromptLogger(
def debugEnabled = PromptLogger.this.debugEnabled

def infoColor: fansi.Attrs = PromptLogger.this.infoColor
def warnColor: fansi.Attrs = PromptLogger.this.warnColor
def errorColor: fansi.Attrs = PromptLogger.this.errorColor
def colored: Boolean = PromptLogger.this.colored
}
Expand Down
1 change: 1 addition & 0 deletions core/internal/src/mill/internal/ProxyLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ private[mill] class ProxyLogger(logger: Logger) extends Logger {
lazy val streams = logger.streams

def info(s: String): Unit = logger.info(s)
def warn(s: String): Unit = logger.warn(s)
def error(s: String): Unit = logger.error(s)
def ticker(s: String): Unit = logger.ticker(s)
def debug(s: String): Unit = logger.debug(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object PromptLoggerTests extends TestSuite {
colored = false,
enableTicker = true,
infoColor = fansi.Attrs.Empty,
warnColor = fansi.Attrs.Empty,
errorColor = fansi.Attrs.Empty,
systemStreams0 = new SystemStreams(baosOut, baosErr, System.in),
debugEnabled = false,
Expand Down
1 change: 1 addition & 0 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ object MillMain {
colored = colored,
enableTicker = enableTicker.getOrElse(true),
infoColor = colors.info,
warnColor = colors.warn,
errorColor = colors.error,
systemStreams0 = streams,
debugEnabled = config.debugLog.value,
Expand Down
1 change: 1 addition & 0 deletions testkit/src/mill/testkit/UnitTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class UnitTester(
colored = true,
enableTicker = false,
infoColor = mill.internal.Colors.Default.info,
warnColor = mill.internal.Colors.Default.warn,
errorColor = mill.internal.Colors.Default.error,
systemStreams0 = new SystemStreams(out = outStream, err = errStream, in = inStream),
debugEnabled = debugEnabled,
Expand Down
Loading