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>
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.

`goto-implementations`)

## Relevant environment variables
* `MAX_LOG_MESSAGE_LENGTH` When set, will truncate any outputted logs that are longer than the value. Defaults to 1000 characters. Set to 0 to turn off truncation.
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.

This doc line doesn’t match the current implementation in src/logging.rs: truncation is enabled by default (1000), 0 does not disable truncation (it produces just " ..."), and the limit is applied in bytes (s.len()) rather than Unicode character count. Please update the docs and/or implementation so the behavior and wording are consistent.

Suggested change
* `MAX_LOG_MESSAGE_LENGTH` When set, will truncate any outputted logs that are longer than the value. Defaults to 1000 characters. Set to 0 to turn off truncation.
* `MAX_LOG_MESSAGE_LENGTH` When set, will truncate any outputted logs whose byte length (`s.len()`) exceeds the given value. Truncation is enabled by default with a limit of 1000 bytes. Note that setting this to 0 does not disable truncation; it causes all log messages to be truncated to just the truncation marker (for example, ` ...`).

Copilot uses AI. Check for mistakes.
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.
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