Move log module to dev::log

This commit is contained in:
Juno Takano 2026-03-16 20:02:03 -03:00
commit 9ebd91a589
9 changed files with 23 additions and 14 deletions

2
src/dev.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod log;
pub mod test;

View file

@ -114,7 +114,7 @@ pub fn timed(past: &Instant, message: &str) -> Instant {
#[macro_export]
macro_rules! tlog {
($instant:expr, $fmt:expr $(, $($arg:tt)+ )?) => {{
$crate::log::timed($instant, &format!($fmt $(, $($arg)+ )?))
$crate::dev::log::timed($instant, &format!($fmt $(, $($arg)+ )?))
}};
}
@ -129,26 +129,26 @@ pub fn elog(function: &str, message: &str) {
macro_rules! log {
($level:path, $fmt:expr $(, $($arg:tt)+ )?) => {{
let data = $crate::log::Data::new(
let data = $crate::dev::log::Data::new(
Some($level),
std::any::type_name_of_val(&|| {}),
std::backtrace::Backtrace::capture(),
);
if data.should_log {
$crate::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
$crate::dev::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
}
}};
($fmt:expr $(, $($arg:tt)+ )?) => {{
let data = $crate::log::Data::new(
let data = $crate::dev::log::Data::new(
None,
std::any::type_name_of_val(&|| {}),
std::backtrace::Backtrace::capture(),
);
if data.should_log {
$crate::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
$crate::dev::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
};
}};
@ -272,7 +272,7 @@ mod tests {
fn test(&self);
}
struct Logger {}
struct Logger;
impl Loggable for Logger {
fn test(&self) {

View file

@ -2,14 +2,13 @@ use std::{sync, time};
pub mod prelude {
pub use crate::{
log,
log::{Level::*, now},
tlog, write_log,
dev::log::{Level::*, now},
log, tlog, write_log,
};
}
pub mod dev;
pub mod graph;
pub mod log;
pub mod router;
pub mod syntax;

View file

@ -1,6 +1,6 @@
use std::{backtrace, io, panic};
use en::{ONSET, graph::Graph, log, prelude::*, syntax};
use en::{ONSET, dev::log, graph::Graph, prelude::*, syntax};
#[tokio::main]
#[expect(clippy::print_stderr, clippy::print_stdout, clippy::use_debug)]

View file

@ -6,6 +6,7 @@ use axum::{
};
use crate::{
dev::log,
prelude::*,
router::{GlobalState, handlers::raw::make_response},
};
@ -136,6 +137,13 @@ fn load_templates() -> Result<tera::Tera, tera::Error> {
let root = PathBuf::from("templates");
let default_names: Vec<&str> = DEFAULTS.iter().map(|(n, _)| *n).collect();
log!(
DEBUG,
"Reading templates from {}, canonical form {:?}",
root.display(),
root.canonicalize()
);
match fs::read_dir(&root) {
Ok(dir) => {
for file_opt in dir {

View file

@ -224,7 +224,7 @@ impl Lexeme {
impl fmt::Display for Lexeme {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use crate::log::wrap;
use crate::dev::log::wrap;
let properties = if self.last && self.first {
"[S] "

View file

@ -121,7 +121,7 @@ impl Parseable for Anchor {
impl std::fmt::Display for Anchor {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use crate::log::wrap;
use crate::dev::log::wrap;
let wrapped_text = wrap(&self.text);
let display_text = if wrapped_text.is_empty() {

View file

@ -23,7 +23,7 @@ impl Parseable for Literal {
impl std::fmt::Display for Literal {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Literal {}", crate::log::wrap(&self.text))
write!(f, "Literal {}", crate::dev::log::wrap(&self.text))
}
}