Skip to content
Snippets Groups Projects
Commit f98bfbbd authored by Jason Volk's avatar Jason Volk
Browse files

add string stream convenience util; add ?Sized bounds on log fmt functors


Signed-off-by: default avatarJason Volk <jason@zemos.net>
parent e9ab5484
No related branches found
No related tags found
1 merge request!545Admin command tracing capture
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
pub fn html<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> pub fn html<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()>
where where
S: Write, S: Write + ?Sized,
{ {
let color = color::code_tag(level); let color = color::code_tag(level);
let level = level.as_str().to_uppercase(); let level = level.as_str().to_uppercase();
...@@ -19,7 +19,7 @@ pub fn html<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> ...@@ -19,7 +19,7 @@ pub fn html<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()>
pub fn markdown<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> pub fn markdown<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()>
where where
S: Write, S: Write + ?Sized,
{ {
let level = level.as_str().to_uppercase(); let level = level.as_str().to_uppercase();
writeln!(out, "`{level:>5}` `{span:^12}` `{msg}`")?; writeln!(out, "`{level:>5}` `{span:^12}` `{msg}`")?;
...@@ -29,7 +29,7 @@ pub fn markdown<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result< ...@@ -29,7 +29,7 @@ pub fn markdown<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<
pub fn markdown_table<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> pub fn markdown_table<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()>
where where
S: Write, S: Write + ?Sized,
{ {
let level = level.as_str().to_uppercase(); let level = level.as_str().to_uppercase();
writeln!(out, "| {level:>5} | {span:^12} | {msg} |")?; writeln!(out, "| {level:>5} | {span:^12} | {msg} |")?;
...@@ -39,7 +39,7 @@ pub fn markdown_table<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> R ...@@ -39,7 +39,7 @@ pub fn markdown_table<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> R
pub fn markdown_table_head<S>(out: &mut S) -> Result<()> pub fn markdown_table_head<S>(out: &mut S) -> Result<()>
where where
S: Write, S: Write + ?Sized,
{ {
write!(out, "| level | span | message |\n| ------: | :-----: | :------- |\n")?; write!(out, "| level | span | message |\n| ------: | :-----: | :------- |\n")?;
......
...@@ -30,6 +30,16 @@ macro_rules! is_format { ...@@ -30,6 +30,16 @@ macro_rules! is_format {
}; };
} }
#[inline]
pub fn collect_stream<F>(func: F) -> Result<String>
where
F: FnOnce(&mut dyn std::fmt::Write) -> Result<()>,
{
let mut out = String::new();
func(&mut out)?;
Ok(out)
}
#[inline] #[inline]
#[must_use] #[must_use]
pub fn camel_to_snake_string(s: &str) -> String { pub fn camel_to_snake_string(s: &str) -> String {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment