Code Monkey home page Code Monkey logo

log4rs's Introduction

log4rs

docs crates.io License: MIT OR Apache-2.0 CI Minimum rustc version

log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries.

Quick Start

log4rs.yaml:

refresh_rate: 30 seconds
appenders:
  stdout:
    kind: console
  requests:
    kind: file
    path: "log/requests.log"
    encoder:
      pattern: "{d} - {m}{n}"
root:
  level: warn
  appenders:
    - stdout
loggers:
  app::backend::db:
    level: info
  app::requests:
    level: info
    appenders:
      - requests
    additive: false

lib.rs:

use log::{error, info, warn};
use log4rs;

fn main() {
    log4rs::init_file("config/log4rs.yaml", Default::default()).unwrap();

    info!("booting up");

    // ...
}

Rust Version Requirements

1.69

Building for Dev

  • Run the tests: cargo test --all-features
  • Run the tests for windows with cross: cross test --target x86_64-pc-windows-gnu
  • Run the tests for all individual features: ./test.sh
  • Run the tests for all individual features for windows with cross: ./test.sh win

Compression

If you are using the file rotation in your configuration there is a known substantial performance issue with the gzip feature. When rolling files it will zip log archives automatically. This is a problem when the log archives are large as the zip happens in the main thread and will halt the process while the zip is completed.

The methods to mitigate this are as follows.

  1. Use the background_rotation feature which spawns an os thread to do the compression.
  2. Do not enable the gzip feature.
  3. Ensure the archives are small enough that the compression time is acceptable.

For more information see the PR that added background_rotation.

License

Licensed under either of

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.

log4rs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

log4rs's Issues

Broken pipe when using | tee

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.

Configuration file directly in the crate

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

Log messages from a hierarchy sometimes don't show up

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.

Ron configuration format

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.

Config File Restrictions

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?

Need some kind of meta-logging infrastructure

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.

Support embedded toml config

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 -

  • Implement Clone for config::Config so that toml::Config::config() can be used to produce an owned config::Config.
  • Implement From<toml::Config> for config::Config
  • Change init_config to take a borrowed config::Config instead of taking ownership of it
  • Make the PrivateTomlConfigExt::unpack method part of the toml::Config public API.

Return Config struct in init_file() func

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.

serde_yaml imcompatability

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.

beautify module truncation

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.

support stderr wirte to file appender?

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?

more `Append` implementations consideration

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:

In log4rs:

  • Pros: easy to use and integrate
  • Cons: somewhat bloated for log4rs

In separate crates:

  • Pros: clean design in crate level
  • Cons: people will have to search for crates with log4rs support and every crate have to consider log4rs and maybe other logger implementations.

log4rs compilation error

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`.

TOML configuration

Why did you drop TOML configuration format? Will it come back anytime soon?

Relicense under dual MIT/Apache-2.0

Why?

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.

How?

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!

Contributor checkoff

log4rs init_file error

**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)

Embedding logging configuration inside general configuration file

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.

stderr support?

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.

Allow use of hardcoded text styles in pattern encoder

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.

Terminal coloration

Hello there!

I have realised log4rs does not provide terminal coloration by default. Would you be interested in the feature?

For comparison, loggers such as log4js and winston provides terminal coloration by default.

If you like the idea but don't have the time for it, I would gladly work on it. :)

Logging to syslog

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 panics when conf file doesn't exist

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!

Log only current crate

Hi. Can you please give me a config file example of how to print logs only from current crate?

Error with Date pattern with serde_json

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

Won't compile in nightly

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

add stderr support in init_file?

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!

Deinitialize logger

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()?

Console appender only writes to stderr

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!

Windows Test Problems

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.

How to use rolling file appender?

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?

JSON Encoder

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.

Add example how to filter by crate/module

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?

Problem with escaping braces `()` - Error: expected '}'

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.