conditionally disable debug logging

master
Avril 4 years ago
parent ec0bf8e24a
commit cc31004e52
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -8,21 +8,28 @@ edition = "2018"
[features] [features]
default = ["threaded", default = ["threaded",
"watcher_timeout"] "watcher_timeout",
"debug_logger"]
# Run with threads (TODO: rename to `threads`. What does this do?? We need `rt-threaded` for fs watcher to work...) # Run with threads (TODO: rename to `threads`. What does this do?? We need `rt-threaded` for fs watcher to work...)
threaded = [] threaded = ["tokio/rt-threaded"]
# Enable `Debug` log level printing option at runtime in release mode.
debug_logger = []
# Hot-reload config files
watcher = ["threaded"]
# FS watcher will have infinite backlog, instead of ignoring if it goes over its backlog. # FS watcher will have infinite backlog, instead of ignoring if it goes over its backlog.
# This can help DoS, but potentially cause OOM. # This can help DoS, but potentially cause OOM.
watcher_unlimited = [] watcher_unlimited = ["watcher"]
# FS watcher hooks have a defined timeout # FS watcher hooks have a defined timeout
# This can help with DoS, and hooks that hog resources # This can help with DoS, and hooks that hog resources
watcher_timeout = [] watcher_timeout = ["watcher"]
[dependencies] [dependencies]
tokio = {version = "0.2", features=["time", "macros", "io-driver", "sync", "rt-core", "rt-threaded", "fs"]} tokio = {version = "0.2", features=["time", "macros", "io-driver", "sync", "rt-core", "fs"]}
notify = "5.0.0-pre.3" notify = "5.0.0-pre.3"
futures= "0.3" futures= "0.3"
sexp = "1.1" sexp = "1.1"

@ -13,6 +13,7 @@
//! # TODO //! # TODO
//! - Make child not panic if `watch()` is called on non-existant path //! - Make child not panic if `watch()` is called on non-existant path
//! - Change hook from just string path prefix to pattern match with optional regex capability. (For finding and dispatching on global/local config files differently) //! - Change hook from just string path prefix to pattern match with optional regex capability. (For finding and dispatching on global/local config files differently)
#![allow(unused_imports)] // For when hotreload feature disabled
use super::*; use super::*;
use std::{ use std::{
@ -241,6 +242,7 @@ impl Oneesan
} }
} }
#[cfg(feature="watcher")]
/// Start watching this path for changes of files /// Start watching this path for changes of files
pub fn watch(path: impl AsRef<Path>) -> Oneesan pub fn watch(path: impl AsRef<Path>) -> Oneesan
{ {

@ -312,7 +312,7 @@ impl Logger
Ok(()) Ok(())
} }
} }
#[cfg(any(debug_assertions,feature="debug_logger"))]
#[macro_export] macro_rules! debug { #[macro_export] macro_rules! debug {
($obj:expr) => { ($obj:expr) => {
{ {
@ -326,8 +326,14 @@ impl Logger
}; };
} }
#[cfg(not(any(debug_assertions,feature="debug_logger")))]
#[macro_export] macro_rules! debug {
($obj:expr) => {{}};
($fmt:literal, $($args:expr),*) => {{}};
}
#[cfg(any(debug_assertions,feature="debug_logger"))]
#[macro_export] macro_rules! status { #[macro_export] macro_rules! status {
($obj:expr) => { ($obj:expr) => {
{ {
@ -363,6 +369,11 @@ impl Logger
}; };
} }
#[cfg(not(any(debug_assertions,feature="debug_logger")))]
#[macro_export] macro_rules! status {
($obj:expr) => {{}};
($fmt:literal, $($args:expr),*) => {{}};
}
#[macro_export] macro_rules! info { #[macro_export] macro_rules! info {
($obj:expr) => { ($obj:expr) => {

@ -26,6 +26,7 @@ mod interval;
mod config; mod config;
mod live; mod live;
mod context; mod context;
mod job; mod job;
@ -80,6 +81,7 @@ fn print_stats()
static ref BUILD_IDENT: recolored::ColoredString = "release".bright_red(); static ref BUILD_IDENT: recolored::ColoredString = "release".bright_red();
} }
#[allow(unused_imports)]
use std::ops::Deref; use std::ops::Deref;
status!("This is the lolicron daemon version {} by {} ({} build)", env!("CARGO_PKG_VERSION"), &AUTHORS[..], BUILD_IDENT.deref()); status!("This is the lolicron daemon version {} by {} ({} build)", env!("CARGO_PKG_VERSION"), &AUTHORS[..], BUILD_IDENT.deref());
status!("---"); status!("---");
@ -92,6 +94,12 @@ fn print_stats()
#[cfg(feature="threaded")] status!(" +threaded".red()); #[cfg(feature="threaded")] status!(" +threaded".red());
#[cfg(not(feature="threaded"))] status!(" -threaded".bright_blue()); #[cfg(not(feature="threaded"))] status!(" -threaded".bright_blue());
#[cfg(feature="watcher")] status!(" +watcher".red());
#[cfg(not(feature="watcher"))] status!(" -watcher".bright_blue());
#[cfg(feature="debug_logger")] status!(" +debug_logger".red());
#[cfg(not(feature="debug_logger"))] status!(" -debug_logger".bright_blue());
#[cfg(feature="watcher_unlimited")] status!(" +watcher_unlimited".bright_red()); #[cfg(feature="watcher_unlimited")] status!(" +watcher_unlimited".bright_red());
#[cfg(not(feature="watcher_unlimited"))] status!(" -watcher_unlimited".blue()); #[cfg(not(feature="watcher_unlimited"))] status!(" -watcher_unlimited".blue());
@ -111,21 +119,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
log::init(log::Level::Debug); log::init(log::Level::Debug);
debug!("Logger initialised"); debug!("Logger initialised"); //TODO: Parse config first
print_stats(); print_stats();
let oneesan = live::watch("."); #[cfg(feature="watcher")]
{ {
let mut recv = oneesan.hook("src/main.rs", live::filter::ALL).await; let oneesan = live::watch(".");
while let Some(event) = recv.recv().await
{ {
important!("Got ev {:?}", event); let mut recv = oneesan.hook("src/main.rs", live::filter::ALL).await;
break; while let Some(event) = recv.recv().await
{
important!("Got ev {:?}", event);
break;
}
} }
}
oneesan.shutdown().await.expect("oneesan panic"); oneesan.shutdown().await.expect("oneesan panic");
}
println!("{:?}", config::parse_global_single("example.rori").await.expect("Waaaaaah")); println!("{:?}", config::parse_global_single("example.rori").await.expect("Waaaaaah"));

Loading…
Cancel
Save