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:
har7an 2022-10-17 15:34:06 +00:00 committed by GitHub
parent 2ae057d061
commit f26e73ce03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 13 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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,

View file

@ -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();

View file

@ -547,10 +547,15 @@ mod not_wasm {
Ok(val) => crate::anyhow::Ok(val),
Err(e) => {
let (msg, context) = e.into_inner();
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()))
}
},
}
}

View file

@ -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();