v0.1.0-pre.020

This commit is contained in:
2026-07-24 22:01:07 +02:00
parent fa2d9d8ecd
commit 4190b2c0ce
84 changed files with 3314 additions and 274 deletions

View File

@@ -1,5 +1,5 @@
# file: kb-logging/Cargo.toml
# version: 1
# version: 2
[package]
name = "kb-logging"
@@ -8,5 +8,11 @@ edition.workspace = true
license.workspace = true
publish.workspace = true
[dependencies]
kb-core = { path = "../kb-core" }
tracing.workspace = true
tracing-appender.workspace = true
tracing-subscriber.workspace = true
[lints]
workspace = true

38
kb-logging/README.md Normal file
View File

@@ -0,0 +1,38 @@
<!-- file: kb-logging/README.md -->
<!-- version: 5 -->
# kb-logging
`kb-logging` initialise le routage `tracing` commun du workspace.
## Responsabilité
Le crate transforme la configuration du profil actif en layers `tracing_subscriber` et route les événements vers la console, les fichiers humains et les fichiers JSONL. Le `LoggingGuard` retourné par `init_logging` doit rester vivant pendant toute la durée du processus afin de conserver les writers non bloquants.
Les décisions de niveau et de target sont appliquées par chaque writer de route, avec un seul filtre dadmission agrégé en amont. Elles ne créent pas un `Filtered` layer par sortie : `tracing-subscriber` réserve seulement 64 identifiants de filtres par subscriber, tandis que la matrice complète comporte désormais plus de 64 routes activables. Le filtrage writer conserve les niveaux, targets exacts, préfixes et overrides configurés sans imposer cette limite au nombre de sorties ; le filtre agrégé évite de formater un événement quaucune route naccepte.
Les chemins relatifs sont résolus depuis la racine du workspace. LANSI est désactivé dans les formatters fichier et retiré une seconde fois par `StripAnsiMakeWriter` afin de nettoyer les messages provenant dune WebView ou dune dépendance externe.
## Contrat de targets
`kb-logging` utilise le target canonique `kb-logging`, défini dans `src/constants.rs`. Chaque crate qui dépend de `tracing` doit suivre le même contrat avec son propre nom Cargo.
Le test `every_tracing_crate_has_one_canonical_target_constant` inspecte les manifests du workspace et vérifie quune crate déclarant `tracing.workspace = true` possède exactement une constante conforme.
## Matrice de fichiers
Chaque profil actif configure :
```text
logs/<profile>/debug.log
logs/<profile>/info.log
logs/<profile>/error.jsonl
logs/<profile>/app.log
logs/<profile>/<crate>/debug.log
logs/<profile>/<crate>/info.log
logs/<profile>/<crate>/error.jsonl
```
Les fichiers sont en rotation quotidienne. Les routes `debug` et `info` sont cumulatives ; les routes `error.jsonl` sont forcées au niveau `error` et najoutent pas les overrides verbeux des dépendances.
Le contrat détaillé se trouve dans `docs/LOGGING.md` et `docs/TRACING_CONTRACT.md`.

58
kb-logging/src/config.rs Normal file
View File

@@ -0,0 +1,58 @@
// file: kb-logging/src/config.rs
// version: 4
//! Logging configuration data structures consumed by the tracing runtime.
/// Legacy file route shape kept for early callers that only need human file logs.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LogFileRoute {
/// Output file path.
pub file: std::string::String,
/// Logging level filter.
pub level: std::string::String,
/// Target filters handled by this route.
pub targets: std::vec::Vec<std::string::String>,
}
/// One target-level filter shared by routes that include the wildcard target.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LogTargetFilterConfig {
/// Tracing target or crate prefix.
pub target: std::string::String,
/// Minimum level assigned to this target.
pub level: std::string::String,
}
/// One logging output route.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LogTargetConfig {
/// Route name used for diagnostics.
pub name: std::string::String,
/// Enables this route.
pub enabled: bool,
/// Sink kind: `console` or `file`.
pub sink: std::string::String,
/// Minimum level for this route.
pub level: std::string::String,
/// File path for file sinks, empty for console sinks.
pub path: std::string::String,
/// Rotation mode: `none`, `never`, `daily`, or `hourly`.
pub rotation: std::string::String,
/// Format kind: `human`, `compact`, `pretty`, or `json`.
pub format: std::string::String,
/// Enables ANSI formatting for this route.
pub ansi: bool,
/// Included tracing targets or wildcard target globs.
pub targets: std::vec::Vec<std::string::String>,
}
/// Logging configuration consumed by `kb-logging` before profile binding exists.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LoggingConfig {
/// Default log level used when a route does not provide target directives.
pub default_level: std::string::String,
/// Output routes.
pub targets: std::vec::Vec<crate::LogTargetConfig>,
/// Target-specific overrides appended to wildcard routes.
pub target_filters: std::vec::Vec<crate::LogTargetFilterConfig>,
}

View File

@@ -1,5 +1,5 @@
// file: kb-logging/src/constants.rs
// version: 1
// version: 2
/// Canonical tracing target for this crate.
pub(crate) const TRACING_TARGET: &str = "kb-logging";

View File

@@ -1,17 +1,30 @@
// file: kb-logging/src/lib.rs
// version: 1
// version: 6
#![forbid(unsafe_code)]
#![deny(unreachable_pub)]
//! Logging and tracing initialization for applications and workers.
#![warn(missing_docs)]
#![deny(unreachable_pub)]
#![forbid(unsafe_code)]
//! Logging contracts for Khadhroony Bot3.
mod config;
mod constants;
mod tracing_runtime;
/// Canonical tracing target for this crate.
pub(crate) use self::constants::TRACING_TARGET;
/// Exposes the legacy file route shape kept for early file-only callers.
pub use self::config::LogFileRoute;
/// Exposes one configured logging output target.
pub use self::config::LogTargetConfig;
/// Exposes one configured tracing target filter.
pub use self::config::LogTargetFilterConfig;
/// Exposes the logging configuration consumed by this crate.
pub use self::config::LoggingConfig;
/// Exposes the guard that keeps non-blocking logging workers alive.
pub use self::tracing_runtime::LoggingGuard;
/// Exposes initialization from a raw logging configuration section.
pub use self::tracing_runtime::init_logging;
/// Returns the canonical tracing target.
pub fn tracing_target() -> &'static str {
return crate::TRACING_TARGET;

File diff suppressed because it is too large Load Diff