Log thread_bus IPC messages only in debug mode (#1800)
* zellij: Add global `DEBUG_MODE` variable that tells us whether zellij was started with the `--debug` CLI flag. * utils/errors: Only log thread_bus message in debug mode, and discard the message otherwise. * utils/logging: Increase logsize to 16 MiB per logfile, totaling 32 MiB of logs at most (in two files). * zellij: Set global `DEBUG` variable in server thread and make sure the value of the `--debug` CLI flag is propagated to the server, too. This means that to enable debug mode, the server must be started with the `--debug` flag. This happens when the first client that starts the zellij session has the `--debug` flag set, because it will be forwarded to the server. Subsequent clients attaching to the same session with the `--debug` flag specified **do not** override the value of the `DEBUG` variable. Hence, if the server wasn't started in debug mode, this cannot be changed.
This commit is contained in:
parent
2ae057d061
commit
f26e73ce03
6 changed files with 25 additions and 13 deletions
|
|
@ -86,7 +86,9 @@ fn get_os_input<OsInputOutput>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start_server(path: PathBuf) {
|
pub(crate) fn start_server(path: PathBuf, debug: bool) {
|
||||||
|
// Set instance-wide debug mode
|
||||||
|
zellij_utils::consts::DEBUG_MODE.set(debug).unwrap();
|
||||||
let os_input = get_os_input(get_server_os_input);
|
let os_input = get_os_input(get_server_os_input);
|
||||||
start_server_impl(Box::new(os_input), path);
|
start_server_impl(Box::new(os_input), path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ fn main() {
|
||||||
{
|
{
|
||||||
commands::kill_session(target_session);
|
commands::kill_session(target_session);
|
||||||
} else if let Some(path) = opts.server {
|
} else if let Some(path) = opts.server {
|
||||||
commands::start_server(path);
|
commands::start_server(path, opts.debug);
|
||||||
} else {
|
} else {
|
||||||
commands::start_client(opts);
|
commands::start_client(opts);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,11 +79,15 @@ impl ErrorInstruction for ClientInstruction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_server(socket_path: &Path) -> io::Result<()> {
|
fn spawn_server(socket_path: &Path, debug: bool) -> io::Result<()> {
|
||||||
let status = Command::new(current_exe()?)
|
let mut cmd = Command::new(current_exe()?);
|
||||||
.arg("--server")
|
cmd.arg("--server");
|
||||||
.arg(socket_path)
|
cmd.arg(socket_path);
|
||||||
.status()?;
|
if debug {
|
||||||
|
cmd.arg("--debug");
|
||||||
|
}
|
||||||
|
let status = cmd.status()?;
|
||||||
|
|
||||||
if status.success() {
|
if status.success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -168,7 +172,7 @@ pub fn start_client(
|
||||||
envs::set_session_name(name);
|
envs::set_session_name(name);
|
||||||
envs::set_initial_environment_vars();
|
envs::set_initial_environment_vars();
|
||||||
|
|
||||||
spawn_server(&*ZELLIJ_IPC_PIPE).unwrap();
|
spawn_server(&*ZELLIJ_IPC_PIPE, opts.debug).unwrap();
|
||||||
|
|
||||||
ClientToServerMsg::NewClient(
|
ClientToServerMsg::NewClient(
|
||||||
client_attributes,
|
client_attributes,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ pub const ZELLIJ_LAYOUT_DIR_ENV: &str = "ZELLIJ_LAYOUT_DIR";
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const DEFAULT_SCROLL_BUFFER_SIZE: usize = 10_000;
|
pub const DEFAULT_SCROLL_BUFFER_SIZE: usize = 10_000;
|
||||||
pub static SCROLL_BUFFER_SIZE: OnceCell<usize> = OnceCell::new();
|
pub static SCROLL_BUFFER_SIZE: OnceCell<usize> = OnceCell::new();
|
||||||
|
pub static DEBUG_MODE: OnceCell<bool> = OnceCell::new();
|
||||||
|
|
||||||
pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
|
pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
|
||||||
pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir();
|
pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir();
|
||||||
|
|
|
||||||
|
|
@ -547,10 +547,15 @@ mod not_wasm {
|
||||||
Ok(val) => crate::anyhow::Ok(val),
|
Ok(val) => crate::anyhow::Ok(val),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let (msg, context) = e.into_inner();
|
let (msg, context) = e.into_inner();
|
||||||
Err(
|
if *crate::consts::DEBUG_MODE.get().unwrap_or(&true) {
|
||||||
crate::anyhow::anyhow!("failed to send message to channel: {:#?}", msg)
|
Err(
|
||||||
.context(context.to_string()),
|
crate::anyhow::anyhow!("failed to send message to channel: {:#?}", msg)
|
||||||
)
|
.context(context.to_string()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Err(crate::anyhow::anyhow!("failed to send message to channel")
|
||||||
|
.context(context.to_string()))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ use log4rs::encode::pattern::PatternEncoder;
|
||||||
use crate::consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR, ZELLIJ_TMP_LOG_FILE};
|
use crate::consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR, ZELLIJ_TMP_LOG_FILE};
|
||||||
use crate::shared::set_permissions;
|
use crate::shared::set_permissions;
|
||||||
|
|
||||||
const LOG_MAX_BYTES: u64 = 1024 * 100;
|
const LOG_MAX_BYTES: u64 = 1024 * 1024 * 16; // 16 MiB per log
|
||||||
|
|
||||||
pub fn configure_logger() {
|
pub fn configure_logger() {
|
||||||
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
|
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue