estk / log4rs Goto Github PK
View Code? Open in Web Editor NEWA highly configurable logging framework for Rust
License: Apache License 2.0
A highly configurable logging framework for Rust
License: Apache License 2.0
I tryed this toml log4rs config:
[appenders.stderr]
kind = "console"
target = "stderr"
encoder = { pattern = "STDERR {d(%Y-%m-%d %H:%M:%S)} {T} {l} {m}{n}" }
But log4rs can not recognise that target.
So could you help me for this? Thank you!
It would be nice if we could init log4rs with a file in the crate.
It exists "std::include_str!" to get the content of a file then log4rs could read it. I know that it is possible to configure it by code by building the config ourself, but would be useful to just add a yaml file to my crate and init log4rs with it.
Does it make sense ?
Thanks
Why did you drop TOML configuration format? Will it come back anytime soon?
Hi! It seems like log4rs uses mut self
for many of the config builder methods (such as .appender
). It seems that it is preffered to use &mut self
for builders: https://aturon.github.io/ownership/builders.html#non-consuming-builders-(preferred):
Is it somehow possible to embed the log4rs configuration inside of a "main" configuration file? Perhaps an API that takes a YAML dictionary, TOML table or JSON object and returns a Config
? I think it should be possible by serializing to a temporary file and calling init_file
on the temporary file, but it's a little bit unwieldy. Alternatively I guess I could mimic log4rs' internal deserialization behaviour but that seems quite tricky and not very robust.
The only formatter that the pattern encoder supports which affects text style is highlight
, which colors based on the log level. It should be possible to also set the text style to some specific configuration, but I'm not sure what syntax would make sense here, particularly in a way that would allow for full configuration of text color, background color, and text intensity.
I am currently doing some development with the amethyst game engine in which all of the amethyst configuration is done via Ron files. They currently use fern internally unless another logger is specified, I would rather use log4rs and would like it if my logging was configured the same way as the rest of the application via Ron files.
Would it be acceptable to add a feature to support the Ron format? If yes I am willing to try and implement this.
Can you return Config struct after read log config from file? If so, I can cache this struct and don't have to read file every times. More over, I can change log config on the fly.
Unlike in Java, it won't be inherited by child threads, but that seems fine IMO since you're probably caching threads between requests anyways.
Hello (: I've been playing around with log4rs, and there's some unexpected behavior: When the specified config file doesn't exist, log4rs panics instead of returning an Err
Result
variant. The panic message is the usual "file not found" Rust message: No such file or directory (os error 2)
.
This is on log4rs version 0.3.3.
Thanks!
In your docs, you write:
//! An appender takes a log record and logs it somewhere, for example, to a file, the console, or the syslog.
Are there any docs on how to actually log to syslog? Is a custom appender required for that? Could a syslog appender be included in the crate or in a 3rd party crate?
log4rs fails to compile under 1.30.0-nightly-x86_64-pc-windows-msvc. Errors below:
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\file.rs:25:1
|
25 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\console.rs:24:1
|
24 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\rolling_file\policy\compound\roll\delete.rs:16:1
|
16 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\rolling_file\policy\compound\roll\fixed_window.rs:17:1
|
17 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\rolling_file\policy\compound\trigger\size.rs:21:1
|
21 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\rolling_file\policy\compound\mod.rs:24:1
|
24 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0658]: The attribute serde
is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> C:\Users\jadun.cargo\registry\src\github.com-1ecc6299db9ec823\log4rs-0.8.0\src\append\rolling_file\mod.rs:46:1
|
46 | #[serde(deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
See clap-rs/clap#747 for more information.
serde_yaml 0.5 implements a change that breaks clap-rs. log4rs allows serde_yaml <0.6. As 0.5 has the potential to break things, I'd like to request the dependency be changed to <0.5.
A local compilation with the change works fine for my project and clap-rs.
If bracelets are used anywhere around a placeholder, out of memory error occurs, for example ({m})
or ({m} {l})
.
I've got sample setting as below,
# Scan this file for changes every 30 seconds
refresh_rate: 30 seconds
appenders:
journey-service:
kind: rolling_file
path: "logs/journey-service.log"
policy:
kind: compound
trigger:
kind: size
limit: 50mb
roller:
kind: fixed_window
base: 1
count: 5
root:
level: info
appenders:
- journey-service
but I keep getting the following error
log4rs: error deserializing component: no appender deserializer for kind
rolling_file registered
Why does it not recognize rolling_file kind? I took this config for rolling_file from your test in RollingFileAppenderDeserializer Any ideas please?
In relation to the discussion here #22, there actually is still a problem with escaping braces. With current implementation this is impossible:
{((({f}:{L}))):30.30}
This should print something like (src/main.rs:111)
padded to 30 spaces. However with current escaping by doubling of braces it is not possible to escape (
at the beginning of padding expression (..):30.30
, since the first two braces ((
are interpreted as an escaped (
instead of group opening brace, followed by an escaped brace ((
.
Also there is a bug with parsing the last three braces )))
in the above expression, it complains about unbalanced }
when the expression is correct.
IMHO the simplest solution would seem to be using backslash for escaping (or any other marker, maybe %
?), as braces doubling cannot work correctly with nesting. If agreed upon I am happy to submit a fix in PR.
This alternative escaping could coexist with current implementation, to solve cases like the one above.
I've been running a process into a | tee logfile
; sending SIGINT
will close everything down, but log4rs prints a bunch of this to stdout at that point:
log4rs: Broken pipe (os error 32)
log4rs: Broken pipe (os error 32)
log4rs: Broken pipe (os error 32)
log4rs: Broken pipe (os error 32)
log4rs: Broken pipe (os error 32)
This is on macOS and a few months old version of log4rs; haven't tested a newer version or different OS.
Hi. I am getting log4rs compilation error when try to run my project Here are details:
Compiling log4rs v0.3.2
INFO:cargo::ops::cargo_rustc::job_queue: start: log4rs v0.3.2 LibraryTests
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at LibraryTests for log4rs v0.3.2
INFO:cargo::ops::cargo_rustc::job_queue: start: toml v0.1.20 BinaryTests
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at BinaryTests for toml v0.1.20
INFO:cargo::ops::cargo_rustc::job_queue: start: toml v0.1.20 Binaries
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at Binaries for toml v0.1.20
INFO:cargo::ops::cargo_rustc::job_queue: end: log4rs v0.3.2 LibraryTests
INFO:cargo::ops::cargo_rustc::job_queue: end: toml v0.1.20 BinaryTests
INFO:cargo::ops::cargo_rustc::job_queue: end: toml v0.1.20 Binaries
INFO:cargo::ops::cargo_rustc::job_queue: start: toml v0.1.20 End
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at End for toml v0.1.20
INFO:cargo::ops::cargo_rustc::job_queue: end: toml v0.1.20 End
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/toml/mod.rs:374:77: 374:90 error: type `collections::vec::Vec<&collections::string::String>` does not implement any method in scope named `connect`
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/toml/mod.rs:374 Err(Box::new(StringError(format!("Unknown keys: {}", remaining_keys.connect(", ")))))
^~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:26: 2:57 note: expansion site
<std macros>:1:1: 2:61 note: in expansion of format!
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/toml/mod.rs:374:34: 374:91 note: expansion site
error: aborting due to previous error
INFO:cargo::ops::cargo_rustc::job_queue: end: log4rs v0.3.2 Libraries
Build failed, waiting for other jobs to finish...
DEBUG:cargo::ops::cargo_rustc::fingerprint: appending /home/devalentino/projects/rust/openrtb/target/debug/.fingerprint/cookie-06b0342919872728/dep-lib-cookie <- /home/devalentino/projects/rust/openrtb
DEBUG:cargo::ops::cargo_rustc::fingerprint: write fingerprint: /home/devalentino/projects/rust/openrtb/target/debug/.fingerprint/cookie-06b0342919872728/lib-cookie
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.3.14 7423feedc5f2a887 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.2 8214dd728a11c371 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.2.34 e60c956de63d26f6 ["05ccb2a72b7547d5", "f93ac7e74187cdc1"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.3.14 7423feedc5f2a887 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.6 6fe09e092fa3838b []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.25 76efb3eb5cc29dff ["ea4a549311910034"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.6 6fe09e092fa3838b []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.10 978ee0dc69fc4e6e []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.1 4fbc2bae715ccce9 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.6 6fe09e092fa3838b []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.6.2 185cd752317b7abe ["ea4a549311910034"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.6.2 eb5510b5d1ad7ab2 ["dce1fa589358bc50", "e7065a134174c680", "ea4a549311910034", "faed0217340356ff"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.20 8ef42cf21841b54b ["63b96739f04ead7d", "f6dd208fd71b79d0", "f93ac7e74187cdc1", "f99656e7cca1ae95"]
DEBUG:cargo: handle_error; err=CliError { error: ChainedError { error: Could not compile `log4rs`., cause: Process didn't exit successfully: `rustc /root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/lib.rs --crate-name log4rs --crate-type lib -g -C metadata=c62ee90dc8e506be -C extra-filename=-c62ee90dc8e506be --out-dir /home/devalentino/projects/rust/openrtb/target/debug/deps --emit=dep-info,link -L dependency=/home/devalentino/projects/rust/openrtb/target/debug/deps -L dependency=/home/devalentino/projects/rust/openrtb/target/debug/deps --extern log=/home/devalentino/projects/rust/openrtb/target/debug/deps/liblog-54cf393d3c69686f.rlib --extern time=/home/devalentino/projects/rust/openrtb/target/debug/deps/libtime-e758cbe877e9589d.rlib --extern toml=/home/devalentino/projects/rust/openrtb/target/debug/deps/libtoml-e4d393d734aaa578.rlib -Awarnings -L native=/home/devalentino/projects/rust/openrtb/target/debug/build/time-e758cbe877e9589d/out` (exit code: 101) }, unknown: false, exit_code: 101 }
Could not compile `log4rs`.
Compiling log4rs v0.3.2
INFO:cargo::ops::cargo_rustc::job_queue: start: log4rs v0.3.2 LibraryTests
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at LibraryTests for log4rs v0.3.2
INFO:cargo::ops::cargo_rustc::job_queue: start: toml v0.1.20 BinaryTests
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at BinaryTests for toml v0.1.20
INFO:cargo::ops::cargo_rustc::job_queue: start: toml v0.1.20 Binaries
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at Binaries for toml v0.1.20
INFO:cargo::ops::cargo_rustc::job_queue: end: log4rs v0.3.2 LibraryTests
INFO:cargo::ops::cargo_rustc::job_queue: end: toml v0.1.20 BinaryTests
INFO:cargo::ops::cargo_rustc::job_queue: end: toml v0.1.20 Binaries
INFO:cargo::ops::cargo_rustc::job_queue: start: toml v0.1.20 End
DEBUG:cargo::ops::cargo_rustc::job_queue: start Dirty at End for toml v0.1.20
INFO:cargo::ops::cargo_rustc::job_queue: end: toml v0.1.20 End
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/toml/mod.rs:374:77: 374:90 error: type `collections::vec::Vec<&collections::string::String>` does not implement any method in scope named `connect`
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/toml/mod.rs:374 Err(Box::new(StringError(format!("Unknown keys: {}", remaining_keys.connect(", ")))))
^~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:26: 2:57 note: expansion site
<std macros>:1:1: 2:61 note: in expansion of format!
/root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/toml/mod.rs:374:34: 374:91 note: expansion site
error: aborting due to previous error
INFO:cargo::ops::cargo_rustc::job_queue: end: log4rs v0.3.2 Libraries
Build failed, waiting for other jobs to finish...
DEBUG:cargo::ops::cargo_rustc::fingerprint: appending /home/devalentino/projects/rust/openrtb/target/debug/.fingerprint/cookie-06b0342919872728/dep-lib-cookie <- /home/devalentino/projects/rust/openrtb
DEBUG:cargo::ops::cargo_rustc::fingerprint: write fingerprint: /home/devalentino/projects/rust/openrtb/target/debug/.fingerprint/cookie-06b0342919872728/lib-cookie
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.3.14 7423feedc5f2a887 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.2 8214dd728a11c371 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.2.34 e60c956de63d26f6 ["05ccb2a72b7547d5", "f93ac7e74187cdc1"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.3.14 7423feedc5f2a887 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.6 6fe09e092fa3838b []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.25 76efb3eb5cc29dff ["ea4a549311910034"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.6 6fe09e092fa3838b []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.10 978ee0dc69fc4e6e []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.1 4fbc2bae715ccce9 []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.6 6fe09e092fa3838b []
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.6.2 185cd752317b7abe ["ea4a549311910034"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.6.2 eb5510b5d1ad7ab2 ["dce1fa589358bc50", "e7065a134174c680", "ea4a549311910034", "faed0217340356ff"]
DEBUG:cargo::ops::cargo_rustc::fingerprint: inputs: 0.1.20 8ef42cf21841b54b ["63b96739f04ead7d", "f6dd208fd71b79d0", "f93ac7e74187cdc1", "f99656e7cca1ae95"]
DEBUG:cargo: handle_error; err=CliError { error: ChainedError { error: Could not compile `log4rs`., cause: Process didn't exit successfully: `rustc /root/.cargo/registry/src/github.com-1ecc6299db9ec823/log4rs-0.3.2/src/lib.rs --crate-name log4rs --crate-type lib -g -C metadata=c62ee90dc8e506be -C extra-filename=-c62ee90dc8e506be --out-dir /home/devalentino/projects/rust/openrtb/target/debug/deps --emit=dep-info,link -L dependency=/home/devalentino/projects/rust/openrtb/target/debug/deps -L dependency=/home/devalentino/projects/rust/openrtb/target/debug/deps --extern log=/home/devalentino/projects/rust/openrtb/target/debug/deps/liblog-54cf393d3c69686f.rlib --extern time=/home/devalentino/projects/rust/openrtb/target/debug/deps/libtime-e758cbe877e9589d.rlib --extern toml=/home/devalentino/projects/rust/openrtb/target/debug/deps/libtoml-e4d393d734aaa578.rlib -Awarnings -L native=/home/devalentino/projects/rust/openrtb/target/debug/build/time-e758cbe877e9589d/out` (exit code: 101) }, unknown: false, exit_code: 101 }
Could not compile `log4rs`.
Currently, the time stamp is always UTC but I'd prefer local time.
It would be nice to be able to truncate module names when they exceed configured limit in such a way that the full path can still be reasonably derived.
Lets say the module is lettre::smtp::client
and configured max module length is 10
-> {M:>10.10}
then it oule be nice to get an output like l::s::client
This is similar to what logback and other frameworks does.
Please provide a sample how to configure the logging programmatically using init_config function.
Having a JSON encoder would be great. It would simply encode the input data as JSON string, with sensible key names, one log per output line.
see also https://github.com/Nercury/android_logger-rs/pull/4
I have Appenders that support sentry and android , which I think will be useful to others.
Should we place them in log4rs directly or in there own separate crates?
Pros and Cons I can think of:
Just like init_config, so we can load a generic config from file and adjust it afterward.
There's currently no way to parse a toml string and initialize the logger using the log4rs public API. Internally, log4rs has the PrivateTomlConfigExt::unpack
method which returns a config::Config
that can be passed to init_config
.
This could be accomplished in a number of ways -
Clone
for config::Config
so that toml::Config::config()
can be used to produce an owned config::Config
.From<toml::Config>
for config::Config
init_config
to take a borrowed config::Config
instead of taking ownership of itPrivateTomlConfigExt::unpack
method part of the toml::Config
public API.Hi. Toml example in docs throws lot of errors. I'll update this issue with exact errors in some time. Is there an example of using toml config file?
I noted that the use different base
from 0
create even a base 0 file (foo.log.0
for instance).
After that following rolls don't create other files.
PR that fix it will follow soon...
Is there a way to completely deinitialize a logger (basically the oposite of init_config
), besides updating the handle with a Config::builder().build(Root::builder().build(LevelFilter::Off)).unwrap()
?
For example, "Info" for console, "Trace" for file, etc.
The LoggerBuilder requires a LogLevelFilter, which is missing in the docs. The link following from LoggerBuilder throws a 404 and you can't find it by search either.
As far as I can tell from browsing the docs and skimming the code it seems like console output is limited to stdout. And the file appenders take paths, so I can't just pass a handle or writer to stderr either.
Yaml in https://github.com/sfackler/log4rs/blob/master/README.md produces this cryptic error:
0:12: 0:13 expected `=`, but found `:`
Using Rust 1.7,
[dependencies]
log = "0.3.5"
log4rs = "0.3.3"
Given this config,
appenders:
main:
kind: console
root:
level: warn
appenders:
- main
loggers:
log4rs_issue:
level: debug
log4rs_issue::nested:
level: trace
messages at the DEBUG level don't show up.. sometimes. There's a repro in this repository. The repro should be runnable after a git clone
and cargo run
. Multiple invocations may be necessary for the issue to show up.
when i use file appender,it seems like just "stdout" write to log file ?when process panic, no record in the log file ,could log4rs support write "stderr" to log file?
Hi, is there any way to specify different log level by appenders at the root level?
The MIT license requires reproducing countless copies of the same copyright
header with different names in the copyright field, for every MIT library in
use. The Apache license does not have this drawback, and has protections from
patent trolls and an explicit contribution licensing clause. However, the
Apache license is incompatible with GPLv2. This is why Rust is dual-licensed as
MIT/Apache (the "primary" license being Apache, MIT only for GPLv2 compat), and
doing so would be wise for this project. This also makes this crate suitable
for inclusion in the Rust standard distribution and other project using dual
MIT/Apache.
To do this, get explicit approval from each contributor of copyrightable work
(as not all contributions qualify for copyright) and then add the following to
your README:
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be dual licensed as above, without any
additional terms or conditions.
and in your license headers, use the following boilerplate (based on that used in Rust):
// Copyright (c) 2015 t developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
And don't forget to update the license
metadata in your Cargo.toml
!
**my Cargo.toml **
[package]
name = "log4rs_test"
version = "0.1.0"
[dependencies]
log4rs = "0.7.0"
log = "0.3.8"
code
#[macro_use]
extern crate log;
extern crate log4rs;
fn main() {
println!("Hello, world!");
log4rs::init_file("config/log4rs.yaml", Default::default()).unwrap();
info!("booting up");
}
but log4rs init_file error,
E:\wsp\wsp_rust\projects\log4rs_test>cargo run
Compiling log4rs_test v0.1.0 (file:///E:/wsp/wsp_rust/projects/log4rs_test)
Finished dev [unoptimized + debuginfo] target(s) in 1.49 secs
Running `target\debug\log4rs_test.exe`
Hello, world!
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Log4rs(Error { repr: Os { code: 3, message: "系统找不到指定的路径。" } })', src\libcore\result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: process didn't exit successfully: `target\debug\log4rs_test.exe` (exit code: 101)
Hello!
I have the following log4rs configuration:
let json_encoder = Box::new(JsonEncoder::new());
let stdout = ConsoleAppender::builder().target(Target::Stdout).encoder(json_encoder).build();
let config = Config::builder().appender(Appender::builder().build("stdout", Box::new(stdout)))
.build(Root::builder()
.appender("stdout")
// Just enable all logging levels for now
.build(LogLevelFilter::Trace))?;
The logging is always sent to stderr - I've checked by redirecting stderr to stdout on the terminal. I've tried both Target::Stdout and Target::Stderr, to make sure they're not inverted.
I'm using MacOS 10.12.4, Rust 1.16, log4rs 0.6.2.
Thanks!
Errors encountered in the logging process are currently just dumped to stderr. This should be configurable in some way. In particular, it'd be great if it were possible for logger internals to provide diagnostic logging as well to debug configuration issues.
Cargo.toml
[dependencies]
log = "*"
log4rs = { git = "https://github.com/sfackler/log4rs", features = ["json"]}
main.rs
[macro_use]
extern crate log;
extern crate log4rs;fn main() {
log4rs::init_file("./test.json", Default::default()).unwrap();
info!("abc");
}
test.json
{
"appenders": {
"console": {
"kind": "console",
"encoder": {
"pattern": "{d(%Y-%m-%d %H:%M:%S)} {m}{n}"
}
}
},
"root": {
"level": "info",
"appenders": ["console"]
},
"loggers": {
"app::backend::logger": {
"level": "info",
"appenders": ["console"]
}
}
}
Display:
{ERROR: expected '}'}
If "pattern": "{d} {m}{n}"
Display:
2016-04-05T09:13:51.607972500+00:00 abc
For my application, I need a small amount of config information. Not wanting to have multiple config files, I just added a field to my 0.5.x Log4rs config file containing my config information, which worked fine. I just upgraded to 0.7.x, and Log4rs can no longer parse the config file. This problem appears to be Serde deserializing into Log4rs' RawConfig struct, seeing an unexpected field (my config data), and returning an error. I'm using the toml format.
Do I have any options except splitting this into two config files?
in the pre version it has method config_from_str. but i could not find that now how could i init config from str?
similar to i.e. log4perl
Maybe %P
failures:
---- append::rolling_file::policy::compound::roll::fixed_window::test::supported_gzip stdout ----
thread 'append::rolling_file::policy::compound::roll::fixed_window::test::supported_gzip' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "Das System kann die angegebene Datei nicht finden." } }', src\libcore\result.rs:860
note: Run with `RUST_BACKTRACE=1` for a backtrace.
---- encode::json::test::default stdout ----
thread 'encode::json::test::default' panicked at 'assertion failed: `(left == right)` (left: `"{\"time\":\"2016-03-20T23:22:20.644420340+01:00\",\"message\":\"message\",\"module_path\":\"module_path\",\"file\":\"file\",\"line\":100,\"level\":\"DEBUG\",\"target\":\"target\",\"thread\":\"encode::json::test::default\",\"mdc\":{\"foo\":\"bar\"}}\n"`, right: `"{\"time\":\"2016-03-20T23:22:20.644420340+01:00\",\"message\":\"message\",\"module_path\":\"module_path\",\"file\":\"file\",\"line\":100,\"level\":\"DEBUG\",\"target\":\"target\",\"thread\":\"encode::json::test::default\",\"mdc\":{\"foo\":\"bar\"}}\r\n"`)', src\encode\json.rs:229
failures:
append::rolling_file::policy::compound::roll::fixed_window::test::supported_gzip
encode::json::test::default
test result: FAILED. 33 passed; 2 failed; 1 ignored; 0 measured; 0 filtered out
I would like to add Appveyor to the build, so Win build fails would pop up immediately.
Currently the log file path from the config file seems to be relative to the current directory. It would be great to have an option (or something like a $EXE_PATH
variable to use in the path string) to make this relative to the executable instead.
Didn't figure this out yet. The default target of the log macros seems to be the module import path, so e.g. nickel
for nickel-rs. I'm trying to figure how to log my own application's messages at "trace" level while keeping others at "error" level.
Failed attempt:
[[logger]]
name = "nickel"
level = "error"
appenders = ["stdout"]
additive = false
Can you explain and add an example to the documentation?
cargo audit
reports a vuln in serde_yaml.
This appears to be fixed here, but a new release hasn't been pushed to crates.io:
f90ea13
Thanks :)
Hi. Can you please give me a config file example of how to print logs only from current crate?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.