forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validator log filter may now be reconfigured at runtime (solana-labs#…
…5473) * Log filter may now be reconfigured at runtime * Add RPC API and bash script to reconfigure the log filter
- Loading branch information
Showing
5 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
//! The `logger` module provides a setup function for `env_logger`. Its only function, | ||
//! `setup()` may be called multiple times. | ||
//! The `logger` module configures `env_logger` | ||
use env_logger; | ||
use std::sync::Once; | ||
use lazy_static::lazy_static; | ||
use std::sync::{Arc, RwLock}; | ||
|
||
static INIT: Once = Once::new(); | ||
lazy_static! { | ||
static ref LOGGER: Arc<RwLock<env_logger::Logger>> = | ||
{ Arc::new(RwLock::new(env_logger::Logger::from_default_env())) }; | ||
} | ||
|
||
struct LoggerShim {} | ||
|
||
impl log::Log for LoggerShim { | ||
fn enabled(&self, metadata: &log::Metadata) -> bool { | ||
LOGGER.read().unwrap().enabled(metadata) | ||
} | ||
|
||
fn log(&self, record: &log::Record) { | ||
LOGGER.read().unwrap().log(record); | ||
} | ||
|
||
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) { | ||
INIT.call_once(|| { | ||
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or(filter)) | ||
.default_format_timestamp_nanos(true) | ||
.init(); | ||
}); | ||
let logger = env_logger::Builder::from_env(env_logger::Env::new().default_filter_or(filter)) | ||
.default_format_timestamp_nanos(true) | ||
.build(); | ||
let max_level = logger.filter(); | ||
log::set_max_level(max_level); | ||
let mut rw = LOGGER.write().unwrap(); | ||
std::mem::replace(&mut *rw, logger); | ||
let _ = log::set_boxed_logger(Box::new(LoggerShim {})); | ||
} | ||
|
||
// Configures logging with the default filter ("error") | ||
pub fn setup() { | ||
setup_with_filter("error"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Reconfigures the log filter on a validator using the current RUST_LOG value | ||
# | ||
|
||
if [[ -n $1 ]]; then | ||
url=$1 | ||
else | ||
# Default to the local node | ||
url=http://127.0.0.1:8899 | ||
fi | ||
|
||
if [[ -z $RUST_LOG ]]; then | ||
echo "RUST_LOG not defined" | ||
exit 1 | ||
fi | ||
|
||
set -x | ||
exec curl $url -X POST -H "Content-Type: application/json" \ | ||
-d " | ||
{ | ||
\"jsonrpc\": \"2.0\", | ||
\"id\": 1, | ||
\"method\": \"setLogFilter\", | ||
\"params\": [\"$RUST_LOG\"] | ||
} | ||
" |