macro_rules! told_options {
() => {
pub fn console(mut self, format: $crate::console::Format) -> Self {
self.told.format = Some(format);
self
}
pub fn time(mut self, time: $crate::console::Time) -> Self {
self.told.time = time;
self
}
pub fn hide_stream(mut self) -> Self {
self.told.hide_stream = true;
self
}
pub fn to(mut self, out: impl std::io::Write + Send + 'static) -> Self {
self.told.to = Some(Box::new(out));
self
}
pub fn redact<S: AsRef<str>>(mut self, names: impl IntoIterator<Item = S>) -> Self {
self.told.redact.extend(names.into_iter().map(|name| name.as_ref().to_owned()));
self
}
pub fn keep_url_passwords(mut self) -> Self {
self.told.keep_url_passwords = true;
self
}
pub fn replace(mut self, replace: impl Fn(&str, &str) -> Option<String> + Send + Sync + 'static) -> Self {
self.told.replace = Some(std::sync::Arc::new(replace));
self
}
pub fn source(mut self) -> Self {
self.told.source = true;
self
}
pub fn env(mut self, prefix: &str) -> Self {
self.told.env = Some($crate::console::Environment { prefix: prefix.to_owned(), ..Default::default() });
self
}
pub fn no_env(mut self) -> Self {
self.told.env = None;
self
}
};
}
#[allow(unused_imports, reason = "a store's logger takes them; the console alone has none")]
pub(crate) use told_options;
mod env;
#[cfg(test)]
pub(crate) mod fixture;
mod layer;
mod line;
mod redact;
mod terminal;
pub use layer::{Layer, Replace};
pub use line::Time;
pub use redact::SECRETS;
#[doc(hidden)]
pub use line::{escaped, lines_of, push_below};
pub(crate) use env::Environment;
#[cfg(all(feature = "records", feature = "config"))]
pub(crate) use env::{FORMATS, LEVELS, TIMES};
#[cfg(all(test, feature = "records", feature = "config"))]
pub(crate) use layer::Declared;
#[allow(unused_imports, reason = "a store's logger takes them; the console alone has none")]
pub(crate) use layer::{Console, Keep, Told, own_line};
#[allow(unused_imports, reason = "a store's logger takes them; the console alone has none")]
pub(crate) use line::{Line, object_pairs, quoted};
pub fn colors(stream: &impl std::io::IsTerminal) -> bool {
env::colors(stream.is_terminal(), layer::real)
}
pub fn logger(stream: &str) -> LoggerBuilder {
LoggerBuilder { stream: stream.to_owned(), told: Told::default() }
}
pub struct LoggerBuilder {
stream: String,
told: Told,
}
impl std::fmt::Debug for LoggerBuilder {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LoggerBuilder").field("stream", &self.stream).finish()
}
}
impl LoggerBuilder {
pub fn level(mut self, level: tracing::Level) -> Self {
self.told.level = Some(level);
self
}
told_options!();
pub fn layer(self) -> Layer {
Layer::new(std::sync::Arc::new(Console::new(&self.stream, self.told)), None)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Format {
Pretty,
Json,
Off,
}
#[cfg(test)]
#[path = "vectors_tests.rs"]
mod tests;