[][src]Crate tari_common

Common logging and configuration utilities

The global Tari configuration file

A single configuration file (usually ~/.tari/config.toml is used to manage settings for all Tari applications and nodes running on a single system, whether it's a base node, validator node, or wallet.

Setting of configuration parameters is applied using the following order of precedence:

  1. Command-line argument
  2. Environment variable
  3. config.toml file value (see details: configuration)
  4. Configuration default

The utilities exposed in this crate are opinionated, but flexible. In general, all data is stored in a .tari folder under your home folder.

Custom application configuration

Tari configuration file allows adding custom application specific sections. Tari is using config crate to load configurations and gives access to config::Config struct so that apps might be flexible. Though as tari apps follow certain configurability assumptions, tari_common provides helper traits which automate those with minimal code.

CLI helpers

Bootstrapping tari configuration files might be customized via CLI or env settings. To help with building tari-enabled CLI from scratch as easy as possible this crate exposes ConfigBootstrap struct which implements structopt::StructOpt trait and can be easily reused in any CLI.

Example - CLI which is loading and deserializing the global config file

let mut args = ConfigBootstrap::from_args();
args.init_dirs(ApplicationType::BaseNode);
let config = args.load_configuration().unwrap();
let global = GlobalConfig::convert_from(config).unwrap();
assert_eq!(global.network, Network::Stibbons);
assert!(global.max_threads.is_none());

Re-exports

pub use configuration::error::ConfigError;
pub use configuration::bootstrap::install_configuration;
pub use configuration::bootstrap::ConfigBootstrap;
pub use configuration::global::CommsTransport;
pub use configuration::global::DatabaseType;
pub use configuration::global::GlobalConfig;
pub use configuration::global::Network;
pub use configuration::global::SocksAuthentication;
pub use configuration::global::TorControlAuthentication;
pub use configuration::loader::ConfigLoader;
pub use configuration::loader::ConfigPath;
pub use configuration::loader::ConfigurationError;
pub use configuration::loader::DefaultConfigLoader;
pub use configuration::loader::NetworkConfigPath;
pub use configuration::utils::default_config;
pub use configuration::utils::install_default_config_file;
pub use configuration::utils::load_configuration;

Modules

configuration

Configuration of tari applications

dir_utils
protobuf_build

Macros

log_if_error

Log an error if an Err is returned from the $expr. If the given expression is Ok(v), Some(v) is returned, otherwise None is returned (same as Result::ok). Useful in cases where the error should be logged and ignored. instead of writing if let Err(err) = my_error_call() { error!(...) }, you can write log_if_error!(my_error_call())

log_if_error_fmt

See log_if_error!.

Constants

DEFAULT_BASE_NODE_LOG_CONFIG
DEFAULT_CONFIG
DEFAULT_MERGE_MINING_PROXY_LOG_CONFIG
DEFAULT_MINING_NODE_LOG_CONFIG
DEFAULT_WALLET_LOG_CONFIG

Functions

initialize_logging

Set up application-level logging using the Log4rs configuration file specified in