summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock111
-rw-r--r--Cargo.toml2
-rw-r--r--src/log.rs29
3 files changed, 29 insertions, 113 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9319f83..7721d79 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -21,15 +21,6 @@ dependencies = [
]
[[package]]
-name = "android_system_properties"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
-dependencies = [
- "libc",
-]
-
-[[package]]
name = "anes"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -115,17 +106,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
-name = "chrono"
-version = "0.4.43"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118"
-dependencies = [
- "iana-time-zone",
- "num-traits",
- "windows-link",
-]
-
-[[package]]
name = "ciborium"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -178,12 +158,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831"
[[package]]
-name = "core-foundation-sys"
-version = "0.8.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
-
-[[package]]
name = "criterion"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -286,11 +260,11 @@ name = "dpibreak"
version = "0.4.2"
dependencies = [
"anyhow",
- "chrono",
"criterion",
"ctrlc",
"daemonize",
"etherparse 0.18.2",
+ "libc",
"nfq-updated",
"nix 0.27.1",
"serde_json",
@@ -342,30 +316,6 @@ dependencies = [
]
[[package]]
-name = "iana-time-zone"
-version = "0.1.65"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
-dependencies = [
- "android_system_properties",
- "core-foundation-sys",
- "iana-time-zone-haiku",
- "js-sys",
- "log",
- "wasm-bindgen",
- "windows-core",
-]
-
-[[package]]
-name = "iana-time-zone-haiku"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
-dependencies = [
- "cc",
-]
-
-[[package]]
name = "itertools"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -397,12 +347,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]]
-name = "log"
-version = "0.4.29"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
-
-[[package]]
name = "memchr"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -842,56 +786,12 @@ dependencies = [
]
[[package]]
-name = "windows-core"
-version = "0.62.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
-dependencies = [
- "windows-implement",
- "windows-interface",
- "windows-link",
- "windows-result",
- "windows-strings",
-]
-
-[[package]]
-name = "windows-implement"
-version = "0.60.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "windows-interface"
-version = "0.59.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
-name = "windows-result"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
-dependencies = [
- "windows-link",
-]
-
-[[package]]
name = "windows-services"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -901,15 +801,6 @@ dependencies = [
]
[[package]]
-name = "windows-strings"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
-dependencies = [
- "windows-link",
-]
-
-[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 94f2d9b..ee9dba2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,7 +32,6 @@ readme = "README.md"
ctrlc = { version = "3.4", features = ["termination"] }
anyhow = "1"
etherparse = "0.18"
-chrono = { version = "0.4", default-features = false, features = ["clock"] }
[target.'cfg(target_os = "linux")'.dependencies]
nfq = { package = "nfq-updated", version = "0.2.6" } # nfq-updated: to us as_raw_fd
@@ -40,6 +39,7 @@ socket2 = { version = "0.6", features = ["all"] }
nix = { version = "0.27.1", features = ["fs", "poll", "user"] }
serde_json = "1.0.145"
daemonize = "0.5.0"
+libc = "0.2"
[target.'cfg(windows)'.dependencies]
windivert = { version = "0.6.0" }
diff --git a/src/log.rs b/src/log.rs
index 9e5d641..3bc9452 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -61,12 +61,37 @@ impl std::str::FromStr for LogLevel {
}
}
+#[cfg(unix)]
+pub fn local_time() -> (i32, u8, u8, u8, u8, u8) {
+ unsafe {
+ let t = libc::time(std::ptr::null_mut());
+ let mut tm: libc::tm = std::mem::zeroed();
+ libc::localtime_r(&t, &mut tm);
+ (tm.tm_year + 1900, (tm.tm_mon + 1) as u8, tm.tm_mday as u8,
+ tm.tm_hour as u8, tm.tm_min as u8, tm.tm_sec as u8)
+ }
+}
+
+#[cfg(windows)]
+pub fn local_time() -> (i32, u8, u8, u8, u8, u8) {
+ use std::mem::zeroed;
+ #[repr(C)]
+ struct SYSTEMTIME { y: u16, m: u16, _dow: u16, d: u16, h: u16, min: u16, s: u16, _ms: u16 }
+ unsafe extern "system" { fn GetLocalTime(st: *mut SYSTEMTIME); }
+ unsafe {
+ let mut st: SYSTEMTIME = zeroed();
+ GetLocalTime(&mut st);
+ (st.y as i32, st.m as u8, st.d as u8, st.h as u8, st.min as u8, st.s as u8)
+ }
+}
+
#[macro_export]
macro_rules! log_println {
($level:expr, $($arg:tt)*) => {{
- let now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S");
+ let (y, mo, d, h, mi, s) = crate::log::local_time();
if $level >= crate::opt::log_level() {
- println!("{now} {} {}", $level, format_args!($($arg)*));
+ println!("{y:04}-{mo:02}-{d:02} {h:02}:{mi:02}:{s:02} {} {}",
+ $level, format_args!($($arg)*));
}
}};
}