improvement: better logging

Use CONDUIT_LOG or the log setting in the config
next
Timo Kösters 2021-03-23 22:01:14 +01:00
parent 46d8f36a2c
commit 1d00a8c41f
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
5 changed files with 18 additions and 7 deletions

View File

@ -35,6 +35,7 @@ max_request_size = 20_000_000 # in bytes
#cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024 #cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
#max_concurrent_requests = 4 # How many requests Conduit sends to other servers at the same time #max_concurrent_requests = 4 # How many requests Conduit sends to other servers at the same time
#log = "info,rocket=off,_=off,sled=off"
#workers = 4 # default: cpu core count * 2 #workers = 4 # default: cpu core count * 2
address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy

View File

@ -12,7 +12,7 @@ use std::collections::BTreeMap;
)] )]
#[tracing::instrument] #[tracing::instrument]
pub async fn get_protocols_route() -> ConduitResult<get_protocols::Response> { pub async fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
warn!("TODO: get_protocols_route"); // TODO
Ok(get_protocols::Response { Ok(get_protocols::Response {
protocols: BTreeMap::new(), protocols: BTreeMap::new(),
} }

View File

@ -46,6 +46,8 @@ pub struct Config {
jwt_secret: Option<String>, jwt_secret: Option<String>,
#[serde(default = "Vec::new")] #[serde(default = "Vec::new")]
trusted_servers: Vec<Box<ServerName>>, trusted_servers: Vec<Box<ServerName>>,
#[serde(default = "default_log")]
pub log: String,
} }
fn false_fn() -> bool { fn false_fn() -> bool {
@ -68,6 +70,10 @@ fn default_max_concurrent_requests() -> u16 {
4 4
} }
fn default_log() -> String {
"info,rocket=off,_=off,sled=off".to_owned()
}
#[derive(Clone)] #[derive(Clone)]
pub struct Database { pub struct Database {
pub globals: globals::Globals, pub globals: globals::Globals,

View File

@ -205,7 +205,8 @@ async fn main() {
rocket.launch().await.unwrap(); rocket.launch().await.unwrap();
} else { } else {
pretty_env_logger::init(); std::env::set_var("CONDUIT_LOG", config.log);
pretty_env_logger::init_custom_env("CONDUIT_LOG");
let root = span!(tracing::Level::INFO, "app_start", work_units = 2); let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
let _enter = root.enter(); let _enter = root.enter();

View File

@ -1339,11 +1339,14 @@ pub(crate) async fn build_forward_extremity_snapshots(
// The current server state and incoming event state are built to be // The current server state and incoming event state are built to be
// the state after. // the state after.
// This would be the incoming state from the server. // This would be the incoming state from the server.
Some(leave_pdu) => { Some(leaf_pdu) => {
let pdu_shortstatehash = db let pdu_shortstatehash = db
.rooms .rooms
.pdu_shortstatehash(&leave_pdu.event_id)? .pdu_shortstatehash(&leaf_pdu.event_id)?
.ok_or_else(|| Error::bad_database("Found pdu with no statehash in db."))?; .ok_or_else(|| {
warn!("Leaf pdu: {:?}", leaf_pdu);
Error::bad_database("Found pdu with no statehash in db.")
})?;
if current_shortstatehash.as_ref() == Some(&pdu_shortstatehash) { if current_shortstatehash.as_ref() == Some(&pdu_shortstatehash) {
includes_current_state = true; includes_current_state = true;
@ -1357,8 +1360,8 @@ pub(crate) async fn build_forward_extremity_snapshots(
.collect::<StateMap<_>>(); .collect::<StateMap<_>>();
// Now it's the state after // Now it's the state after
let key = (leave_pdu.kind.clone(), leave_pdu.state_key.clone()); let key = (leaf_pdu.kind.clone(), leaf_pdu.state_key.clone());
state_before.insert(key, Arc::new(leave_pdu)); state_before.insert(key, Arc::new(leaf_pdu));
fork_states.insert(state_before); fork_states.insert(state_before);
} }