add selective log handle reload
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
0023b09f5b
commit
160f48043e
4 changed files with 21 additions and 8 deletions
|
@ -314,6 +314,8 @@ pub(super) async fn force_device_list_updates(_body: Vec<&str>) -> Result<RoomMe
|
||||||
pub(super) async fn change_log_level(
|
pub(super) async fn change_log_level(
|
||||||
_body: Vec<&str>, filter: Option<String>, reset: bool,
|
_body: Vec<&str>, filter: Option<String>, reset: bool,
|
||||||
) -> Result<RoomMessageEventContent> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
|
let handles = &["console"];
|
||||||
|
|
||||||
if reset {
|
if reset {
|
||||||
let old_filter_layer = match EnvFilter::try_new(&services().globals.config.log) {
|
let old_filter_layer = match EnvFilter::try_new(&services().globals.config.log) {
|
||||||
Ok(s) => s,
|
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(()) => {
|
Ok(()) => {
|
||||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||||
"Successfully changed log level back to config value {}",
|
"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(()) => {
|
Ok(()) => {
|
||||||
return Ok(RoomMessageEventContent::text_plain("Successfully changed log level"));
|
return Ok(RoomMessageEventContent::text_plain("Successfully changed log level"));
|
||||||
},
|
},
|
||||||
|
|
|
@ -45,12 +45,13 @@ impl LogLevelReloadHandles {
|
||||||
.insert(name.into(), handle);
|
.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
|
self.handles
|
||||||
.lock()
|
.lock()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.values()
|
.iter()
|
||||||
.for_each(|handle| {
|
.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);
|
_ = handle.reload(new_value.clone()).or_else(error::else_log);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Suppress {
|
||||||
server
|
server
|
||||||
.log
|
.log
|
||||||
.reload
|
.reload
|
||||||
.reload(suppress)
|
.reload(suppress, Some(&["console"]))
|
||||||
.expect("log filter reloaded");
|
.expect("log filter reloaded");
|
||||||
Self {
|
Self {
|
||||||
server: server.clone(),
|
server: server.clone(),
|
||||||
|
@ -32,7 +32,7 @@ impl Drop for Suppress {
|
||||||
self.server
|
self.server
|
||||||
.log
|
.log
|
||||||
.reload
|
.reload
|
||||||
.reload(&self.restore)
|
.reload(&self.restore, Some(&["console"]))
|
||||||
.expect("log filter reloaded");
|
.expect("log filter reloaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
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));
|
let subscriber = Registry::default().with(fmt_layer.with_filter(fmt_reload_filter));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue