summaryrefslogtreecommitdiff
path: root/examples/common
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2023-04-10 08:57:22 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2023-04-10 08:57:22 +0900
commite09dd45244e56e863482b7bef30617fd0c692105 (patch)
treef24f806cbe1b8c2c937f16a9f591aa5179789449 /examples/common
downloadrust-slog-e09dd45244e56e863482b7bef30617fd0c692105.tar.gz
rust-slog-e09dd45244e56e863482b7bef30617fd0c692105.tar.bz2
rust-slog-e09dd45244e56e863482b7bef30617fd0c692105.zip
Import slog 2.7.0upstream/2.7.0upstream
Diffstat (limited to 'examples/common')
-rw-r--r--examples/common/mod.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/common/mod.rs b/examples/common/mod.rs
new file mode 100644
index 0000000..b83755d
--- /dev/null
+++ b/examples/common/mod.rs
@@ -0,0 +1,36 @@
+use slog::*;
+use std::{fmt, result};
+
+pub struct PrintlnSerializer;
+
+impl Serializer for PrintlnSerializer {
+ fn emit_arguments(&mut self, key: Key, val: &fmt::Arguments) -> Result {
+ print!(", {}={}", key, val);
+ Ok(())
+ }
+}
+
+pub struct PrintlnDrain;
+
+impl Drain for PrintlnDrain {
+ type Ok = ();
+ type Err = ();
+
+ fn log(
+ &self,
+ record: &Record,
+ values: &OwnedKVList,
+ ) -> result::Result<Self::Ok, Self::Err> {
+
+ print!("{}", record.msg());
+
+ record
+ .kv()
+ .serialize(record, &mut PrintlnSerializer)
+ .unwrap();
+ values.serialize(record, &mut PrintlnSerializer).unwrap();
+
+ println!("");
+ Ok(())
+ }
+}