Allow override of RUST_LOG (#7705)

This commit is contained in:
Jack May 2020-01-08 09:19:12 -08:00 committed by GitHub
parent 2f5f8e7afd
commit 07855e3125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 32 additions and 18 deletions

View File

@ -12,7 +12,7 @@ use std::{collections::HashMap, fs::File, io::prelude::*, path::Path, process::e
pub const NUM_SIGNATURES_FOR_TXS: u64 = 100_000 * 60 * 60 * 24 * 7;
fn main() {
solana_logger::setup_with_filter("solana=info");
solana_logger::setup_with_default("solana=info");
solana_metrics::set_panic_hook("bench-tps");
let matches = cli::build_args(solana_clap_utils::version!()).get_matches();

View File

@ -1023,7 +1023,7 @@ impl RpcSol for RpcSolImpl {
}
fn set_log_filter(&self, _meta: Self::Metadata, filter: String) -> Result<()> {
solana_logger::setup_with_filter(&filter);
solana_logger::setup_with(&filter);
Ok(())
}

View File

@ -12,7 +12,7 @@ use std::{
};
fn main() -> Result<(), Box<dyn error::Error>> {
solana_logger::setup_with_filter("solana=info");
solana_logger::setup_with_default("solana=info");
solana_metrics::set_panic_hook("faucet");
let matches = App::new(crate_name!())
.about(crate_description!())

View File

@ -13,7 +13,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::process::exit;
fn main() -> Result<(), Box<dyn error::Error>> {
solana_logger::setup_with_filter("solana=info");
solana_logger::setup_with_default("solana=info");
let matches = App::new(crate_name!())
.about(crate_description!())

View File

@ -515,7 +515,7 @@ fn open_database(ledger_path: &Path) -> Database {
#[allow(clippy::cognitive_complexity)]
fn main() {
const DEFAULT_ROOT_COUNT: &str = "1";
solana_logger::setup_with_filter("solana=info");
solana_logger::setup_with_default("solana=info");
let starting_slot_arg = Arg::with_name("starting_slot")
.long("starting-slot")

View File

@ -22,12 +22,7 @@ impl log::Log for LoggerShim {
fn flush(&self) {}
}
// Configures logging with a specific filter.
// May be called at any time to re-configure the log filter
pub fn setup_with_filter(filter: &str) {
let logger = env_logger::Builder::from_env(env_logger::Env::new().default_filter_or(filter))
.format_timestamp_nanos()
.build();
fn replace_logger(logger: env_logger::Logger) {
let max_level = logger.filter();
log::set_max_level(max_level);
let mut rw = LOGGER.write().unwrap();
@ -35,7 +30,26 @@ pub fn setup_with_filter(filter: &str) {
let _ = log::set_boxed_logger(Box::new(LoggerShim {}));
}
// Configures logging with the default filter ("error")
pub fn setup() {
setup_with_filter("error");
// Configures logging with a specific filter overriding RUST_LOG. _RUST_LOG is used instead
// so if set it takes precedence.
// May be called at any time to re-configure the log filter
pub fn setup_with(filter: &str) {
let logger =
env_logger::Builder::from_env(env_logger::Env::new().filter_or("_RUST_LOG", filter))
.format_timestamp_nanos()
.build();
replace_logger(logger);
}
// Configures logging with a default filter if RUST_LOG is not set
pub fn setup_with_default(filter: &str) {
let logger = env_logger::Builder::from_env(env_logger::Env::new().default_filter_or(filter))
.format_timestamp_nanos()
.build();
replace_logger(logger);
}
// Configures logging with the default filter "error" if RUST_LOG is not set
pub fn setup() {
setup_with_default("error");
}

View File

@ -93,7 +93,7 @@ pub fn process_instruction(
keyed_accounts: &mut [KeyedAccount],
ix_data: &[u8],
) -> Result<(), InstructionError> {
solana_logger::setup();
solana_logger::setup_with_default("solana=info");
if let Ok(instruction) = limited_deserialize(ix_data) {
match instruction {

View File

@ -179,7 +179,7 @@ pub fn process_instruction(
keyed_accounts: &mut [KeyedAccount],
data: &[u8],
) -> Result<(), InstructionError> {
solana_logger::setup_with_filter("solana=info");
solana_logger::setup_with_default("solana=info");
trace!("process_instruction: {:?}", data);
trace!("keyed_accounts: {:?}", keyed_accounts);

View File

@ -692,7 +692,7 @@ pub fn main() {
}
};
solana_logger::setup_with_filter(
solana_logger::setup_with_default(
&[
"solana=info", /* info logging for all solana modules */
"rpc=trace", /* json_rpc request/response logging */

View File

@ -48,7 +48,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let json_rpc_url = value_t_or_exit!(matches, "json_rpc_url", String);
let validator_identity = pubkey_of(&matches, "validator_identity").map(|i| i.to_string());
solana_logger::setup_with_filter("solana=info");
solana_logger::setup_with_default("solana=info");
solana_metrics::set_panic_hook("watchtower");
let rpc_client = RpcClient::new(json_rpc_url);