Add env variable for truncating max log length#194
Add env variable for truncating max log length#194JonatanWaern wants to merge 2 commits intomainfrom
Conversation
JonatanWaern
commented
Feb 19, 2026
- Get rid of usage of 'warn' level
- Override logs with trancating ones
There was a problem hiding this comment.
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.rsmacros (debug/info/trace/error) that truncate log messages based onMAX_LOG_MESSAGE_LENGTH. - Replaced
use log::{...}imports across the codebase withuse crate::logging::{...}and convertedwarn!call sites. - Documented the new environment variable in
USAGE.mdand noted it inCHANGELOG.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.
77e5cee to
255a575
Compare
There was a problem hiding this comment.
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.
255a575 to
07774e3
Compare
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>
07774e3 to
8bf06be
Compare
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
| * `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, ` ...`). |
| if (log::log_enabled!($level)) { | ||
| $log!("{}", $crate::format_truncated!(*crate::logging::MAX_LOG_MESSAGE_LENGTH, $($arg)*)); |
There was a problem hiding this comment.
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.
| 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)*)); | |
| } | |
| } |