Skip to content

Commit

Permalink
Update to log's stable kv feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Mar 4, 2024
1 parent eff67f4 commit e32b372
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ timestamp = []
nightly = []

[dependencies]
log = { version = "0.4.16", default-features = false, features = ["kv_unstable_std"] }
log = { version = "0.4.21", default-features = false, features = ["kv_std"] }
itoa = { version = "1.0.1", default-features = false }
ryu = { version = "1.0.5", default-features = false }

Expand Down
7 changes: 5 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn log_panic(info: &std::panic::PanicInfo<'_>) {
let backtrace = Backtrace::force_capture();

let key_values = [
("backtrace", kv::Value::capture_display(&backtrace)),
("backtrace", kv::Value::from_display(&backtrace)),
("thread_name", kv::Value::from(thread_name)),
];
let key_values = key_values.as_slice();
Expand Down Expand Up @@ -195,7 +195,10 @@ fn log_panic(info: &std::panic::PanicInfo<'_>) {
pub struct NoKvs;

impl kv::Source for NoKvs {
fn visit<'kvs>(&'kvs self, _: &mut dyn log::kv::Visitor<'kvs>) -> Result<(), log::kv::Error> {
fn visit<'kvs>(
&'kvs self,
_: &mut dyn log::kv::VisitSource<'kvs>,
) -> Result<(), log::kv::Error> {
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions src/format/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fmt::{self, Write};
use std::io::IoSlice;

use log::kv::value::Visit;
use log::kv::{VisitSource, VisitValue};
use log::{kv, Record};

#[cfg(feature = "timestamp")]
Expand Down Expand Up @@ -153,7 +153,7 @@ fn line(buf: &Buffer) -> &[u8] {
/// `"user_name":"Thomas","user_id":123,"is_admin":true`.
pub(super) struct KeyValueVisitor<'b>(pub(super) &'b mut Vec<u8>);

impl<'b, 'kvs> kv::Visitor<'kvs> for KeyValueVisitor<'b> {
impl<'b, 'kvs> VisitSource<'kvs> for KeyValueVisitor<'b> {
fn visit_pair(&mut self, key: kv::Key<'kvs>, value: kv::Value<'kvs>) -> Result<(), kv::Error> {
self.0.push(b',');
self.0.push(b'"');
Expand All @@ -164,7 +164,7 @@ impl<'b, 'kvs> kv::Visitor<'kvs> for KeyValueVisitor<'b> {
}
}

impl<'b, 'v> Visit<'v> for KeyValueVisitor<'b> {
impl<'b, 'v> VisitValue<'v> for KeyValueVisitor<'b> {
fn visit_any(&mut self, value: kv::Value) -> Result<(), kv::Error> {
self.0.push(b'\"');
Buf(self.0)
Expand Down
6 changes: 3 additions & 3 deletions src/format/logfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fmt::{self, Write};
use std::io::IoSlice;

use log::kv::value::Visit;
use log::kv::{VisitSource, VisitValue};
use log::{kv, Record};

#[cfg(feature = "timestamp")]
Expand Down Expand Up @@ -142,7 +142,7 @@ fn line(buf: &Buffer) -> &[u8] {
/// `user_name="Thomas" user_id=123 is_admin=true`
struct KeyValueVisitor<'b>(&'b mut Vec<u8>);

impl<'b, 'kvs> kv::Visitor<'kvs> for KeyValueVisitor<'b> {
impl<'b, 'kvs> VisitSource<'kvs> for KeyValueVisitor<'b> {
fn visit_pair(&mut self, key: kv::Key<'kvs>, value: kv::Value<'kvs>) -> Result<(), kv::Error> {
self.0.push(b' ');
Buf(self.0).extend_from_slice(key.as_str().as_bytes());
Expand All @@ -151,7 +151,7 @@ impl<'b, 'kvs> kv::Visitor<'kvs> for KeyValueVisitor<'b> {
}
}

impl<'b, 'v> Visit<'v> for KeyValueVisitor<'b> {
impl<'b, 'v> VisitValue<'v> for KeyValueVisitor<'b> {
fn visit_any(&mut self, value: kv::Value) -> Result<(), kv::Error> {
self.0.push(b'\"');
Buf(self.0)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
//! request!(
//! url = req.url,
//! status = req.status,
//! response_time = log::as_debug!(req.response_time);
//! response_time:? = req.response_time;
//! "HTTP request"
//! );
//! }
Expand Down
5 changes: 4 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ where
("key2e", &true),
("key2f", &false),
("key2g", &'c'),
("key2\"g", &(&MyDisplay as &dyn fmt::Display)),
(
"key2\"g",
&(&log::kv::Value::from_display(&MyDisplay) as &dyn kv::ToValue),
),
];
let kvs: &dyn kv::Source = &kvs;
let record2 = Record::builder()
Expand Down

0 comments on commit e32b372

Please sign in to comment.