fucking crowdstrike

parse-tree
Jordan Orelli 2 years ago
parent f8f59c2de5
commit b548b908e7

@ -1,3 +1,4 @@
use std::io;
use thiserror::Error; use thiserror::Error;
use windows::Win32::Foundation::{GetLastError, BOOL}; use windows::Win32::Foundation::{GetLastError, BOOL};
@ -5,6 +6,9 @@ use windows::Win32::Foundation::{GetLastError, BOOL};
pub enum Error { pub enum Error {
#[error("windows error: {0}")] #[error("windows error: {0}")]
WindowsError(String), WindowsError(String),
#[error("i/o error: {0}")]
IOError(#[from] io::Error),
} }
impl Error { impl Error {

@ -1,19 +1,58 @@
use crate::error::Error;
pub use log::{debug, error, info, set_logger, set_max_level, trace, warn, LevelFilter}; pub use log::{debug, error, info, set_logger, set_max_level, trace, warn, LevelFilter};
use std::{
fs::File,
io,
path::Path,
sync::{Arc, Mutex},
};
use log::{Metadata, Record}; use log::{Metadata, Record};
pub struct Log; pub struct Log<W> {
out: Arc<Mutex<W>>,
}
impl Log<File> {
pub fn file<P: AsRef<Path>>(p: P) -> Result<Self, Error> {
let f = File::options().append(true).create(true).open(p)?;
Ok(Self {
out: Arc::new(Mutex::new(f)),
})
}
}
impl<W> Log<W>
where
W: io::Write,
{
pub fn from_writer(w: W) -> Self {
Self {
out: Arc::new(Mutex::new(w)),
}
}
}
impl log::Log for Log { impl<W> log::Log for Log<W>
where
W: io::Write + Send,
{
fn enabled(&self, _metadata: &Metadata) -> bool { fn enabled(&self, _metadata: &Metadata) -> bool {
true true
} }
fn log(&self, record: &Record) { fn log(&self, record: &Record) {
if self.enabled(record.metadata()) { if self.enabled(record.metadata()) {
println!("{} - {}", record.level(), record.args()); if let Ok(out) = self.out.lock().as_deref_mut() {
_ = write!(out, "{} - {}\n", record.level(), record.args());
}
} }
} }
fn flush(&self) {} fn flush(&self) {
if let Ok(out) = self.out.lock().as_deref_mut() {
_ = out.flush();
}
}
} }

@ -244,7 +244,16 @@ fn setup_stdout() -> Result<()> {
} }
fn main() -> Result<()> { fn main() -> Result<()> {
_ = set_logger(&Log {}).map(|()| set_max_level(LevelFilter::Info)); match Log::file("C:\\Users\\JordanOrelli\\wash.log") {
Ok(f) => {
let target = Box::leak(Box::new(f));
_ = set_logger(target).map(|()| set_max_level(LevelFilter::Debug));
}
Err(e) => {
println!("did not open log file: {}", e);
}
}
setup_stdin()?; setup_stdin()?;
setup_stdout()?; setup_stdout()?;

Loading…
Cancel
Save