summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-12-24 23:50:02 +0100
committerqkzk <qu3nt1n@gmail.com>2023-12-24 23:50:02 +0100
commitf25cfbf20fb036ad27ebf7907b972db7cb8e4a58 (patch)
tree6f98f17c1722b340af0d926ded097c006e539c6a
parenta79651f4b350ae68e60e7dfc1136de1e0b37b80a (diff)
enable logging with CL argument -l --log. Nothing is logged otherwise
-rw-r--r--development.md3
-rw-r--r--readme.md12
-rw-r--r--src/app/tab.rs3
-rw-r--r--src/event/event_exec.rs4
-rw-r--r--src/io/args.rs4
-rw-r--r--src/io/log.rs27
6 files changed, 40 insertions, 13 deletions
diff --git a/development.md b/development.md
index be82c96..7acf515 100644
--- a/development.md
+++ b/development.md
@@ -725,6 +725,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- Configurable cli applications. See `~/fm/cli.yaml`
- Simplify tui config files. Remove `cwd` boolean parameter. Doesn't break old config files.
- Display the number of entries as the size of a directory instead of '-'. Might affect performance for very large directories.
+- Enable logging with `-l` or `--log`. Nothing is logged anywhere without this flag.
#### Changelog
@@ -754,7 +755,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] rename Action::Command to Action::Action since it's what it does
- [x] use number of files for dir size
- [x] rename Goto Mode to cd to allow `:` then `cd`
-- [ ] optionable logging
+- [x] optionable logging
- [ ] display number of matches while searching
- [x] FIX: Filter isn't shown and does nothing in tree mode
diff --git a/readme.md b/readme.md
index f0a3fc5..882f96b 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,7 @@
[docrs]: https://docs.rs/fm-tui/0.1.24
```
-A TUI file manager inspired by dired and ranger
+ A TUI file manager inspired by dired and ranger
Usage: fm [OPTIONS]
@@ -17,6 +17,7 @@ Options:
-p, --path <PATH> Starting path. directory or file [default: .]
-s, --server <SERVER> Nvim server [default: ]
-A, --all Display all files (hidden)
+ -l, --log Enable logging
-h, --help Print help
-V, --version Print version
```
@@ -170,6 +171,15 @@ Expansions :
- %n : selected filename
- %d : current directory
+### Logging
+
+With `-l` or `--log`, logs are enabled. They are disabled by default.
+
+Critical actions will be logged to `~/.config/fm/log/fm.log` and actions affecting the file tree will be logged to `~/.config/fm/log/action_logger.log`.
+
+The last action is displayed at the bottom of the screen and can be read with `Alt+l` like a preview.
+Those logs can be seen even if logging is disabled, it just won't be up to date.
+
### More
- Copy a filename/filepath to clipboard with Ctrl+n, Ctrl+p
diff --git a/src/app/tab.rs b/src/app/tab.rs
index b978b9f..a92febb 100644
--- a/src/app/tab.rs
+++ b/src/app/tab.rs
@@ -658,7 +658,8 @@ impl Tab {
/// Move the preview to the bottom
pub fn preview_go_bottom(&mut self) {
- self.window.scroll_to(self.preview.len() - 1)
+ self.window
+ .scroll_to(self.preview.len().checked_sub(1).unwrap_or_default())
}
/// Move 30 lines up or an image in Ueberzug.
diff --git a/src/event/event_exec.rs b/src/event/event_exec.rs
index d894d62..46daeb4 100644
--- a/src/event/event_exec.rs
+++ b/src/event/event_exec.rs
@@ -379,7 +379,9 @@ impl EventAction {
/// Display the last actions impacting the file tree
pub fn log(tab: &mut Tab) -> Result<()> {
- let log = read_log()?;
+ let Ok(log) = read_log() else {
+ return Ok(());
+ };
tab.set_display_mode(Display::Preview);
tab.preview = Preview::log(log);
tab.window.reset(tab.preview.len());
diff --git a/src/io/args.rs b/src/io/args.rs
index 7d4ac4f..b594699 100644
--- a/src/io/args.rs
+++ b/src/io/args.rs
@@ -15,4 +15,8 @@ pub struct Args {
/// Display all files (hidden)
#[arg(short = 'A', long, default_value_t = false)]
pub all: bool,
+
+ /// Enable logging
+ #[arg(short = 'l', long, default_value_t = false)]
+ pub log: bool,
}
diff --git a/src/io/log.rs b/src/io/log.rs
index 551f3d7..388e17f 100644
--- a/src/io/log.rs
+++ b/src/io/log.rs
@@ -1,27 +1,36 @@
use std::sync::RwLock;
use anyhow::Result;
+use clap::Parser;
use lazy_static::lazy_static;
use log4rs;
use crate::common::extract_lines;
use crate::common::{ACTION_LOG_PATH, LOG_CONFIG_PATH};
-
-// static ENV_HOME: &str = "$ENV{HOME}";
+use crate::io::Args;
/// Set the logs.
+/// First we read the `-l` `--log` command line argument which default to false.
+///
+/// If it's false, nothing is done and we return.
+/// No logger is set, nothing is logged.
+///
+/// If it's true :
/// The configuration is read from a config file defined in `LOG_CONFIG_PATH`
/// It's a YAML file which defines 2 logs:
/// - a normal one used directly with the macros like `log::info!(...)`, used for debugging
/// - a special one used with `log::info!(target: "special", ...)` to be displayed in the application
pub fn set_loggers() -> Result<()> {
- log4rs::init_file(
- shellexpand::tilde(LOG_CONFIG_PATH).as_ref(),
- Default::default(),
- )?;
- // clear_useless_env_home()?;
-
- log::info!("fm is starting");
+ let args = Args::parse();
+ if args.log {
+ log4rs::init_file(
+ shellexpand::tilde(LOG_CONFIG_PATH).as_ref(),
+ Default::default(),
+ )?;
+ // clear_useless_env_home()?;
+
+ log::info!("fm is starting with logs enabled");
+ }
Ok(())
}