Repository navigation
Annotate extracted log statements with their log level - #2
Conversation
Keep the logging call name captured before the format string in each language's query and normalize it (e.g. log::warn, logger.warning, spdlog::info, SPDLOG_ERROR) to a LogLevel on SourceRef. The level is serialized as an optional "level" field in the srcRef output. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014JycCPeVRxuveoeMtHnJmt
Names made of words joined by underscores, like lnav's log_debug() or SPDLOG_INFO, map to the level at the end as long as another word looks logging related. Arguments before the format string, as in syslog(LOG_ERR, ...) or spdlog::log(spdlog::level::warn, ...), are also checked for a level and take precedence over the call name. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014JycCPeVRxuveoeMtHnJmt
|
Test VS Code Extension failed before any extension test ran. This looks like a runner or VS Code download problem rather than something in this diff. The only extension change here is an optional Generated by Claude Code |
|
The re-run failed the same way ( Two ways to fix it, outside this PR's scope:
I'll wait for the maintainer to decide whether that goes here or in its own PR. Generated by Claude Code |
- Only take level constants from leading arguments that are names, so a string literal like "conn error" no longer sets the level of a later string in the same call. - Require leading arguments to be qualified by something logging related (LOG_ERR, logging.WARNING, spdlog::level::warn), so a variable like `err` no longer overrides the call name. - Require the qualifier of a call like `x.error` to look logging related, so warnings.warn and parser.error don't get a level. - Split names on case changes so logInfo and LogWarning are recognized. - Let the Java query match severe/fatal and log.log(Level.X, ...). - Match level-first calls in Python (logger.log(logging.WARNING, ...)) and Rust (log!(Level::Warn, ...), tracing::event!(Level::INFO, ...)). - Parse the level from log messages and prefer source statements with the same level when candidates have the same quality. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VN7ZsUqHrHHcBHoxTnSpjb
The job fails before any test runs because @vscode/test-electron can't find the Electron binary in the current VS Code macOS download. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014JycCPeVRxuveoeMtHnJmt
Every extracted statement now has a level. Calls where we can't tell the level, which might not be logging at all (printf, println!, print, or any call that takes a string), get LogLevel::Unknown, and the "level" field is always present in the srcRef output. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014JycCPeVRxuveoeMtHnJmt
Requested by Tim · project thread
Summary
Each language's query already captures the logging call (Rust
@macro-name, Java@method-name, C++@fname, Python@func), butSourceQuery::queryused to throw away captures that came before the format string. This change keeps that call name, normalizes it to aLogLevel(Trace,Debug,Info,Warn,Error,Fatal,Unknown), and stores it onSourceRefaslevel.Every
srcRefin the output has a"level"field. If the level can't be determined, it'sUnknown. That coversprintf,println!,print, and any other call that just happens to take a string, soUnknownalso means the statement might not be logging at all.How names map to levels (
LogLevel::from_name):log::warn,logger->warn,self.log.critical,log_debug(),SPDLOG_INFO,LOG_ERRandlogInfoall work. The level is the last word.log_debug,logInfo), one of them must look logging related (containslog, or islevel,lvlortracing), soreport_error()getsUnknown.x.error, the qualifier must look logging related, sowarnings.warnandparser.errorgetUnknown, whilelogger.warn,spdlog::infoandtracing::errorget a real level.finemaps to Debug;finerandfinestto Trace;noticeto Info;err,exceptionandsevereto Error;critical,crit,alertandemergto Fatal.Level arguments (
LogLevel::from_level_arg):syslog(LOG_ERR, ...),spdlog::log(spdlog::level::trace, ...).errinlogger->info(err, "x")doesn't override the call name and the statement stays Info.logger.log(logging.WARNING, "..."), Rustlog!(Level::Warn, "...")/tracing::event!(Level::INFO, "..."), and Javalog.log(Level.WARNING, "..."). The Java query also matchessevereandfatal.Linking: when the log format captures a
level, it's parsed from each log line, and when several source statements match with the same quality, the one with the same level is preferred.The VS Code extension's
SourceRefinterface also gainslevel: string.CI: the "Test VS Code Extension" job is disabled (
if: false). It failed before any test ran because@vscode/test-electron2.5.2 can't find the Electron binary in the current VS Code macOS download.Tests
test_levels_{rust,java,cpp,python}tests insrc/lib.rs, which checkUnknownfor print-style and non-logging calls, plustest_link_to_source_by_level.test_log_level_from_name,test_log_level_from_level_argandtest_log_level_from_log_textinsrc/source_ref.rs.levelfield.cargo test: all 46 tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_014JycCPeVRxuveoeMtHnJmt