Comments (17)
This seems like a pretty great idea! I don't personally have many strong opinions about logging or what direction this library should go in, and I also don't mind deprecating this library as-is (just going into maintenance mode) to make room for another.
Some thoughts:
The log levels are now an enum instead of a u32
This seems like a good idea.
The logging macros don't call enabled before calling log
Some use cases of logging may hurt because of this, but I'd be willing to believe that they're fairly few and somewhat niche.
There is now a single global logger instead of thread-local loggers
This also seems like a good idea.
In addition, it's not totally clear to me that anyone actually wants to have different loggers on different threads
The one use case I know of for this is a unit testing framework where you want to capture each test's output individually. As you mentioned though you can build this on top of a global framework so it's probably not that bad to lose.
The logger may only be initialized once, and isn't torn down when a program exits
The lack of teardown seems somewhat worrying to me, but the one-time initialization is probably fine.
The strategy I'm going to try to take elsewhere is that once atexit
starts running, it's considered a task panic to continue accessing logging. This means that you'll need synchronization around it, but it probably all comes out in the wash.
A logger has to be manually installed
This seems somewhat reasonable. If I've invested time and effort into using a logging infrastructure I'm probably willing to set it up to get it running.
from log.
The lack of teardown seems somewhat worrying to me, but the one-time initialization is probably fine.
The strategy I'm going to try to take elsewhere is that once atexit starts running, it's considered a task panic to continue accessing logging. This means that you'll need synchronization around it, but it probably all comes out in the wash.
Yeah, thinking about it a bit more, you'd definitely want teardown to flush buffers at the very least. I'm not a huge fan of having post-atexit calls panic. Seems like they should just be noops to avoid weird transient failures that are hard to reproduce.
from log.
Adding at_exit cleanup wasn't that bad, though the implementation involves some "interesting" uses of atomics: https://github.com/sfackler/log-ng/commit/0bc99ed5b0e2b0f417257921cda78c5ef3612f7b.
I also don't mind deprecating this library as-is (just going into maintenance mode) to make room for another.
I'd prefer to keep the implementation in the log
crate since it'd be a bummer to burn a good name so quickly. That could mean keeping it in this repo or just transferring ownership on crates.io.
from log.
That's a good point, I wouldn't mind moving this crate more towards a different design, may want to discuss with a few others though :)
from log.
The logging macros don't call enabled before calling log
I would like it if in addition to the dynamic logging level, there was a static logging level -- a compile time choice of what types of logging are even available. This should recover all the niche uses of the old system and impose no burdens the common case.
If cfg!
wasn't used in the logging macros (for the static level) but #[cfg(.,.)]
instead, the logging facade could be unconditionally #[phase(plugin)] extern
d, and conditionally be #[phase(link)] extern
d to completely go away at the most restrictive static logging level.
from log.
A static logging level seems like a great idea. I've been worrying a bit about debug!
and trace!
being tied to ndebug
, but a separate cfg seems like a better way of handling that.
#[cfg(...)]
can't be attached to expressions right now, which would prohibit its use here. cfg!
should be fine, as if cfg!(foo) { stuff }
ends up as if false { stuff }
which is trivially optimized away. In fact, I believe the removal of if false {..}
blocks is one of the very few optimizations performed by rustc itself instead of llvm.
from log.
@Ericson2314 is this something like what you had in mind? https://github.com/sfackler/log-ng/commit/f40621c311ab82af8ded28b79566ccdcec427d99
from log.
Glad you like it!
That's most of it. My thing about cfg!
vs #[cfg(.,.)]
is that in the case where logging is effectively statically disabled, log probably won't get linked in the end, but could anyways. By aggressively using #[cfg(...)]
it might be possible to guarantee log goes away entirely -- and that might be a useful invariant for people distributing proprietary binaries or something.
What do we use ndebug
for currently? If just for debug_assert
and friends, might we remove it altogether now that log is becoming is so much more flexible?
from log.
I believe debug_assert
is the only thing built into the standard distribution that uses ndebug
.
We could potentially do something like this, though it's pretty bizzaro looking:
macro_rules! debug {
($($arg:tt)*) => (
match () {
#[cfg(not(any(log_level = "off",
log_level = "error",
log_level = "warn",
log_level = "info")))]
() => log!(::log_ng::LogLevel::Debug, $($arg)*),
#[cfg(any(log_level = "off",
log_level = "error",
log_level = "warn",
log_level = "info")))]
() => (),
}
)
}
from log.
That's a great trick!
I'm now firmly in scrapping debug_assert. If debug_assert is /used/ by the standard library, not merely defined in it. liblog can be used, and just compiled out for release.
from log.
Keep in mind that debug_assert!
has nothing to do with logging. It's just like assert!
except that it turns into a noop when compiled with ndebug
.
from log.
Well debugging and logging are related, broadly. And having one library to manage all optional sanity checks seems convenient.
from log.
Hmm, I'm trying
#[macro_use] #[no_link]
extern crate log_ng;
#[cfg(any(log_level = "off",
log_level = "error",
log_level = "warn",
log_level = "info",
log_level = "debug"))]
extern crate log_ng;
But it doesn't seem to be working. Perhaps those cfg
s are being resolved in log_ng itself?
from log.
Are you passing one of those to rustc?
from log.
no, but the macros are asking for things in log_ng
.
from log.
The macros expand inline into crates that use them, and that's where the cfg takes effect.
from log.
Oh no. Is there anyway to delay that?
from log.
Related Issues (20)
- Is this possible to make a failable log facade ? HOT 2
- "event" name support? (appending a suffix to the default target instead of replacing it entirely) HOT 5
- 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
- feature request: support the `critical` level defined in the `wasi-logging` spec HOT 1
- Add `critical!` Log Level HOT 1
- Log timestamp not match my timezone. HOT 1
- Release 0.4.22 breaks --all-features CI testing HOT 10
- Custom log levels HOT 3
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.