autocommit 2022-04-02 00:31:30 CEST
This commit is contained in:
parent
2dd433aa04
commit
6ad6d83b7e
34 changed files with 446 additions and 161 deletions
|
|
@ -7,7 +7,9 @@ use crate::utils::buffd::{MsgParser, MsgParserError};
|
|||
use crate::wire::jay_compositor::*;
|
||||
use crate::wire::JayCompositorId;
|
||||
use std::rc::Rc;
|
||||
use log::Level;
|
||||
use thiserror::Error;
|
||||
use crate::cli::CliLogLevel;
|
||||
|
||||
pub struct JayCompositorGlobal {
|
||||
name: GlobalName,
|
||||
|
|
@ -81,6 +83,25 @@ impl JayCompositor {
|
|||
self.client.state.el.stop();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_log_level(&self, parser: MsgParser<'_, '_>) -> Result<(), SetLogLevelError> {
|
||||
let req: SetLogLevel = self.client.parse(self, parser)?;
|
||||
const ERROR: u32 = CliLogLevel::Error as u32;
|
||||
const WARN: u32 = CliLogLevel::Warn as u32;
|
||||
const INFO: u32 = CliLogLevel::Info as u32;
|
||||
const DEBUG: u32 = CliLogLevel::Debug as u32;
|
||||
const TRACE: u32 = CliLogLevel::Trace as u32;
|
||||
let level = match req.level {
|
||||
ERROR => Level::Error,
|
||||
WARN => Level::Warn,
|
||||
INFO => Level::Info,
|
||||
DEBUG => Level::Debug,
|
||||
TRACE => Level::Trace,
|
||||
_ => return Err(SetLogLevelError::UnknownLogLevel(req.level)),
|
||||
};
|
||||
self.client.state.logger.set_level(level);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
|
|
@ -89,11 +110,12 @@ object_base! {
|
|||
DESTROY => destroy,
|
||||
GET_LOG_FILE => get_log_file,
|
||||
QUIT => quit,
|
||||
SET_LOG_LEVEL => set_log_level,
|
||||
}
|
||||
|
||||
impl Object for JayCompositor {
|
||||
fn num_requests(&self) -> u32 {
|
||||
QUIT + 1
|
||||
SET_LOG_LEVEL + 1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +129,8 @@ pub enum JayCompositorError {
|
|||
GetLogFileError(#[from] GetLogFileError),
|
||||
#[error("Could not process a `quit` request")]
|
||||
QuitError(#[from] QuitError),
|
||||
#[error("Could not process a `set_log_level` request")]
|
||||
SetLogLevelError(#[from] SetLogLevelError),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
|
|
@ -138,3 +162,12 @@ pub enum QuitError {
|
|||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(QuitError, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetLogLevelError {
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
#[error("Unknown log level {0}")]
|
||||
UnknownLogLevel(u32),
|
||||
}
|
||||
efrom!(SetLogLevelError, MsgParserError);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue