Skip to content

Commit

Permalink
feat(validator-node): add logging (#4189)
Browse files Browse the repository at this point in the history
Description
---
Adds log4rs to validator node

Motivation and Context
---
Currently, no logs are produced fr the validator node

How Has This Been Tested?
---
Manually
  • Loading branch information
sdbondi authored Jun 14, 2022
1 parent 6a4c1a4 commit 2ed859f
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 2 deletions.
188 changes: 188 additions & 0 deletions applications/tari_validator_node/log4rs_sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# A sample log configuration file for running in release mode. By default, this configuration splits up log messages to
# three destinations:
# * Console: For log messages with level INFO and higher
# * log/validator-node/network.log: INFO-level logs related to the comms crate. This file will be quite busy since there
# are lots of P2P debug messages, and so this traffic is segregated from the application log messages
# * log/validator-node/base_layer.log: Non-comms related INFO-level messages and higher are logged into this file
# * log/validator-node/other.log: Third-party crates' messages will be logged here at an ERROR level
#
# See https://docs.rs/log4rs/0.8.3/log4rs/encode/pattern/index.html for deciphering the log pattern. The log format
# used in this sample configuration prints messages as:
# timestamp [target] LEVEL message
refresh_rate: 30 seconds
appenders:
# An appender named "stdout" that writes to stdout
stdout:
kind: console

encoder:
pattern: "{d(%H:%M)} {h({l}):5} {m}{n}"
filters:
- kind: threshold
level: warn

# An appender named "network" that writes to a file with a custom pattern encoder
network:
kind: rolling_file
path: "log/validator-node/network.log"
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "log/validator-node/network.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] {l:5} {m}{n} // {f}:{L}"

# An appender named "base_layer" that writes to a file with a custom pattern encoder
base_layer:
kind: rolling_file
path: "log/validator-node/base_layer.log"
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "log/validator-node/base_layer.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [{X(node-public-key)},{X(node-id)}] {l:5} {m}{n} // {f}:{L} "

# An appender named "base_layer" that writes to a file with a custom pattern encoder
dan_layer:
kind: rolling_file
path: "log/validator-node/dan_layer.log"
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "log/validator-node/dan_layer.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [{X(node-public-key)},{X(node-id)}] {l:5} {m}{n} // {f}:{L} "


# An appender named "other" that writes to a file with a custom pattern encoder
other:
kind: rolling_file
path: "log/validator-node/other.log"
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "log/validator-node/other.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] {l:5} {m}{n} // {f}:{L} "

# Set the default logging level to "info"
root:
level: warn
appenders:
- stdout

loggers:
# Route log events common to every application to all appenders

tari::application:
level: info
appenders:
- base_layer
- network
- other
additive: false

tari::validator_node:
level: info
appenders:
- dan_layer
- base_layer
- network
- other
additive: false

tari::dan_layer:
level: info
appenders:
- dan_layer
additive: false

# Route log events sent to the "core" logger to the "base_layer" appender
c:
level: info
appenders:
- base_layer
tari:
level: info
appenders:
- base_layer

# Route log events sent to the "wallet" logger to the "base_layer" appender
wallet:
level: info
appenders:
- base_layer
# Route log events sent to the "comms" logger to the "network" appender
comms:
level: debug
appenders:
- network
# Route log events sent to the "p2p" logger to the "network" appender
p2p:
level: debug
appenders:
- network

# Route log events sent to the "yamux" logger to the "network" appender
yamux:
level: info
appenders:
- network
# Route log events sent to the "mio" logger to the "network" appender
mio:
level: error
appenders:
- network
# Route log events sent to the "rustyline" logger to the "other" appender
rustyline:
level: error
appenders:
- other
additive: false

# Route log events sent to the "tokio_util" logger to the "other" appender
tokio_util:
level: error
appenders:
- other
# Route PGP log events
pgp:
level: warn
appenders:
- other
# Route log events sent to the "tari_mm_proxy" logger to the "base_layer" appender
tari_mm_proxy:
level: info
appenders:
- base_layer
# Route R2D2 log events
r2d2:
level: warn
appenders:
- other
additive: false
2 changes: 1 addition & 1 deletion applications/tari_validator_node/src/dan_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl DanNode {
.await
{
Ok(()) => info!("Contracts accepted"),
Err(e) => error!("Contracts not accepted becayse {:?}", e),
Err(e) => error!("Contracts not accepted because {:?}", e),
}

time::sleep(Duration::from_secs(
Expand Down
6 changes: 5 additions & 1 deletion applications/tari_validator_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use tari_app_grpc::tari_rpc::validator_node_server::ValidatorNodeServer;
use tari_app_utilities::identity_management::setup_node_identity;
use tari_common::{
exit_codes::{ExitCode, ExitError},
initialize_logging,
load_configuration,
};
use tari_comms::{
Expand Down Expand Up @@ -90,7 +91,10 @@ fn main_inner() -> Result<(), ExitError> {
println!("Starting validator node on network {}", cli.network);
let config_path = cli.common.config_path();
let cfg = load_configuration(config_path, true, &cli.config_property_overrides())?;

initialize_logging(
&cli.common.log_config_path("validator"),
include_str!("../log4rs_sample.yml"),
)?;
let config = ApplicationConfig::load_from(&cfg)?;
let runtime = build_runtime()?;
runtime.block_on(run_node(&config))?;
Expand Down

0 comments on commit 2ed859f

Please sign in to comment.