Git Product home page Git Product logo

Comments (5)

Thomasdezeeuw avatar Thomasdezeeuw commented on July 19, 2024

You can use target for this. See the logging macros and Record.target. Example:

debug!(target: "load-game", "Loading game file: {:?}", game_file);

// In logging
let record: log::Record = // ..
println!("target: {}", record.target());

Note that it defaults to the module name.

Let me know if this does or doesn't work for you.

from log.

radix avatar radix commented on July 19, 2024

@Thomasdezeeuw sorry, maybe I wasn't clear enough. The point of my post is that if I use target, and I want the module name to also be part of the target, I have to write ptrpi::storage::load-game, not just load-game.

from log.

Thomasdezeeuw avatar Thomasdezeeuw commented on July 19, 2024

The point of my post is that if I use target, and I want the module name to also be part of the target, I have to write ptrpi::storage::load-game, not just load-game.

You could combine the module and target in you logging implementation.

Otherwise you can look at logging a separate key-value: https://docs.rs/log/latest/log/kv/index.html. It's officially still unstable, but it hasn't seen any breaking changes in months/years and it's close to stabilising (https://github.com/rust-lang/log/issues/4360).

from log.

radix avatar radix commented on July 19, 2024

I think the kv log approach is probably my best bet, but I couldn't really figure out how to use it in the log crate. In the end I switched to tracing and am using this formulation:

debug!(event="load-snapshot", ?filename);

from log.

Thomasdezeeuw avatar Thomasdezeeuw commented on July 19, 2024

I think the kv log approach is probably my best bet, but I couldn't really figure out how to use it in the log crate. In the end I switched to tracing and am using this formulation:

debug!(event="load-snapshot", ?filename);

For reference you need to enable the kv feature(s), i.e. kv_unstable and likely kv_unstable_std (unless you don't use std), see

log/Cargo.toml

Lines 51 to 54 in b834897

kv_unstable = ["value-bag"]
kv_unstable_sval = ["kv_unstable", "value-bag/sval", "sval", "sval_ref"]
kv_unstable_std = ["std", "kv_unstable", "value-bag/error"]
kv_unstable_serde = ["kv_unstable_std", "value-bag/serde", "serde"]

Then you can use the following:

log::debug!(event="load-snapshot", filename=log::as_debug!(filename));

When logging you can access event and filename in Record::key_values.

We're still discussing whether or not we want to support the ?filename notation as well.

from log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.