Use solana_logger for logging setup

This commit is contained in:
Christian Kamm 2021-11-02 12:54:39 +01:00
parent d8015daea6
commit 16f8dad40d
5 changed files with 13 additions and 33 deletions

1
Cargo.lock generated
View File

@ -3903,6 +3903,7 @@ dependencies = [
"serde",
"solana-account-decoder",
"solana-client",
"solana-logger",
"solana-rpc",
"solana-sdk",
"tokio",

View File

@ -13,7 +13,8 @@ jsonrpc-core-client = { version = "18.0.0", features = ["ws", "http"] }
solana-rpc = "=1.8.2"
solana-client = "=1.8.2"
solana-account-decoder = "1.8.2"
solana-sdk = "^1.7.10"
solana-sdk = "=1.8.2"
solana-logger = "=1.8.2"
hyper = { version = "0.14", features = ["client", "http1"] }
hyper-tls = { version = "0.5" }

View File

@ -6,26 +6,6 @@ use solana_sdk::pubkey::Pubkey;
use log::*;
struct SimpleLogger;
impl log::Log for SimpleLogger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.level() <= log::Level::Info
}
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
println!("{} - {}", record.level(), record.args());
}
}
fn flush(&self) {}
}
static LOGGER: SimpleLogger = SimpleLogger;
//
// main etc.
//
trait AnyhowWrap {
type Value;
fn map_err_anyhow(self) -> anyhow::Result<Self::Value>;
@ -59,9 +39,7 @@ pub struct SlotUpdate {
#[tokio::main]
async fn main() {
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(log::LevelFilter::Info))
.unwrap();
solana_logger::setup_with_default("info");
info!("startup");
let postgres_connection_string = "host=/var/run/postgresql user=kamm port=5433";

View File

@ -102,7 +102,7 @@ pub fn init(
data = write.data,
);
let result = query.execute(client).await.unwrap();
println!("new write: count: {}", result);
info!("new write: count: {}", result);
});
}
});
@ -148,7 +148,7 @@ pub fn init(
status = update.status,
);
let result = query.execute(client).await.unwrap();
println!("new slot: count: {}", result);
info!("new slot: count: {}", result);
} else {
let query = query!(
" \
@ -162,11 +162,11 @@ pub fn init(
status = update.status,
);
let result = query.execute(client).await.unwrap();
println!("new slot: count: {}", result);
info!("new slot: count: {}", result);
}
if update.status == "rooted" {
println!("slot changed to rooted");
info!("slot changed to rooted");
slots.remove(&update.slot);
// TODO: should also convert all parents to rooted, just in case we missed an update
@ -214,7 +214,7 @@ pub fn init(
let new_newest_slot = newest_nonfinal_slot.unwrap_or(-1) < update.slot;
if new_newest_slot || parent_update {
println!("recomputing uncles");
info!("recomputing uncles");
// update the uncle column for the chain of slots from the
// newest down the the first rooted slot
let query = query!("\

View File

@ -153,11 +153,11 @@ pub fn process_events(
// copy websocket updates into the postgres account write queue
loop {
let update = update_receiver.recv().unwrap();
println!("got update message");
info!("got update message");
match update {
WebsocketMessage::SingleUpdate(update) => {
println!("single update");
info!("single update");
let account: Account = update.value.account.decode().unwrap();
let pubkey = Pubkey::from_str(&update.value.pubkey).unwrap();
account_write_queue_sender
@ -165,7 +165,7 @@ pub fn process_events(
.unwrap();
}
WebsocketMessage::SnapshotUpdate(update) => {
println!("snapshot update");
info!("snapshot update");
for keyed_account in update.value {
let account: Account = keyed_account.account.decode().unwrap();
let pubkey = Pubkey::from_str(&keyed_account.pubkey).unwrap();
@ -175,7 +175,7 @@ pub fn process_events(
}
}
WebsocketMessage::SlotUpdate(update) => {
println!("slot update");
info!("slot update");
let message = match *update {
solana_client::rpc_response::SlotUpdate::CreatedBank {
slot, parent, ..