Repository navigation
Conversation
…Record::logger_name
Subsystems and dependency libraries passed an explicit `Logger` previously had no first-class way to identify their logical channel or narrow verbosity locally without cloning dispatch pipelines, while `logforth-bridge-log` had to smuggle explicit `log` target overrides (`log::info!(target: "sqlx::query", ...)`) into `RustLogFilter` through a reserved `"logforth.log_target"` key-value pair that leaked into formatted records.
Split `Logger`'s shared state into `LoggerState` (`level_mask`, `name`, and `Arc<Pipeline>`) and introduce first-class logical logger names and handle-local level narrowing:
- Add `Logger::{name, named, with_level_filter}` in `logforth-core`: `named` joins hierarchical segments with `"::"` (`Logger::noop()` remains a no-op and empty segments preserve the current name), and `with_level_filter` narrows the handle's precomputed `level_mask` via bitwise intersection without affecting parent or sibling handles.
- Add `Record::{logger_name, logger_name_static}` and `RecordBuilder::{logger_name, logger_name_static}` (preserved across `to_builder`, `to_owned`, and `RecordOwned::with`), stamping a named `Logger`'s name onto records only when `Record::logger_name` is unset so explicit per-record overrides win.
- Replace the `"logforth.log_target"` key-value bridge workaround in `logforth-bridge-log` and `logforth-filter-rustlog`: `LogBridge` maps custom `log` targets to `RecordBuilder::logger_name`, and `RustLogFilter` matches prefix directives against `Record::logger_name` before falling back to `Record::module_path`.
- Emit optional logger names across built-in layouts and OpenTelemetry (`[logger]` in `PlainTextLayout` and `TextLayout`, `"logger"` in `JsonLayout` and `GoogleCloudLoggingLayout`, `logger=` in `LogfmtLayout`, and `LogRecord::set_target` in `OpentelemetryLog` when `Record::logger_name` is present).
Signed-off-by: tison <wander4096@gmail.com>
Contributor
Author
|
Closing after further design evaluation:
|
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
Subsystems and libraries receiving an injected
Loggerpreviously lacked a way to attach a hierarchical channel name or restrict handle verbosity locally without rebuilding dispatch pipelines, andlogforth-bridge-loghad to forward customlogtargets (log::info!(target: "sqlx::query", ...)) intoRustLogFilterthrough a synthetic"logforth.log_target"key-value entry that leaked into downstream layouts and appenders.This PR introduces first-class hierarchical logger naming and monotonic handle-level narrowing on
Logger, backed byRecord::logger_name(related to #276):Logger::{name, named, with_level_filter}(logforth-core): SplitsLogger's internalArcintoLoggerState { level_mask, name, pipeline: Arc<Pipeline> }soLoggerremains pointer-sized andLogger::enabledstays a single pointer dereference.Logger::namedjoins segments with"::"(root.named("db").named("wal")->"db::wal"), keepsLogger::noop()a zero-allocation no-op, treats""as an identity clone, and preserves'staticprovenance for single-segment static names.Logger::with_level_filterintersects the handle'slevel_maskwithLevelFilter, narrowing verbosity locally on the derived handle without starving parent/sibling handles or bypassing downstream dispatch filters.Record::logger_name& target precedence (logforth-core,logforth-bridge-log,logforth-filter-rustlog):Record::{logger_name, logger_name_static}andRecordBuilder::{logger_name, logger_name_static}, preserved acrossRecord::to_builder,Record::to_owned, andRecordOwned::with.Logger::logstampsLogger::name()onto a stack-copiedRecordBuilderonly whenrecord.logger_name().is_none(), so explicit per-record names (including customlogtargets bridged byLogBridge) take precedence over outer handle names."logforth.log_target"magic key-value entry completely;RustLogFilternow matches prefix directives againstrecord.logger_name().or_else(|| record.module_path()).PlainTextLayout,TextLayout,JsonLayout,LogfmtLayout,GoogleCloudLoggingLayout,OpentelemetryLog):Record::logger_name()isSome(name)NonePlainTextLayout[name]immediately after severity (INFO [db::wal] app::storage: ...)TextLayout[name]immediately after severityJsonLayout"logger": namebefore"module_path"LogfmtLayoutlogger=<name>beforemodule=GoogleCloudLoggingLayout"logger"tojsonPayloadorlogging.googleapis.com/labels(overridable by diagnostics/record KVs)OpentelemetryLogLogRecord::set_targetso OTLP exports group records intoScopeLogsby logger nameOpentelemetryLogBuilder::new(name, ...)scopeTest Plan
cargo x checkcargo x testcargo x lint