aboutsummaryrefslogtreecommitdiff
path: root/src/logging.rs
diff options
context:
space:
mode:
authorrottedfm <rottedfm@proton.me>2026-08-19 11:24:55 -0400
committerrottedfm <rottedfm@proton.me>2026-08-19 11:24:55 -0400
commit8e16347b0eb329e84892af8ece36886324c95f62 (patch)
treebe1267972b5de2f1ae592577dfabce67f1fe6e87 /src/logging.rs
parentc6ae4660d1cc2414b22c492c5e819d009c8187c2 (diff)
parentea0bd36167b684c0accdb5ce2b2e21b8d84aeb25 (diff)
Merge branch 'buffer-implementation'HEADmain
Establishes the first working baseline: moji <file> opens a file into a ropey rope and edits it with Helix selection-first modal editing, under a DO-178C DAL-C requirements and traceability process. Prior to this, main tracked four files and src/main.rs was still println!("Hello, world!") — there was no buildable state to build on. Verified on a fresh clone of the branch with no untracked files: cargo build; clippy --all-targets -D warnings clean; 294 tests passing; scripts/check-trace.sh reports 98/98 requirements traced in both directions. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/logging.rs')
-rw-r--r--src/logging.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/logging.rs b/src/logging.rs
new file mode 100644
index 0000000..fd4e0b6
--- /dev/null
+++ b/src/logging.rs
@@ -0,0 +1,36 @@
+use std::sync::LazyLock;
+
+use tracing_error::ErrorLayer;
+use tracing_subscriber::{EnvFilter, fmt, prelude::*};
+
+use crate::config;
+
+pub static LOG_ENV: LazyLock<String> =
+ LazyLock::new(|| format!("{}_LOG_LEVEL", config::PROJECT_NAME.clone()));
+pub static LOG_FILE: LazyLock<String> = LazyLock::new(|| format!("{}.log", config::APP_NAME));
+
+pub fn init() -> color_eyre::Result<()> {
+ let directory = config::get_data_dir();
+ std::fs::create_dir_all(directory.clone())?;
+ let log_path = directory.join(LOG_FILE.clone());
+ let log_file = std::fs::File::create(log_path)?;
+ let env_filter = EnvFilter::builder().with_default_directive(tracing::Level::INFO.into());
+ // If the `RUST_LOG` environment variable is set, use that as the default, otherwise use the
+ // value of the `LOG_ENV` environment variable. If the `LOG_ENV` environment variable contains
+ // errors, then this will return an error.
+ let env_filter = env_filter
+ .try_from_env()
+ .or_else(|_| env_filter.with_env_var(LOG_ENV.clone()).from_env())?;
+ let file_subscriber = fmt::layer()
+ .with_file(true)
+ .with_line_number(true)
+ .with_writer(log_file)
+ .with_target(false)
+ .with_ansi(false)
+ .with_filter(env_filter);
+ tracing_subscriber::registry()
+ .with(file_subscriber)
+ .with(ErrorLayer::default())
+ .try_init()?;
+ Ok(())
+}