-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(daemon): support dynamically setting the logging level at runtime #105
Changes from 1 commit
1d94f2c
b99706b
f0f1ee6
2fd260f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,43 @@ | ||
//! This is a helper command for setting our logging filter within the daemon while it is running. | ||
//! Doing this involves having to send a GRPC message to the daemon which inolves more plumbing | ||
//! than we'd ideally like but it allows us to update the filter without having to restart the | ||
//! daemon. | ||
//! | ||
//! The docs on the command itself cover how to set simple logging levels but the tracing framework | ||
//! we are using actually supports a rich syntax for how these filters are written. As and when we | ||
//! need to use this in anger, the docs can be found here: | ||
//! https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html | ||
Comment on lines
+1
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, this is great! |
||
use clap::Parser; | ||
use prompting_client::cli_actions::set_log_level; | ||
use prompting_client::cli_actions::set_logging_filter; | ||
use std::process::exit; | ||
|
||
/// Set the logging level for a running instance of the prompting client daemon | ||
/// Set the logging level for a running instance of the prompting client daemon. | ||
/// | ||
/// Simple usage of this command involves specifying a level based filter for what logs are written | ||
/// to the system journal by the prompting-client daemon. The supported levels are (in order of | ||
/// least to most verbose): | ||
/// | ||
/// - error | ||
/// - warn | ||
/// - info | ||
/// - debug | ||
/// - trace | ||
/// | ||
/// The default level is "info". | ||
Comment on lines
+14
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect! |
||
#[derive(Debug, Parser)] | ||
#[clap(about, long_about = None)] | ||
struct Args { | ||
/// The filter to use for setting the logging level | ||
/// The filter to use for determining what gets logged | ||
#[clap(short, long, value_name = "FILTER")] | ||
level: String, | ||
filter: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let Args { level } = Args::parse(); | ||
let Args { filter } = Args::parse(); | ||
|
||
match set_log_level(level).await { | ||
Ok(current) => println!("logging level set to: {current}"), | ||
match set_logging_filter(filter).await { | ||
Ok(current) => println!("logging filter set to: {current}"), | ||
Err(e) => { | ||
eprintln!("{e}"); | ||
exit(1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ pub struct ResolveHomePatternTypeResponse { | |
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct SetLoggingLevelResponse { | ||
pub struct SetLoggingFilterResponse { | ||
#[prost(string, tag = "1")] | ||
pub current: ::prost::alloc::string::String, | ||
} | ||
|
@@ -423,11 +423,11 @@ pub mod app_armor_prompting_client { | |
); | ||
self.inner.unary(req, path, codec).await | ||
} | ||
pub async fn set_logging_level( | ||
pub async fn set_logging_filter( | ||
&mut self, | ||
request: impl tonic::IntoRequest<::prost::alloc::string::String>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the logging level is contained in the request? |
||
) -> std::result::Result< | ||
tonic::Response<super::SetLoggingLevelResponse>, | ||
tonic::Response<super::SetLoggingFilterResponse>, | ||
tonic::Status, | ||
> { | ||
self.inner | ||
|
@@ -441,14 +441,14 @@ pub mod app_armor_prompting_client { | |
})?; | ||
let codec = tonic::codec::ProstCodec::default(); | ||
let path = http::uri::PathAndQuery::from_static( | ||
"/apparmor_prompting.AppArmorPrompting/SetLoggingLevel", | ||
"/apparmor_prompting.AppArmorPrompting/SetLoggingFilter", | ||
); | ||
let mut req = request.into_request(); | ||
req.extensions_mut() | ||
.insert( | ||
GrpcMethod::new( | ||
"apparmor_prompting.AppArmorPrompting", | ||
"SetLoggingLevel", | ||
"SetLoggingFilter", | ||
), | ||
); | ||
self.inner.unary(req, path, codec).await | ||
|
@@ -483,11 +483,11 @@ pub mod app_armor_prompting_server { | |
tonic::Response<super::ResolveHomePatternTypeResponse>, | ||
tonic::Status, | ||
>; | ||
async fn set_logging_level( | ||
async fn set_logging_filter( | ||
&self, | ||
request: tonic::Request<::prost::alloc::string::String>, | ||
) -> std::result::Result< | ||
tonic::Response<super::SetLoggingLevelResponse>, | ||
tonic::Response<super::SetLoggingFilterResponse>, | ||
tonic::Status, | ||
>; | ||
} | ||
|
@@ -706,14 +706,14 @@ pub mod app_armor_prompting_server { | |
}; | ||
Box::pin(fut) | ||
} | ||
"/apparmor_prompting.AppArmorPrompting/SetLoggingLevel" => { | ||
"/apparmor_prompting.AppArmorPrompting/SetLoggingFilter" => { | ||
#[allow(non_camel_case_types)] | ||
struct SetLoggingLevelSvc<T: AppArmorPrompting>(pub Arc<T>); | ||
struct SetLoggingFilterSvc<T: AppArmorPrompting>(pub Arc<T>); | ||
impl< | ||
T: AppArmorPrompting, | ||
> tonic::server::UnaryService<::prost::alloc::string::String> | ||
for SetLoggingLevelSvc<T> { | ||
type Response = super::SetLoggingLevelResponse; | ||
for SetLoggingFilterSvc<T> { | ||
type Response = super::SetLoggingFilterResponse; | ||
type Future = BoxFuture< | ||
tonic::Response<Self::Response>, | ||
tonic::Status, | ||
|
@@ -724,7 +724,10 @@ pub mod app_armor_prompting_server { | |
) -> Self::Future { | ||
let inner = Arc::clone(&self.0); | ||
let fut = async move { | ||
<T as AppArmorPrompting>::set_logging_level(&inner, request) | ||
<T as AppArmorPrompting>::set_logging_filter( | ||
&inner, | ||
request, | ||
) | ||
.await | ||
}; | ||
Box::pin(fut) | ||
|
@@ -736,7 +739,7 @@ pub mod app_armor_prompting_server { | |
let max_encoding_message_size = self.max_encoding_message_size; | ||
let inner = self.inner.clone(); | ||
let fut = async move { | ||
let method = SetLoggingLevelSvc(inner); | ||
let method = SetLoggingFilterSvc(inner); | ||
let codec = tonic::codec::ProstCodec::default(); | ||
let mut grpc = tonic::server::Grpc::new(codec) | ||
.apply_compression_config( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the filename could be updated to match as well