Commit Graph

41 Commits

Author SHA1 Message Date
KodrAus
bb111eb90d add a macro test with common types 2022-04-20 16:27:06 +10:00
Ashley Mannix
06380b99cd fully qualify Type import for MSRV 2022-03-22 23:52:16 +10:00
Thomas de Zeeuw
0b90513e65 Fully qualify Some and None 2022-03-22 14:01:09 +01:00
Thomas de Zeeuw
c626f82520 Support static string as key value 2022-02-26 12:28:43 +01:00
Ashley Mannix
26aef64c46 fix up kv examples 2021-12-23 15:13:42 +10:00
Ashley Mannix
699afffdc0 revert requirement for target = in kv macros 2021-12-23 15:07:25 +10:00
KodrAus
505c255f0a try putting attribute on fn 2021-12-12 11:20:05 +10:00
KodrAus
7ed6401b93 run fmt 2021-12-12 11:13:26 +10:00
KodrAus
d6e44eb253 add an expr test to macros 2021-12-12 11:02:50 +10:00
KodrAus
13b9dbcef1 add a different prop type to macro tests 2021-12-12 11:00:46 +10:00
KodrAus
77667f5436 move implicit arg tests into module 2021-12-12 10:57:45 +10:00
Ashley Mannix
62c6607b25 allow macros to be more consistent with kvs 2021-12-07 22:48:47 +10:00
Ashley Mannix
77ae39bfc7 fix up some links and tests 2021-12-07 20:05:11 +10:00
KodrAus
c68890197d fix tests when running with --all-features 2021-11-15 16:59:00 +10:00
Thomas de Zeeuw
e49f063235 Add key-values to the macros
Attempt number two/three? Too many in any case.

Previously I proposed a design that followed a `struct` like syntax:

```rust
info!("my message: {}", arg, {
    key1: "value1",
    key2: 123,
});
```

However it turns out that this does not work well with named arguments
as reported in issues #369 and #372. The implementation was eventually
reverted in pr #374.

This new design takes inspiration from the `tracing` crate which already
supports key-value pairs in logging events. The basic idea is to put the
key-value pairs before the message and arguments. Applying the same
structure like syntax as above we would get something like the
following.

```rust
info!({
    key1: "value1",
    key2: 123,
}, "my message: {}", arg);
```

But personally I'm not a big fan of this formatting, let's try putting
everything on a single line instead.

```rust
info!({ key1: "value1", key2: 123 }, "my message: {}", arg);
```

A little better, but at this point the structure like syntax is really
more annoying then helpful. So, instead I've done away it, opting
instead use the following syntax.

```rust
info!(key1 = "value1", key2 = 123, "my message: {}", arg);
```

Two major differences:
 * Removed the brackets.
 * Colons (`:`) are replaced with equal/assignment signs (`=`).

This gives us syntax similar to variable assignment.

But then we run in some limitations of the macro syntax, specifically
that `expr` fragments aren't allowed after `expr` fragments. To fix this
I went with the easiest option of changing the last comma (`,`) after
the key-value pairs to a semicolon (`;`). Making the final syntax look
like the following.

```rust
info!(key1 = "value1", key2 = 123; "my message: {}", arg);
info!(target: "my_target", key1 = "value1", key2 = 123; "my message: {}", arg);
log!(target: "my_target", log::Level::Info, key1 = "value1", key2 = 123; "my message: {}", arg);
```

Which, in my opinion and all things considered, it's too bad looking.
2021-08-29 14:22:22 +02:00
Ashley Mannix
0e78c11b40
Run tests in our MSRV (#427) 2020-12-21 16:44:59 +10:00
Ashley Mannix
c3a9a14c58 revert to old macro impl for now 2019-12-19 07:15:14 +10:00
Ashley Mannix
bb0224c120 add test for named format args 2019-12-19 07:11:56 +10:00
Ashley Mannix
1a7ffda379 fix up macro use in expr context 2019-12-16 10:09:37 +10:00
Mathias Svensson
454b3079d5 Run cargo fix 2019-12-10 11:41:36 +01:00
Mathias Svensson
299d1d5c16 Use Box::leak to get rid of some unsafe code 2019-12-10 11:36:36 +01:00
Yoshua Wuyts
6ad361009e
remove named tests
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-11-09 11:23:49 +01:00
Yoshua Wuyts
40b7f3b7b1
better macro names
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-11-09 11:23:49 +01:00
Yoshua Wuyts
debccc4913
update macro tests
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-11-09 11:23:49 +01:00
Yoshua Wuyts
6dab6ffb54
push broken test
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-11-09 11:23:49 +01:00
Yoshua Wuyts
7f2387d7db
add test & fix breakage
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-11-09 11:23:49 +01:00
David Tolnay
ce64c06a37
Format with rustfmt 2019-02-14 2019-03-09 16:15:10 -08:00
David Kellum
9b48836440 Move max_level_features project out of tests to avoid warning
fixes: #270
2019-02-01 16:35:01 -08:00
Steven Fackler
b1b5196775 Remove MaxLevelFilter in favor of a simple function
Closes #243
2017-12-05 21:22:22 -08:00
Steven Fackler
dc11b85c07 Restructure initialization setup
try_set_logger_raw is now set_logger and try_set_logger is now
set_boxed_logger. The use_std feature is now disabled by default. The
old set_logger has been removed.

When we did the crate evaluation for log, we wanted to add more variants
of set_logger that e.g. panicked by default, but I'm no longer convinced
that's a good idea. There are going to be very few instances of actually
calling these methods explicitly, since each logger implementation
should be providing their own init method that calls them. Having a huge
constellation of functions that all do basically the same thing just
makes things really confusing. We also don't want to encourage logger
implementations to only provide an init function that panics because a
common way of working with logging in tests is to try to init the system
in each test and ignore the result.
2017-09-30 21:31:07 -07:00
Alisha
308e6f33d6 Change set_logger_raw to try_set_logger_raw 2017-08-18 00:56:29 +10:00
dan pittman
44bbdbd93b
removes shutdown and adds flush to Log trait.
Signed-off-by: dan pittman <danielscottt@gmail.com>
2017-07-17 08:38:02 -07:00
Alisha
a1e0bcacef set_logger panics on error 2017-06-22 10:53:05 +10:00
David Tolnay
473aa60a92
Run rustfmt 2017-05-29 20:58:11 -07:00
David Tolnay
07d3e7df6e
Disable publishing the breaking changes 2017-05-23 16:18:55 -07:00
Ottavio Hartman
d4748011fa Removed "stuttering" of types, like LogLevel -> Level.
The affected enums, structs, and functions include:
- LogLevel
- LogLevelFilter
- LogRecord
- LogMetadata
- LogLocation
- MaxLogLevelFilter (now MaxLevelFilter)
- max_log_level (now max_level)
2017-05-21 20:43:59 -04:00
Amanieu d'Antras
2644916237 Add support for no_std 2016-01-14 23:55:22 +00:00
Matt Brubeck
737f8ecbfa Test the max_level features 2015-10-08 13:46:15 -07:00
Alex Crichton
c8ffc91a1a Fix tests for rust master 2015-04-02 09:40:03 -07:00
Steven Fackler
207e329267 Encapsulate data passed to Log::enabled
We may want to add things to the information provided to `log` and
`enabled`. slf4j provides the ability to pass `Marker` objects when
logging which can be used for more advanced filtering for example.
2015-03-07 22:34:39 -08:00
Alex Crichton
443249e382 Fix typo in trace! macro
Closes #19
2015-02-09 12:23:12 -08:00