Skip to content

[2.x] fix: Fixes command logs#8515

Merged
eed3si9n merged 1 commit intosbt:developfrom
SalesforcePeak:fix/logging
Jan 13, 2026
Merged

[2.x] fix: Fixes command logs#8515
eed3si9n merged 1 commit intosbt:developfrom
SalesforcePeak:fix/logging

Conversation

@SalesforcePeak
Copy link
Copy Markdown
Contributor

@SalesforcePeak SalesforcePeak commented Jan 13, 2026

Fixes #7971

Problem

When running sbt with --warn or --error log levels, logs created from commands using state.log were not displayed on the console. This affected:

  • Warning and error logs from custom commands
  • Error messages from MessageOnlyException thrown in commands

Example:

# Expected warnings and errors to show, but console was empty
$ sbt --warn logCommand
$ sbt --error logCommand

Root Cause

In LogManager.setGlobalLogLevel, when updating the global log level:

  1. All appenders were cleared from the global logger
  2. Only the backed (file) appender was re-added with the new level
  3. The console appender was not re-added, causing all console output to disappear

This meant logs were only written to the backing file (target/global-logging/*.log), not displayed on the console.

Solution

Modified setGlobalLogLevel to preserve the console appender when changing log levels:

def setGlobalLogLevel(s: State, level: Level.Value): State = {
  val s1 = s.put(BasicKeys.explicitGlobalLogLevels, true).put(Keys.logLevel.key, level)
  val gl = s1.globalLogging
  LoggerContext.globalContext.clearAppenders(gl.full.name)
  val consoleAppender = MainAppender.defaultScreen(gl.console)
  LoggerContext.globalContext.addAppender(gl.full.name, consoleAppender -> level)
  LoggerContext.globalContext.addAppender(gl.full.name, gl.backed -> level)
  s1
}

Now both the console and file appenders are properly configured with the new log level.

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=147358252

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Do you have before / after comparison even if it's a manual test?

@SalesforcePeak
Copy link
Copy Markdown
Contributor Author

Thanks for the contribution! Do you have before / after comparison even if it's a manual test?

yes, I ran simple test

val logCommand = Command.command("logCommand") { state =>
  state.log.info("Command info")
  state.log.warn("Command warning")
  state.log.error("Command error")
  state
}

commands += logCommand

sbt --warn logCommand and sbt --error logCommand logged correctly in the console

[info] Command info
[warn] Command warning
[error] Command error

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n
Copy link
Copy Markdown
Member

Could you sign the CLA and let me know plz, and I'll rerun the check.

@eed3si9n eed3si9n changed the title fix: Loggings Created in Commands Not Showing up in WARN or ERROR Log Levels [2.x] fix: Loggings Created in Commands Not Showing up in WARN or ERROR Log Levels Jan 13, 2026
@SalesforcePeak
Copy link
Copy Markdown
Contributor Author

Could you sign the CLA and let me know plz, and I'll rerun the check.

I've signed, can you plz rerun it?

@eed3si9n eed3si9n merged commit 1ef5823 into sbt:develop Jan 13, 2026
14 of 15 checks passed
@eed3si9n eed3si9n changed the title [2.x] fix: Loggings Created in Commands Not Showing up in WARN or ERROR Log Levels [2.x] fix: Fixes command logs Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loggings Created in Commands Not Showing up in WARN or ERROR Log Levels

2 participants