Skip to content

Coloured console logger#46

Merged
GuilhermeF03 merged 19 commits into
mainfrom
31-colored-console-logs-bleeding-into-files
Mar 14, 2026
Merged

Coloured console logger#46
GuilhermeF03 merged 19 commits into
mainfrom
31-colored-console-logs-bleeding-into-files

Conversation

@DanielSousa01

Copy link
Copy Markdown
Collaborator

Summary
This PR aims to fix bugs from the previous PR related to issue #31, where user logs and engine logs were written to the same log files, the log fields were missing, and color coding was not applied.

Changes

  • Removed some unnecessary files;
  • Added the missing call to formatFields;
  • Changed the canopy-logback.xml to support the requirements;
  • Some changes to the remaining modules.

Related Issues

GuilhermeF03 and others added 15 commits March 2, 2026 19:05
Allows end-users to import less modules
* Refactored logging module for better organization
* Made banner logging bare console print
* Moved it into "nodeEnterTree" instead of "nodeReady"
* Also made context provide lambdas, so calling "provide" calls the up to date value
* Fields color-coded, but no file bleeding
* Engine logs with custom fields and no color bleeding
* Rmoved runDir, runId from logs, added date to timestamp

Co-Authored-By: Daniel Sousa <94607405+danielsousa01@users.noreply.github.com>
Everything was mashed together, now are properly separated into:

[context-fields] [fields] msg

Co-Authored-By: Daniel Sousa <94607405+danielsousa01@users.noreply.github.com>
Replace the previous programmatic Logback setup with an external logback.xml and runtime bootstrap.
Added fieldsPrefix with the fields correctly formatted.
Introduce a default Config for CanopyLogging and make init() accept it as an optional parameter.
Added EngineLogs as a centralized registry of engine subsystem loggers.
* Also fixed files being created at root due to Logback auto loading logback.xml before the setting the property
Removed unnecessary files from main
@DanielSousa01 DanielSousa01 self-assigned this Mar 14, 2026
@DanielSousa01 DanielSousa01 added the bug Something isn't working label Mar 14, 2026
@DanielSousa01 DanielSousa01 linked an issue Mar 14, 2026 that may be closed by this pull request
@DanielSousa01 DanielSousa01 added enhancement New feature or request pull-request labels Mar 14, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in canopy-tasks Mar 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the engine logging stack by moving Logback setup to a classpath XML configuration, updating the logging API surface (rename to CanopyLogs), and adjusting how global/scoped context and per-event fields are propagated to output formats (console, text files, JSONL).

Changes:

  • Add canopy-logback.xml with console + rolling file appenders (text + JSONL) and an engine-namespace logger split.
  • Replace ANSI field coloring in code with a Logback MessageConverter (ColoredFieldsConverter) and shift per-event fields into MDC under a dedicated key.
  • Simplify CanopyLogging bootstrap to set LOG_DIR and reload Logback via JoranConfigurator; rename LogsCanopyLogs and adjust engine logger naming.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
engine/logging/src/main/resources/canopy-logback.xml New Logback config for console + rolling text/JSONL files and engine/root routing.
engine/logging/src/main/kotlin/io/canopy/engine/logging/util/MdcExcludeConverter.kt Removes custom MDC converter previously used for console formatting.
engine/logging/src/main/kotlin/io/canopy/engine/logging/util/Mdc.kt Trims documentation around temporary MDC scoping utility.
engine/logging/src/main/kotlin/io/canopy/engine/logging/util/LogUtils.kt Updates logging extension receivers from Logs to CanopyLogs.
engine/logging/src/main/kotlin/io/canopy/engine/logging/slf4j/Slf4jProvider.kt Deletes SLF4J provider abstraction layer.
engine/logging/src/main/kotlin/io/canopy/engine/logging/slf4j/Slf4jLogger.kt Reworks event field formatting and MDC merging; removes Logstash structured args usage.
engine/logging/src/main/kotlin/io/canopy/engine/logging/Logger.kt Moves Logger into io.canopy.engine.logging package.
engine/logging/src/main/kotlin/io/canopy/engine/logging/LogContext.kt Changes global context storage to normalized string map; adds remove/clear APIs.
engine/logging/src/main/kotlin/io/canopy/engine/logging/logback/ColoredFieldsConverter.kt Adds Logback converter to colorize [k=v] prefixes in console output.
engine/logging/src/main/kotlin/io/canopy/engine/logging/logback/ClassNameDiscriminator.kt Adds discriminator for potential sifted appenders (currently commented out in XML).
engine/logging/src/main/kotlin/io/canopy/engine/logging/EngineLogs.kt Updates engine logger naming scheme and adds engineLogger(...) helper.
engine/logging/src/main/kotlin/io/canopy/engine/logging/core/LogProvider.kt Removes provider interface abstraction.
engine/logging/src/main/kotlin/io/canopy/engine/logging/core/DefaultProvider.kt Removes default provider indirection.
engine/logging/src/main/kotlin/io/canopy/engine/logging/CanopyLogs.kt Renames central logger factory to CanopyLogs and keeps convenience logger() helpers.
engine/logging/src/main/kotlin/io/canopy/engine/logging/CanopyLogging.kt Switches from programmatic appender construction to XML reload with LOG_DIR injection.
engine/core/src/test/kotlin/io/canopy/engine/core/flow/EventTests.kt Minor whitespace cleanup.
engine/app/app-test/src/main/kotlin/io/canopy/engine/app/test/TestHeadlessCanopyApp.kt Removes eager ManagersRegistry.teardown() from test app constructor.
engine/app/app-headless/src/main/kotlin/io/canopy/engine/app/headless/TerminalCanopyApp.kt Adds a log line on backend startup.
engine/app/app-core/src/main/kotlin/io/canopy/engine/app/core/CanopyApp.kt Simplifies logging init call and moves ManagersRegistry.teardown() into app startup.
Comments suppressed due to low confidence (5)

engine/logging/src/main/kotlin/io/canopy/engine/logging/CanopyLogs.kt:5

  • This import appears to be a self-import of CanopyLogs.setProvider and is unused (setProvider is referenced unqualified within the object). Unused imports typically fail ktlint; please remove it.
    engine/logging/src/main/kotlin/io/canopy/engine/logging/CanopyLogs.kt:28
  • The KDoc above still references [LogProvider] / “[Logs] object”, but LogProvider/Logs were removed/renamed in this PR. This creates broken KDoc links and is misleading; please update the doc to refer to CanopyLogs and the current provider type ((String) -> Logger).
    engine/logging/src/main/kotlin/io/canopy/engine/logging/CanopyLogs.kt:28
  • This PR renames/replaces the old Logs API with CanopyLogs, but there are still references to the old API elsewhere in the repo (e.g. engine/app/app-desktop/.../DesktopCanopyApp.kt imports io.canopy.engine.logging.api.Logs and calls Logs.get(...)). As-is, the build will fail; please update remaining call sites to CanopyLogs/logger().
    engine/logging/src/main/kotlin/io/canopy/engine/logging/EngineLogs.kt:16
  • Engine logger names were switched to the io.canopy.engine.* namespace (see subsystem() implementation), but this KDoc still states canopy.engine.* and gives canopy.engine.physics style examples. Please update the documentation to match the actual logger name prefix so routing/filtering expectations are clear.
 * Centralized access point for engine loggers.
 *
 * All loggers created here live under the `canopy.engine.*` namespace,
 * which allows the logging system to:
 *
 * - Route engine-origin logs to dedicated files (engine.log / engine.jsonl)
 * - Filter them out from user-facing console output
 * - Keep engine logging consistent across subsystems
 *
 * Contributors:
 * - Add new engine subsystems here instead of creating ad-hoc loggers.
 * - Subsystem names become part of the logger category
 *   (e.g. `canopy.engine.physics`, `canopy.engine.render`).

engine/logging/src/main/kotlin/io/canopy/engine/logging/CanopyLogs.kt:75

  • This convenience-helper comment still says callers shouldn’t have to reference the [Logs] object, but the object is now CanopyLogs. Please update this wording to avoid confusion (and to prevent broken KDoc links if [Logs] no longer exists).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread engine/logging/src/main/resources/canopy-logback.xml
Comment thread engine/logging/src/main/resources/canopy-logback.xml Outdated
Comment thread engine/logging/src/main/resources/canopy-logback.xml
Comment thread engine/logging/src/main/resources/canopy-logback.xml Outdated
DanielSousa01 and others added 3 commits March 14, 2026 20:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@GuilhermeF03 GuilhermeF03 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 🥳

@GuilhermeF03 GuilhermeF03 merged commit 244590f into main Mar 14, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in canopy-tasks Mar 14, 2026
@GuilhermeF03 GuilhermeF03 deleted the 31-colored-console-logs-bleeding-into-files branch March 14, 2026 20:57
@GuilhermeF03 GuilhermeF03 changed the title feat: Coloured console logger Coloured console logger Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request pull-request topic:logging

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Bug: Colored console logs bleeding into files

3 participants