282 Commits

Author SHA1 Message Date
Ashley Mannix
518821e0fc prepare for 0.4.17 release 2022-04-29 09:02:57 +10:00
Ashley Mannix
c9049be616 make notes for implementors consistent 2022-04-29 08:42:34 +10:00
Ashley Mannix
c9284a6842 note that Log implementors should call enabled 2022-04-20 20:53:51 +10:00
Marcel Hellwig
3ad4611891
fix markdown links in lib.rs 2022-04-20 11:43:25 +02:00
Julio Merino
3d791f291d Add reference to db_logger
db_logger is a logging implementation that writes log entries to a
database.  At the time of this writing, it supports PostgreSQL and
SQLite via the sqlx crate.
2022-04-12 18:07:44 -07:00
Ashley Mannix
3b243dd2b8 re-export Option to use in macros 2022-03-22 23:44:12 +10:00
Ashley Mannix
4342193c02 prepare for 0.4.16 release 2022-03-22 23:36:24 +10:00
Ashley Mannix
f3b4fde154 prepare for 0.4.15 release 2022-02-23 08:39:45 +10:00
Ashley Mannix
806eb7fbb4 fix up CI 2021-12-30 12:12:22 +10:00
Ashley Mannix
26aef64c46 fix up kv examples 2021-12-23 15:13:42 +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
wendajiang
403f16cffb add some readme to crate doc 2021-12-03 16:27:04 +08:00
piegames
084624a097 fixup! Add Log implementation on foreign types
Removes the Pin implementation again, because of the MSRV of the crate beeing too low
2021-11-17 18:18:55 +01:00
piegames
4a1d48867f Add Log implementation on foreign types
Closes #458. Implements Log for references to loggers, as well as loggers wrapped
in `Arc` or `Pin`. More may be added in the future. Especially, we probably will
want to add a blanket implementation (bounded on `Borrow`) once we have impl
specialization. (Technically, we could probably already do this now, but at the
risk of painting ourselves into a corner.)
2021-11-17 18:17:57 +01:00
KodrAus
d394b0c3c3 just unwrap since they're always valid 2021-11-15 11:00:04 +10:00
KodrAus
0813f35205 fix up level iterators 2021-11-15 10:55:38 +10:00
Ashley Mannix
2d3ecdfe86
Merge pull request #459 from WaDelma/master
Expose logging levels
2021-11-15 10:43:45 +10:00
Delma
05532fabfd Added documentation on the order of iteration 2021-11-05 18:51:42 +02:00
Ashley Mannix
05860c4d83
Merge pull request #420 from DevJac/master
Clarify ordering of log levels in the docs
2021-11-05 22:14:32 +10:00
Ashley Mannix
092aae0298
Merge pull request #461 from Thomasdezeeuw/key-value-macros
Add key-values to the macros
2021-11-05 22:07:55 +10:00
Ashley Mannix
23669956d3
Merge pull request #463 from ibraheemdev/patch-2
relax ordering in `set_max_level` atomic store
2021-11-05 22:07:16 +10:00
Delma
299d3bcb5b Fixed a bug in Level::iter implementation 2021-10-27 18:02:07 +03:00
Delma
0355d570ff Instead of making array public add iterator methods 2021-10-27 17:59:29 +03:00
cherryblossom000
9e5f755a3a
Fix typo in docs
structued -> structured
2021-10-23 16:57:59 +11:00
Ibraheem Ahmed
9cb04d763e
relax ordering in set_max_level atomic store 2021-10-19 18:59:34 -04: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
Delma
a1f1748bfb Make log level names array public 2021-08-27 14:32:49 +03:00
Thomas de Zeeuw
85a3ef6783 Allow use of deprecated atomic::spin_loop_hint
It's replaced by hint::spin_loop, however that has only been stable
since 1.49.0. Since we still support 1.31.0 we can't use it. Once the
MSRV is updated to 1.49 we can use hint::spin_loop.
2021-03-25 10:18:02 +01:00
Ashley Mannix
9d4206770d
Prepare for.0.4.14 release (#447)
* prepare for.0.4.14 release

* update based on value-bag API

* rename to_error to to_borrowed_error

* note method name change in changelog

* update to released value-bag
2021-01-27 13:07:13 +10:00
hyd-dev
2d1a477f5a
Remove the __private_api_log_lit special case
It existed because of code size reasons, but it's incompatible with `format_args_capture`.
2021-01-23 23:57:36 +08:00
Thomas de Zeeuw
16ecfbeeb4 Remove usage of AtomicUsize::compare_exchange
It is going to be deprecated in 1.50, but it's already producing
warnings on nightly.
2021-01-08 13:23:04 +01:00
KodrAus
eff148e459 prepare for 0.4.13 release 2021-01-08 14:24:25 +10:00
DevJac
44310aad68 Clarify ordering of log levels in the docs
It was not clear whether `error` or `trace` was the maximum log level.
The docs said "`error!` represents the _highest_-priority log messages and `trace!` the _lowest_".
Yet, `set_max_level` regards `Trace` to be the maximum level.

I attempted to clarify this by avoiding the terms "high" and "low" in the docs except for where
they are applicable to the Rust order as defined in `Ord`.
2020-12-26 22:16:13 -07:00
KodrAus
4c66a1cefe prepare for 0.4.12 release 2020-12-24 09:07:48 +10:00
Steven Fackler
9a1902dfc6
Merge pull request #413 from alistair23/alistair/atomics
atomics: Add support for targets without atomics
2020-09-22 19:38:37 -04:00
Alistair Francis
3ae52e2729 lib.rs: Add rationale comments
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-22 12:07:01 -07:00
Lionel Faber
b5e9d0182a Implement Log for boxed data types that already implement the Log trait 2020-09-21 20:05:02 +05:30
Alistair Francis
351ee33633 lib: Implement AtomicUsize for platforms without atomics
Some platforms don't provide a AtomicUsize. Instead of just failing to
build with this error:

291 | use std::sync::atomic::{AtomicUsize, Ordering};
    |                         ^^^^^^^^^^^ no `AtomicUsize` in `sync::atomic`

let's instead add a fake AtomicUsize.

As the platform doesn't have atomics we can't implement an Atomic
version of AtomicUsize, so this version is not atomic. Any platform
without atomics is unlikely to have multiple cores, so this shouldn't be
a problem.

This is somewhat based on:
940d2e9d7f

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-14 08:42:09 -07:00
Thomas de Zeeuw
186efede86 Add LevelFilter::as_str 2020-08-24 11:20:25 +02:00
Thomas de Zeeuw
85dad3f61e Add Level::as_str
Returns the string representation of the `Level`.
2020-08-23 19:02:17 +02:00
Ashley Mannix
ee4bc80680 prepare for 0.4.11 release 2020-07-09 09:51:24 +10:00
David Tolnay
f3cce30dff
Resolve possible inference disruption by removing unneeded From impl
This impl breaks some code in rust-analyzer's ra_hir_def crate.

1dba84019e/crates/ra_hir_def/src/path.rs (L273-L307)

    $ cargo check --manifest-path crates/ra_hir_def/Cargo.toml
        Checking ra_hir_def v0.1.0
        Finished dev [unoptimized] target(s) in 0.75s

    $ cargo check --manifest-path crates/ra_hir_def/Cargo.toml --features log/kv_unstable
        Checking ra_hir_def v0.1.0
    error[E0282]: type annotations needed for the closure `fn(&str) -> std::result::Result<(), _>`
       --> crates/ra_hir_def/src/path.rs:278:17
        |
    278 |                 f.write_str("::")?;
        |                 ^^^^^^^^^^^^^^^^^^ cannot infer type
        |
    help: give this closure an explicit return type without `_` placeholders
        |
    276 |         let mut add_segment = |s| -> std::result::Result<(), _> {
        |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020-06-03 19:00:52 -07:00
Joshua Nelson
51562abb06 Document why transmute is sound 2020-04-10 13:23:03 -04:00
Joshua Nelson
0b0a78ccf2 Reduce the scope of unsafe blocks 2020-04-10 13:15:17 -04:00
vallentin
cf1b35aef8 Fixed misspelling 2020-02-11 21:18:50 +01:00
Ashley Mannix
66af8f2d0c refactor coerce into cast
revert to to_ inherent methods
support downcasting erased values
2020-02-03 09:27:54 +10:00
Ashley Mannix
76cb179dec make the get test use borrowed data 2020-01-31 17:33:43 +10:00
Ashley Mannix
6743f4a0d2 make value internal visitor support borrowing 2020-01-31 16:51:44 +10:00
Ashley Mannix
ddb118e466 support coercing Values into primitive types 2020-01-31 12:53:40 +10:00