Skip to content

Add env variable for truncating max log length#194

Open
JonatanWaern wants to merge 2 commits intomainfrom
truncate-max-log-length
Open

Add env variable for truncating max log length#194
JonatanWaern wants to merge 2 commits intomainfrom
truncate-max-log-length

Conversation

@JonatanWaern
Copy link
Contributor

  • Get rid of usage of 'warn' level
  • Override logs with trancating ones

Copy link

Copilot AI left a comment

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 introduces a truncating logging wrapper (configurable via an environment variable) and migrates most modules away from direct log::* usage, while also removing warn-level logging in favor of info/error.

Changes:

  • Added src/logging.rs macros (debug/info/trace/error) that truncate log messages based on MAX_LOG_MESSAGE_LENGTH.
  • Replaced use log::{...} imports across the codebase with use crate::logging::{...} and converted warn! call sites.
  • Documented the new environment variable in USAGE.md and noted it in CHANGELOG.md.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/vfs/mod.rs Switches trace import to the truncating logging wrapper.
src/server/mod.rs Uses wrapper logging macros and removes warn usage.
src/server/message.rs Switches debug import to wrapper macro.
src/server/io.rs Switches debug/trace imports to wrapper macros.
src/server/dispatch.rs Switches info/error/debug imports to wrapper macros.
src/logging.rs Adds truncating logging macros and env-based max length configuration.
src/lint/mod.rs Switches debug/error/trace imports to wrapper macros.
src/file_management.rs Switches debug/error/trace imports to wrapper macros.
src/dfa/main.rs Removes extra blank lines (still imports log::debug).
src/dfa/client.rs Switches debug/trace imports to wrapper macros.
src/config.rs Switches error/trace imports to wrapper macros.
src/cmd.rs Switches debug import to wrapper macro.
src/analysis/templating/traits.rs Switches debug/error/trace imports to wrapper macros.
src/analysis/templating/topology.rs Switches debug/error/trace imports to wrapper macros.
src/analysis/templating/objects.rs Switches debug/trace/error imports to wrapper macros.
src/analysis/structure/toplevel.rs Switches trace import to wrapper macro.
src/analysis/structure/statements.rs Switches error import to wrapper macro.
src/analysis/structure/expressions.rs Switches error import to wrapper macro.
src/analysis/scope.rs Switches debug import to wrapper macro.
src/analysis/parsing/structure.rs Switches trace import to wrapper macro.
src/analysis/parsing/statement.rs Switches error import to wrapper macro.
src/analysis/parsing/parser.rs Switches debug import to wrapper macro.
src/analysis/mod.rs Switches debug/error/info/trace imports to wrapper macros.
src/actions/work_pool.rs Uses wrapper logging macros and removes warn usage.
src/actions/requests.rs Uses wrapper logging macros and removes warn usage.
src/actions/notifications.rs Uses wrapper logging macros and removes warn usage.
src/actions/mod.rs Uses wrapper logging macros and removes warn usage.
src/actions/hover.rs Switches from log::* glob import to wrapper logging glob import.
src/actions/analysis_storage.rs Switches debug/trace/info imports to wrapper macros.
src/actions/analysis_queue.rs Switches info/debug/trace/error imports to wrapper macros.
USAGE.md Documents MAX_LOG_MESSAGE_LENGTH.
CHANGELOG.md Notes the new environment variable behavior.

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.


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

@JonatanWaern JonatanWaern force-pushed the truncate-max-log-length branch from 255a575 to 07774e3 Compare February 20, 2026 12:46
This lives in-between error and info, in practice its better to put
errors on error and info-oriented things on info

Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.


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

Comment on lines +34 to +35
if (log::log_enabled!($level)) {
$log!("{}", $crate::format_truncated!(*crate::logging::MAX_LOG_MESSAGE_LENGTH, $($arg)*));
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

format_truncated! uses format! to build a String, so every info!/debug!/trace!/error! call now allocates even when the message is short. If logs are hot, this can be a noticeable regression vs log::* macros (which pass fmt::Arguments). Consider a fast-path: when truncation is disabled (None), delegate directly to $log!($($arg)*) to avoid the allocation; and/or consider a truncating formatter that works with fmt::Arguments to avoid building the full String in the common case.

Suggested change
if (log::log_enabled!($level)) {
$log!("{}", $crate::format_truncated!(*crate::logging::MAX_LOG_MESSAGE_LENGTH, $($arg)*));
if log::log_enabled!($level) {
match *crate::logging::MAX_LOG_MESSAGE_LENGTH {
None => {
// No truncation configured: delegate directly to the underlying log macro
$log!($($arg)*);
}
Some(_) => {
// Truncation enabled: format and truncate the message as before
$log!("{}", $crate::format_truncated!(*crate::logging::MAX_LOG_MESSAGE_LENGTH, $($arg)*));
}
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fast-path is a bit nonsensical, since the formatting path is the default one.

I have tried fairly extensively to find a non-allocating alternative that also preserves env_loggers formatting and failed, so I will eat the one-allocation per log overhead. At the very least we avoid hot-path when the log level is disabled.

@JonatanWaern JonatanWaern force-pushed the truncate-max-log-length branch from 8bf06be to 0e621f5 Compare March 9, 2026 10:06
Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
@JonatanWaern JonatanWaern force-pushed the truncate-max-log-length branch from 0e621f5 to 91c6468 Compare March 9, 2026 16:41
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.

2 participants