add selective log handle reload

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-11 00:42:49 +00:00
parent 0023b09f5b
commit 160f48043e
4 changed files with 21 additions and 8 deletions

View file

@ -314,6 +314,8 @@ pub(super) async fn force_device_list_updates(_body: Vec<&str>) -> Result<RoomMe
pub(super) async fn change_log_level(
_body: Vec<&str>, filter: Option<String>, reset: bool,
) -> Result<RoomMessageEventContent> {
let handles = &["console"];
if reset {
let old_filter_layer = match EnvFilter::try_new(&services().globals.config.log) {
Ok(s) => s,
@ -324,7 +326,12 @@ pub(super) async fn change_log_level(
},
};
match services().server.log.reload.reload(&old_filter_layer) {
match services()
.server
.log
.reload
.reload(&old_filter_layer, Some(handles))
{
Ok(()) => {
return Ok(RoomMessageEventContent::text_plain(format!(
"Successfully changed log level back to config value {}",
@ -349,7 +356,12 @@ pub(super) async fn change_log_level(
},
};
match services().server.log.reload.reload(&new_filter_layer) {
match services()
.server
.log
.reload
.reload(&new_filter_layer, Some(handles))
{
Ok(()) => {
return Ok(RoomMessageEventContent::text_plain("Successfully changed log level"));
},

View file

@ -45,12 +45,13 @@ impl LogLevelReloadHandles {
.insert(name.into(), handle);
}
pub fn reload(&self, new_value: &EnvFilter) -> Result<()> {
pub fn reload(&self, new_value: &EnvFilter, names: Option<&[&str]>) -> Result<()> {
self.handles
.lock()
.expect("locked")
.values()
.for_each(|handle| {
.iter()
.filter(|(name, _)| names.map_or(false, |names| names.contains(&name.as_str())))
.for_each(|(_, handle)| {
_ = handle.reload(new_value.clone()).or_else(error::else_log);
});

View file

@ -18,7 +18,7 @@ impl Suppress {
server
.log
.reload
.reload(suppress)
.reload(suppress, Some(&["console"]))
.expect("log filter reloaded");
Self {
server: server.clone(),
@ -32,7 +32,7 @@ impl Drop for Suppress {
self.server
.log
.reload
.reload(&self.restore)
.reload(&self.restore, Some(&["console"]))
.expect("log filter reloaded");
}
}

View file

@ -27,7 +27,7 @@ pub(crate) fn init(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard
};
let (fmt_reload_filter, fmt_reload_handle) = reload::Layer::new(filter_layer.clone());
reload_handles.add("format", Box::new(fmt_reload_handle));
reload_handles.add("console", Box::new(fmt_reload_handle));
let subscriber = Registry::default().with(fmt_layer.with_filter(fmt_reload_filter));