mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-25 02:27:00 -06:00
Settings: 56 of 59 not-yet-wired settings now change behaviour (nested-comp switches, constant vertex count, related-item time sync, match-name pick whip, split-layer order, Home on open, motion path span, internal wireframes, zoom quality, label-coloured tabs, mask colour cycling, gradients, grid/guide styles, text engine, font preview/recent/native names, missing frames, unlabeled alpha, drag import, default output folder, segmenting, bit depth names, preview sample rate, disk/media/conformed-audio caches, RAM reserve and low-memory reduction, Video Preview window, 3D reference axes/extended viewer/draft shadows, script file gate + File.execute warning, expression editor options and error banner). Three stay display-only and are documented. Features: Convert Audio to Keyframes, RPF Camera Import (JSON/CSV camera data), keyframe colour labels + Select Keyframe Label Group, Recent Animation Presets. Menus: Edit > History, File > Import Recent Footage, Replace Footage > With Layered Comp, Save a Copy As XML (.ecprojx, opens again), Composition > VR (Create VR Environment, Extract Cubemap), Assign Shortcut to 3D view / workspace, Window viewer labels + open viewers, Help > System Compatibility Report / Enable Logging / Reveal Logging File. Dynamic menu nodes (@dynamic:…) shared by the egui and native menus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.3 KiB
Rust
100 lines
3.3 KiB
Rust
//! Help ▸ Enable Logging / Reveal Logging File: a `log` logger that, while enabled, appends
|
|
//! every record to `Logs/EffectCraft Log.txt` in the settings folder (or the temporary folder),
|
|
//! and always keeps the last few hundred warnings and errors in memory for the System
|
|
//! Compatibility Report.
|
|
//!
|
|
//! Frontends call [`install`] once at startup; [`set_enabled`] (the `help.enableLogging`
|
|
//! command) turns file logging on and off.
|
|
|
|
use std::collections::VecDeque;
|
|
use std::io::Write;
|
|
use std::path::{Path, PathBuf};
|
|
use std::sync::Mutex;
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
static ENABLED: AtomicBool = AtomicBool::new(false);
|
|
static STATE: Mutex<State> = Mutex::new(State { file: None, recent: VecDeque::new() });
|
|
|
|
struct State {
|
|
file: Option<PathBuf>,
|
|
recent: VecDeque<String>,
|
|
}
|
|
|
|
struct Logger;
|
|
|
|
const RECENT: usize = 300;
|
|
|
|
impl log::Log for Logger {
|
|
fn enabled(&self, m: &log::Metadata) -> bool {
|
|
m.level() <= log::Level::Warn || (ENABLED.load(Ordering::Relaxed) && m.target().starts_with("effectcraft"))
|
|
}
|
|
fn log(&self, r: &log::Record) {
|
|
if !self.enabled(r.metadata()) {
|
|
return;
|
|
}
|
|
let line = format!("{} {:<5} {}: {}", unix_secs(), r.level(), r.target(), r.args());
|
|
let Ok(mut st) = STATE.lock() else { return };
|
|
if r.level() <= log::Level::Warn {
|
|
st.recent.push_back(line.clone());
|
|
if st.recent.len() > RECENT {
|
|
st.recent.pop_front();
|
|
}
|
|
}
|
|
if ENABLED.load(Ordering::Relaxed)
|
|
&& let Some(f) = &st.file
|
|
&& let Ok(mut out) = std::fs::OpenOptions::new().create(true).append(true).open(f)
|
|
{
|
|
let _ = writeln!(out, "{line}");
|
|
}
|
|
}
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
fn unix_secs() -> u64 {
|
|
web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0)
|
|
}
|
|
|
|
/// Install the logger (once; later calls and other installed loggers are left alone).
|
|
pub fn install() {
|
|
static LOGGER: Logger = Logger;
|
|
if log::set_logger(&LOGGER).is_ok() {
|
|
log::set_max_level(log::LevelFilter::Info);
|
|
}
|
|
}
|
|
|
|
/// The log file inside `config_dir` (the settings folder), or the temporary folder.
|
|
pub fn log_path(config_dir: Option<&Path>) -> PathBuf {
|
|
config_dir.map(Path::to_path_buf).unwrap_or_else(std::env::temp_dir).join("Logs").join("EffectCraft Log.txt")
|
|
}
|
|
|
|
/// Turn file logging on (writing to `file`) or off.
|
|
pub fn set_enabled(on: bool, file: PathBuf) -> std::io::Result<()> {
|
|
install();
|
|
if on {
|
|
if let Some(d) = file.parent() {
|
|
std::fs::create_dir_all(d)?;
|
|
}
|
|
let mut f = std::fs::OpenOptions::new().create(true).append(true).open(&file)?;
|
|
writeln!(f, "{} INFO effectcraft: logging enabled ({} {})", unix_secs(), std::env::consts::OS, env!("CARGO_PKG_VERSION"))?;
|
|
}
|
|
if let Ok(mut st) = STATE.lock() {
|
|
st.file = Some(file);
|
|
}
|
|
ENABLED.store(on, Ordering::Relaxed);
|
|
Ok(())
|
|
}
|
|
|
|
pub fn is_enabled() -> bool {
|
|
ENABLED.load(Ordering::Relaxed)
|
|
}
|
|
|
|
/// The current log file (set once logging was enabled).
|
|
pub fn current_file() -> Option<PathBuf> {
|
|
STATE.lock().ok().and_then(|s| s.file.clone())
|
|
}
|
|
|
|
/// Recent warnings and errors, oldest first.
|
|
pub fn recent() -> Vec<String> {
|
|
STATE.lock().map(|s| s.recent.iter().cloned().collect()).unwrap_or_default()
|
|
}
|