#learning `tracing`

22 messages · Page 1 of 1 (latest)

humble terrace
#
#[derive(Debug)]
struct MyType(SocketAddr);

impl serde::Serialize for MyType {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_newtype_struct("MyType", &self.0)
    }
}
#

the error I'm getting is something like, "type doesn't implement tracing::Value"

#

but this appears to be a sealed trait

cinder torrent
#

Implementing Debug should be enough. Value has the necessary blanket impl.
Do you need to Serialize for some other purpose than tracing? Because if not, just implement Debug directly.

humble terrace
cinder torrent
#

I'd implement Debug manually and leverage Serialize by encoding to String

humble terrace
#

but that doesn't give me correct output

#

I don't want a string with a JSON serialized object inside, I just want that object

#

it almost feels like I just need to access the members separately rather than being able to pass the struct to the macros

#

which is annoying

cinder torrent
#

Why did you bring up Serialize then? Just implement Debug with whatever you want to show

#

Ah.. it's slowly sinking in

#

Manually implement Debug and serialize the members

#

So yes, if "the macros" means the derive part, you are right. Can't use it to get exactly what you want.

#

But tracing macros should work once you took care of Debug

humble terrace
humble terrace
#
{"timestamp":"2023-03-05T01:18:39.114144Z","level":"INFO","fields":{"server":"Server(Server { socket_addr: 127.0.0.1:5502 }, 127.0.0.1:5502)"},"target":"server"}
cinder torrent
#

Do you know what I meant when I said "manually implement Debug"?

humble terrace
#

do you know what "I don't want JSON in a string" meant?

cinder torrent
#

wow okay let's stop here. It was an honest question meant to help.