Comments (5)
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.
@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.
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 justload-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.
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.
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
Lines 51 to 54 in b834897
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)
- Is it possible to reset the global logger after the program initiates the global logger HOT 8
- Release a new version? HOT 1
- Building failed on x86_64-pc-windows-msvc nightly HOT 4
- Version `0.4.19` breaks build for target `thumbv4t-none-eabi` HOT 9
- Couldn't compile for Android(`aarch64-linux-android`) HOT 1
- Is this possible to make a failable log facade ? HOT 2
- Derive `Deserialize` for `Level` HOT 1
- How do I set log level in Windows (Powershell)? HOT 3
- Is it possible to group logs? HOT 2
- Add tests that check the line numbers HOT 2
- The design of kV is not concise enough, I have a simple suggestion. HOT 2
- Surprising error when using `enabled` method in logger HOT 4
- Setting the file/line shown in a log message HOT 8
- ANSI escape sequences - Code injection HOT 4
- Feature suggestion: fatal log level with fatal! macro HOT 3
- log crate catches Clion stop signal HOT 2
- Release a build with `kv` support HOT 4
- Allow constructing LevelFilter via incrementation HOT 9
- Add log level fatal/critical HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log.