From f64cba41d5019432a2935ce39d39697c4c94ef82 Mon Sep 17 00:00:00 2001 From: dvkt Date: Sat, 21 Dec 2019 18:47:20 -0800 Subject: [PATCH] debug log --- .gitignore | 3 ++- src/gopher.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d596b32..cfa3560 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target **/*.rs.bk -phetch \ No newline at end of file +phetch +phetch.log \ No newline at end of file diff --git a/src/gopher.rs b/src/gopher.rs index 5932911..ac81a24 100644 --- a/src/gopher.rs +++ b/src/gopher.rs @@ -99,6 +99,23 @@ pub fn char_for_type(t: Type) -> Option { }) } +#[allow(unused_macros)] +macro_rules! log { + ($e:expr) => {{ + if let Ok(mut file) = std::fs::OpenOptions::new() + .append(true) + .create(true) + .open("phetch.log") + { + file.write($e.as_ref()); + file.write(b"\n"); + } + }}; + ($e:expr, $($y:expr),*) => { + log!(format!($e, $($y),*)); + }; +} + macro_rules! error { ($e:expr) => { std::io::Error::new(std::io::ErrorKind::Other, $e)