Logger implementations commonly need to convert a `Record` into a
non-borrowed form to e.g. log it asynchronously on a separate thread.
This allows them to avoid having to allocate owned `String`s for the
module path and file fields, which will in practice almost always be
`'static`.
cc #206
* refactor Value internals to avoid needing to buffer
that means doing two things:
1. allowing us to create a value with any lifetime from some owned
primitive, like u8, bool etc
2. allowing us to create a value from some type that _can_ produce
a concrete value we can use, but doesn't guarantee it will live as
long as the value itself
* add test for Fill
This mirrors a similar commit fe073054a0999d1bb238cb0293757741e95b3588
that changed output for Level, it seems sensible if the user wishes to
output the logging filter level to afford the same formatting choices.
The log! macro matches part of its arguments as $($arg:tt)+, but the other
macros match it as $($arg:tt)*. That means if a user calls error!() or any of
the other macros with an empty argument, it successfully matches the macro rules
of the first macro they called but then turns into an invalid call to log!,
leading to a confusing error message.
This PR uses $($arg:tt)+ consistently to match arguments.
Example:
use log::error;
fn main() {
error!();
}
Before:
error: expected identifier, found `,`
--> src/main.rs:4:5
|
4 | error!();
| ^^^^^^^^^
| |
| expected identifier
| help: remove this comma
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
After:
error: unexpected end of macro invocation
--> src/main.rs:4:5
|
4 | error!();
| ^^^^^^^^^ missing tokens in macro arguments
ATOMIC_USIZE_INIT was deprecated in rust 1.34. Silence the deprecation
warning until our MSRV >= 1.24, where we can use the replacement const
fn `AtomicUsize::new`
github: fixes#320
This fixes the following error when using Rust 2018 style macro imports.
use log::info;
fn main() {
info!("...");
}
error: cannot find macro `log!` in this scope
--> src/main.rs:4:5
|
4 | info!("...");
| ^^^^^^^^^^^^^
The `local_inner_macros` modifier resolves all macro invocations made
from within that macro as macros in the same crate. So if `info!`
expands to an invocation of `log!` then this would be resolved as
`$crate::log!` rather than requiring the caller to have `log` in scope.
The attribute is ignored by pre-2018 compilers so log will continue to
work as normal with #[macro_use].
In the future when dropping compatibility with pre-2018 compilers we can
remove the `local_inner_macros` modifier and use our own explicit
`$crate::` prefixes on invocations of local macros.
If `set_logger_inner` is called while `STATE` is `INITIALIZING`, make it
wait until the `STATE` is `INITIALIZED` so that callers can assume that
the logging state is fully initialized after a call to
`set_logger_inner`.
The extra work involved in loading the logger and creating the record
struct involves move codegen than is necessary if we take this kind of
approach (which we previously used in 0.3). It's a bit unfortunate to
have these public-but-not-public functions, but I think it's worth it.
We want to minimize the footprint of logging so people feel comfortable
using it!
A main function containing nothing but `warn!("hello world")` shrinks
from 204 bytes to 124 bytes in x86_64 with this change.
Closes#275
This is required by some deserializers which deserialize identifiers using their binary representation.
This implementation should be equivalent to what serde derive would implement.