add partial envfilter support for admin log capture; conf item
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
4d0fc41222
commit
50e66a2976
2 changed files with 31 additions and 11 deletions
|
@ -30,6 +30,7 @@ use service::{
|
||||||
Services,
|
Services,
|
||||||
};
|
};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
use tracing_subscriber::{filter::LevelFilter, EnvFilter};
|
||||||
|
|
||||||
use crate::{admin, admin::AdminCommand, Command};
|
use crate::{admin, admin::AdminCommand, Command};
|
||||||
|
|
||||||
|
@ -87,17 +88,7 @@ fn reply(mut content: RoomMessageEventContent, reply_id: Option<OwnedEventId>) -
|
||||||
|
|
||||||
// Parse and process a message from the admin room
|
// Parse and process a message from the admin room
|
||||||
async fn process(context: &Command<'_>, command: AdminCommand, args: &[String]) -> CommandOutput {
|
async fn process(context: &Command<'_>, command: AdminCommand, args: &[String]) -> CommandOutput {
|
||||||
let filter: &capture::Filter =
|
let (capture, logs) = capture_create(context);
|
||||||
&|data| data.level() <= Level::DEBUG && data.our_modules() && data.scope.contains(&"admin");
|
|
||||||
let logs = Arc::new(Mutex::new(
|
|
||||||
collect_stream(|s| markdown_table_head(s)).expect("markdown table header"),
|
|
||||||
));
|
|
||||||
|
|
||||||
let capture = Capture::new(
|
|
||||||
&context.services.server.log.capture,
|
|
||||||
Some(filter),
|
|
||||||
capture::fmt(markdown_table, logs.clone()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let capture_scope = capture.start();
|
let capture_scope = capture.start();
|
||||||
let result = Box::pin(admin::process(command, context)).await;
|
let result = Box::pin(admin::process(command, context)).await;
|
||||||
|
@ -130,6 +121,30 @@ async fn process(context: &Command<'_>, command: AdminCommand, args: &[String])
|
||||||
Some(RoomMessageEventContent::notice_markdown(output))
|
Some(RoomMessageEventContent::notice_markdown(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn capture_create(context: &Command<'_>) -> (Arc<Capture>, Arc<Mutex<String>>) {
|
||||||
|
let env_config = &context.services.server.config.admin_log_capture;
|
||||||
|
let env_filter = EnvFilter::try_new(env_config).unwrap_or_else(|_| "debug".into());
|
||||||
|
let log_level = env_filter
|
||||||
|
.max_level_hint()
|
||||||
|
.and_then(LevelFilter::into_level)
|
||||||
|
.unwrap_or(Level::DEBUG);
|
||||||
|
|
||||||
|
let filter =
|
||||||
|
move |data: capture::Data<'_>| data.level() <= log_level && data.our_modules() && data.scope.contains(&"admin");
|
||||||
|
|
||||||
|
let logs = Arc::new(Mutex::new(
|
||||||
|
collect_stream(|s| markdown_table_head(s)).expect("markdown table header"),
|
||||||
|
));
|
||||||
|
|
||||||
|
let capture = Capture::new(
|
||||||
|
&context.services.server.log.capture,
|
||||||
|
Some(filter),
|
||||||
|
capture::fmt(markdown_table, logs.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
(capture, logs)
|
||||||
|
}
|
||||||
|
|
||||||
// Parse chat messages from the admin room into an AdminCommand object
|
// Parse chat messages from the admin room into an AdminCommand object
|
||||||
fn parse<'a>(
|
fn parse<'a>(
|
||||||
services: &Arc<Services>, input: &'a CommandInput,
|
services: &Arc<Services>, input: &'a CommandInput,
|
||||||
|
|
|
@ -338,6 +338,8 @@ pub struct Config {
|
||||||
pub admin_console_automatic: bool,
|
pub admin_console_automatic: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub admin_execute: Vec<String>,
|
pub admin_execute: Vec<String>,
|
||||||
|
#[serde(default = "default_admin_log_capture")]
|
||||||
|
pub admin_log_capture: String,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub sentry: bool,
|
pub sentry: bool,
|
||||||
|
@ -596,6 +598,7 @@ impl fmt::Display for Config {
|
||||||
&self.admin_console_automatic.to_string(),
|
&self.admin_console_automatic.to_string(),
|
||||||
);
|
);
|
||||||
line("Execute admin commands after startup", &self.admin_execute.join(", "));
|
line("Execute admin commands after startup", &self.admin_execute.join(", "));
|
||||||
|
line("Filter for admin command log capture", &self.admin_log_capture);
|
||||||
line("Allow outgoing federated typing", &self.allow_outgoing_typing.to_string());
|
line("Allow outgoing federated typing", &self.allow_outgoing_typing.to_string());
|
||||||
line("Allow incoming federated typing", &self.allow_incoming_typing.to_string());
|
line("Allow incoming federated typing", &self.allow_incoming_typing.to_string());
|
||||||
line(
|
line(
|
||||||
|
@ -1054,3 +1057,5 @@ fn default_sentry_traces_sample_rate() -> f32 { 0.15 }
|
||||||
fn default_sentry_filter() -> String { "info".to_owned() }
|
fn default_sentry_filter() -> String { "info".to_owned() }
|
||||||
|
|
||||||
fn default_startup_netburst_keep() -> i64 { 50 }
|
fn default_startup_netburst_keep() -> i64 { 50 }
|
||||||
|
|
||||||
|
fn default_admin_log_capture() -> String { "debug".to_owned() }
|
||||||
|
|
Loading…
Add table
Reference in a new issue