diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2022-10-17 15:34:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 15:34:06 +0000 |
commit | f26e73ce03241cab89ee75aa1853973c21b22fc1 (patch) | |
tree | cc1535da82bfbfa44bee577ea4c58887f9dc4f70 | |
parent | 2ae057d061db2dc4d41afe39cb40197d3d01c616 (diff) |
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.
-rw-r--r-- | src/commands.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | zellij-client/src/lib.rs | 16 | ||||
-rw-r--r-- | zellij-utils/src/consts.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/errors.rs | 13 | ||||
-rw-r--r-- | zellij-utils/src/logging.rs | 2 |
6 files changed, 25 insertions, 13 deletions
diff --git a/src/commands.rs b/src/commands.rs index 1acaf12f4..e9ab951bc 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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); start_server_impl(Box::new(os_input), path); } diff --git a/src/main.rs b/src/main.rs index 895bc8998..fa18f0900 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,7 @@ fn main() { { commands::kill_session(target_session); } else if let Some(path) = opts.server { - commands::start_server(path); + commands::start_server(path, opts.debug); } else { commands::start_client(opts); } diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index bac08715f..c48fd5575 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -79,11 +79,15 @@ impl ErrorInstruction for ClientInstruction { } } -fn spawn_server(socket_path: &Path) -> io::Result<()> { - let status = Command::new(current_exe()?) - .arg("--server") - .arg(socket_path) - .status()?; +fn spawn_server(socket_path: &Path, debug: bool) -> io::Result<()> { + let mut cmd = Command::new(current_exe()?); + cmd.arg("--server"); + cmd.arg(socket_path); + if debug { + cmd.arg("--debug"); + } + let status = cmd.status()?; + if status.success() { Ok(()) } else { @@ -168,7 +172,7 @@ pub fn start_client( envs::set_session_name(name); envs::set_initial_environment_vars(); - spawn_server(&*ZELLIJ_IPC_PIPE).unwrap(); + spawn_server(&*ZELLIJ_IPC_PIPE, opts.debug).unwrap(); ClientToServerMsg::NewClient( client_attributes, diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs index cb11315fc..52e2f2369 100644 --- a/zellij-utils/src/consts.rs +++ b/zellij-utils/src/consts.rs @@ -11,6 +11,7 @@ pub const ZELLIJ_LAYOUT_DIR_ENV: &str = "ZELLIJ_LAYOUT_DIR"; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const DEFAULT_SCROLL_BUFFER_SIZE: usize = 10_000; 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_DATA_DIR_PREFIX: &str = system_default_data_dir(); diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 5c872741b..a662ed246 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -547,10 +547,15 @@ mod not_wasm { Ok(val) => crate::anyhow::Ok(val), Err(e) => { let (msg, context) = e.into_inner(); - Err( - crate::anyhow::anyhow!("failed to send message to channel: {:#?}", msg) - .context(context.to_string()), - ) + if *crate::consts::DEBUG_MODE.get().unwrap_or(&true) { + Err( + 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())) + } }, } } diff --git a/zellij-utils/src/logging.rs b/zellij-utils/src/logging.rs index 2d94d7d89..fb068a645 100644 --- a/zellij-utils/src/logging.rs +++ b/zellij-utils/src/logging.rs @@ -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::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() { atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap(); |