feat: JSON-Logging mit Correlation-ID, Anfrage-Log und Audit (M2.4)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -16,6 +16,8 @@ pub struct Config {
|
||||
pub listen: String,
|
||||
/// Ordner für Datenbank, Logs und Ergebnisse.
|
||||
pub data_dir: PathBuf,
|
||||
/// Log-Stufe: `error`, `warn`, `info`, `debug` oder `trace`.
|
||||
pub log_level: String,
|
||||
/// Rohe Einstellungen des llama.cpp-Adapters (Abschnitt `[llama_cpp]`).
|
||||
/// Dieses Crate kennt die Adapter nicht; der Adapter liest die Tabelle selbst.
|
||||
pub llama_cpp: toml::Table,
|
||||
@ -26,6 +28,7 @@ impl Default for Config {
|
||||
Self {
|
||||
listen: "127.0.0.1:8080".to_string(),
|
||||
data_dir: PathBuf::from("data"),
|
||||
log_level: "info".to_string(),
|
||||
llama_cpp: toml::Table::new(),
|
||||
}
|
||||
}
|
||||
@ -53,6 +56,12 @@ impl Config {
|
||||
self.listen.parse::<SocketAddr>().map_err(|e| {
|
||||
Error::Config(format!("listen \"{}\" ist keine Adresse: {e}", self.listen))
|
||||
})?;
|
||||
if !["error", "warn", "info", "debug", "trace"].contains(&self.log_level.as_str()) {
|
||||
return Err(Error::Config(format!(
|
||||
"log_level \"{}\" ist unbekannt (error, warn, info, debug, trace)",
|
||||
self.log_level
|
||||
)));
|
||||
}
|
||||
if self.data_dir.as_os_str().is_empty() {
|
||||
return Err(Error::Config("data_dir darf nicht leer sein".to_string()));
|
||||
}
|
||||
@ -102,6 +111,13 @@ mod tests {
|
||||
assert_eq!(c.llama_cpp["ready_timeout_secs"].as_integer(), Some(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_stufe_wird_geprueft() {
|
||||
assert_eq!(Config::default().log_level, "info");
|
||||
assert!(Config::from_toml("log_level = \"debug\"").is_ok());
|
||||
assert!(Config::from_toml("log_level = \"laut\"").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leeres_datenverzeichnis_wird_abgelehnt() {
|
||||
assert!(Config::from_toml("data_dir = \"\"").is_err());
|
||||
|
||||
Reference in New Issue
Block a user