Phase 0: Rust project scaffolding (M0 complete)
Completed Rust project initialization: - Cargo.toml with all dependencies (actix-web, tokio, rustls, etc.) - Project structure (src/, tests/, configs/) - Module declarations (api, auth, config, jobs, logging, packages, systemd) - Clippy and rustfmt configured - Initial lib.rs and main.rs with logging setup - Config examples (config.yaml.example, whitelist.yaml.example) Dependencies resolved and project compiles successfully. Rust toolchain 1.94.1 installed.
This commit is contained in:
44
src/logging/init.rs
Normal file
44
src/logging/init.rs
Normal file
@ -0,0 +1,44 @@
|
||||
//! Logging Initialization
|
||||
//!
|
||||
//! Sets up tracing with systemd journal and file appender support.
|
||||
|
||||
|
||||
use anyhow::Result;
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
|
||||
|
||||
/// Initialize logging with tracing
|
||||
///
|
||||
/// Sets up:
|
||||
/// - Env-based log level filtering
|
||||
/// - JSON formatting for machine readability
|
||||
/// - systemd journal integration
|
||||
/// - File appender fallback to /var/log/linux_patch_api/
|
||||
pub fn init_logging(verbose: bool) -> Result<WorkerGuard> {
|
||||
let log_level = if verbose { "debug" } else { "info" };
|
||||
let filter = EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| EnvFilter::new(log_level));
|
||||
|
||||
let file_appender = tracing_appender::rolling::daily("/var/log/linux_patch_api", "audit.log");
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
let file_layer = fmt::layer()
|
||||
.with_writer(non_blocking)
|
||||
.with_ansi(false)
|
||||
.with_target(true)
|
||||
.with_thread_ids(true);
|
||||
|
||||
let stdout_layer = fmt::layer()
|
||||
.with_writer(std::io::stdout)
|
||||
.with_ansi(true);
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(filter)
|
||||
.with(file_layer)
|
||||
.with(stdout_layer)
|
||||
.try_init()
|
||||
.ok(); // Ignore if already initialized
|
||||
|
||||
Ok(guard)
|
||||
}
|
||||
11
src/logging/mod.rs
Normal file
11
src/logging/mod.rs
Normal file
@ -0,0 +1,11 @@
|
||||
//! Logging Module - Audit logging and tracing
|
||||
//!
|
||||
//! Handles audit logging as defined in SPEC.md:
|
||||
//! - systemd journal integration (primary)
|
||||
//! - Optional remote syslog
|
||||
//! - Local file fallback (/var/log/linux_patch_api/audit.log)
|
||||
//! - 30-day retention with daily rotation
|
||||
|
||||
pub mod appender;
|
||||
pub mod journal;
|
||||
pub mod init;
|
||||
Reference in New Issue
Block a user