summaryrefslogtreecommitdiffstats
path: root/vendor/env_logger/examples/direct_logger.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/env_logger/examples/direct_logger.rs')
-rw-r--r--vendor/env_logger/examples/direct_logger.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/env_logger/examples/direct_logger.rs b/vendor/env_logger/examples/direct_logger.rs
new file mode 100644
index 0000000..4d7f39d
--- /dev/null
+++ b/vendor/env_logger/examples/direct_logger.rs
@@ -0,0 +1,39 @@
+/*!
+Using `env_logger::Logger` and the `log::Log` trait directly.
+
+This example doesn't rely on environment variables, or having a static logger installed.
+*/
+
+use env_logger::{Builder, WriteStyle};
+
+use log::{Level, LevelFilter, Log, MetadataBuilder, Record};
+
+fn record() -> Record<'static> {
+ let error_metadata = MetadataBuilder::new()
+ .target("myApp")
+ .level(Level::Error)
+ .build();
+
+ Record::builder()
+ .metadata(error_metadata)
+ .args(format_args!("Error!"))
+ .line(Some(433))
+ .file(Some("app.rs"))
+ .module_path(Some("server"))
+ .build()
+}
+
+fn main() {
+ let stylish_logger = Builder::new()
+ .filter(None, LevelFilter::Error)
+ .write_style(WriteStyle::Always)
+ .build();
+
+ let unstylish_logger = Builder::new()
+ .filter(None, LevelFilter::Error)
+ .write_style(WriteStyle::Never)
+ .build();
+
+ stylish_logger.log(&record());
+ unstylish_logger.log(&record());
+}