Coloured console logger#46
Merged
Merged
Conversation
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
There was a problem hiding this comment.
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.xmlwith 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
CanopyLoggingbootstrap to setLOG_DIRand reload Logback viaJoranConfigurator; renameLogs→CanopyLogsand 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.Logsand callsLogs.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 statescanopy.engine.*and givescanopy.engine.physicsstyle 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 nowCanopyLogs. 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.
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>
…/github.com/canopyengine/canopy into 31-colored-console-logs-bleeding-into-files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
formatFields;canopy-logback.xmlto support the requirements;Related Issues