Crates.io | holochain_logging |
lib.rs | holochain_logging |
version | 0.0.7 |
source | src |
created_at | 2019-10-15 17:20:04.822707 |
updated_at | 2020-02-11 20:51:58.397155 |
description | A logger for Holochain |
homepage | |
repository | https://github.com/holochain/holochain-logging |
max_upload_size | |
id | 172727 |
size | 66,591 |
This logger implementation has been designed to be fast. It delegates most of the heavy work to a dedicated thread. It offers nice filtering capability that can be combined with an optional and easy to use TOML configuration.
To have a generale view of the capability of this crate, you can run this command:
cargo run --example simple-fastlog-example
or
cargo run --example from-toml-fastlog-example
Additional examples can be found here as well.
This logging factory handles the environnement variable RUST_LOG as well so it can be used like this (the logger has to be registered):
RUST_LOG="debug" path/to/exec
Here is an example of how to simply build a logger with the Debug
log verbosity level:
FastLoggerBuilder::new()
// Optionally you can specify your custom timestamp format
.timestamp_format("%Y-%m-%d %H:%M:%S%.6f")
.set_level_from_str("Debug")
.build()
.expect("Fail to init the logging factory.");
debug!("What's bugging you today?");
Filtering out every log from dependencies and putting back in everything related to a particular target
is easy:
let toml = r#"
[logger]
level = "debug"
[[logger.rules]]
pattern = ".*"
exclude = true
[[logger.rules]]
pattern = "^holochain"
exclude = false
"#;
FastLoggerBuilder::from_toml(toml)
.expect("Fail to instantiate the logger from toml.")
.build()
.expect("Fail to build logger from toml.");
// Should NOT be logged
debug!(target: "rpc", "This is our dependency log filtering.");
// Should be logged each in different color. We avoid filtering by prefixing using the 'target'
// argument.
info!(target: "holochain", "Log message from Holochain Core.");
info!(target: "holochain-app-2", "Log message from Holochain Core with instance ID 2");
Copyright (C) 2019, Holochain Foundation
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.