Files
sqm-autorate-rust/src/log.rs
T
Nils Andreas Svee 9811592f13 feat(platform): introduce abstractions for cross-platform interface statistics and traffic control
Decouple the rate controller from Linux-specific Netlink calls to support other operating systems. This adds a macOS backend for interface statistics and an "observe-only" mode for platforms where traffic shaping is not yet implemented.
2026-07-17 11:35:43 +07:00

41 lines
1.0 KiB
Rust

// SPDX-FileCopyrightText: 2022-Present Nils Andreas Svee mailto:contact@lochnair.net (github @Lochnair)
//
// SPDX-License-Identifier: MPL-2.0
use log::{Level, LevelFilter, Metadata, Record, SetLoggerError};
use rustix::time::ClockId;
use crate::time::Time;
#[derive(Clone, Copy)]
pub struct SimpleLogger {
pub level: Level,
}
impl log::Log for SimpleLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= self.level
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
let now = Time::new(ClockId::Realtime);
println!(
"{} {:5} {}:{}: {}",
now.as_secs_f64(),
record.level(),
record.file().unwrap(),
record.line().unwrap(),
record.args()
);
}
}
fn flush(&self) {}
}
pub fn init(level: Level) -> Result<(), SetLoggerError> {
log::set_boxed_logger(Box::new(SimpleLogger { level }))
.map(|()| log::set_max_level(LevelFilter::Trace))
}