Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
clean up old logs and make Sentry optional
PJ527b5eaf0224
diff --git a/.env.example b/.env.exampleindex f2af00b7d..a13e9abfd 100644--- a/.env.example+++ b/.env.example@@ -18,6 +18,8 @@NEXT_PUBLIC_ENVIRONMENT=developmentNEXT_PUBLIC_URL=http://localhost:3000NEXT_PUBLIC_TASKS_URL=http://localhost:3002+# For error reporting to Sentry. Replace with an empty string to disable.+CAP_DESKTOP_SENTRY_URL=https://efd3156d9c0a8a49bee3ee675bec80d8@o4506859771527168.ingest.us.sentry.io/4506859844403200# IMPORTANT FOR LOCAL DEV:# This determines whether or not the app will run in "local mode".@@ -51,4 +53,4 @@ RESEND_API_KEY=# - MISC, NOT REQUIRED FOR DEV ****************-NEXT_LOOPS_KEY=\ No newline at end of file+NEXT_LOOPS_KEY=diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.mdnew file mode 100644index 000000000..3a9cb5a15--- /dev/null+++ b/.github/ISSUE_TEMPLATE/bug_report.md@@ -0,0 +1,30 @@+---+name: Bug report+about: Report a crash, error, or other unusual behaviour by Cap+title: ''+labels: bug+assignees: ''++---++### Description++<!-- What went wrong? What were you expecting to happen? Please provide as much information as possible. -->++### Reproduction++<!-- If you can remember, list the steps to trigger the bug -->++### Additional Context++- Cap version:+- Operating system, version:+- Device (optional):++<!-- Add or attach any screenshots, logs, etc that might help.+Cap's debug logs can be found in the following locations:++macOS: /Users/{your username}/Library/Logs/so.cap.desktop+Linux: /home/{your username}/.config/so.cap.desktop/logs+Windows: C:\Users\{your username}\AppData\Roaming\so.cap.desktop\logs+-->diff --git a/.github/workflows/main.yml b/.github/workflows/main.ymlindex 884182c9d..2c6002e04 100644--- a/.github/workflows/main.yml+++ b/.github/workflows/main.yml@@ -50,6 +50,7 @@ jobs:echo "appVersion=${{ steps.get_version.outputs.appVersion }}" >> apps/desktop/.envecho "NEXT_PUBLIC_ENVIRONMENT=production" >> apps/desktop/.envecho "NEXT_PUBLIC_LOCAL_MODE=false" >> apps/desktop/.env+ echo "CAP_DESKTOP_SENTRY_URL=https://efd3156d9c0a8a49bee3ee675bec80d8@o4506859771527168.ingest.us.sentry.io/4506859844403200" >> apps/desktop/.env- name: Output .env filerun: cat apps/desktop/.envdiff --git a/Cargo.lock b/Cargo.lockindex 425444ff4..61509b638 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -624,7 +624,7 @@ dependencies = ["capture","chrono","cpal",- "dotenv_codegen",+ "dotenvy_macro","ffmpeg-sidecar","fix-path-env","futures",@@ -1241,29 +1241,18 @@ dependencies = [][[package]]-name = "dotenv"-version = "0.15.0"+name = "dotenvy"+version = "0.15.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"+checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"[[package]]-name = "dotenv_codegen"-version = "0.15.0"+name = "dotenvy_macro"+version = "0.15.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "56966279c10e4f8ee8c22123a15ed74e7c8150b658b26c619c53f4a56eb4a8aa"+checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424"dependencies = [- "dotenv_codegen_implementation",- "proc-macro-hack",-]--[[package]]-name = "dotenv_codegen_implementation"-version = "0.15.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "53e737a3522cd45f6adc19b644ce43ef53e1e9045f2d2de425c1f468abd4cf33"-dependencies = [- "dotenv",- "proc-macro-hack",+ "dotenvy","proc-macro2","quote","syn 1.0.109",diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.tomlindex 124a07614..7d05c542c 100644--- a/apps/desktop/src-tauri/Cargo.toml+++ b/apps/desktop/src-tauri/Cargo.toml@@ -60,7 +60,7 @@ tauri-plugin-deep-link = { git = "https://github.com/FabianLars/tauri-plugin-deewindow-vibrancy = "0.4.3"window-shadows = "0.2.2"chrono = "0.4.33"-dotenv_codegen = "0.15.0"+dotenvy_macro = "0.15.7"byteorder = "1.4.3"bytemuck = "1.14.3"regex = "1"diff --git a/apps/desktop/src-tauri/src/app/config.rs b/apps/desktop/src-tauri/src/app/config.rsindex 047ab5748..db95f39f7 100644--- a/apps/desktop/src-tauri/src/app/config.rs+++ b/apps/desktop/src-tauri/src/app/config.rs@@ -1,11 +1,16 @@+use sentry::types::Dsn;+use std::env;use tracing::Level;// TODO: More flexible configuration? For instance, using a custom `CAP_LOGGING_LEVEL` (or something similar)pub fn logging_level() -> Level {#[cfg(debug_assertions)]{- let maybe_level = std::env::var("RUST_LOG").unwrap_or("INFO".into());+ let maybe_level = env::var("RUST_LOG").unwrap_or("INFO".into());if let Ok(level) = str::parse(&maybe_level) {+ if level == Level::TRACE && env::var("RUST_BACKTRACE").is_err() {+ env::set_var("RUST_BACKTRACE", "1");+ }return level;}}@@ -13,9 +18,15 @@ pub fn logging_level() -> Level {Level::INFO}+#[inline]pub fn is_local_mode() -> bool {- match dotenv_codegen::dotenv!("NEXT_PUBLIC_LOCAL_MODE") {+ match dotenvy_macro::dotenv!("NEXT_PUBLIC_LOCAL_MODE") {"true" => true,_ => false,}}++#[inline]+pub fn sentry_dsn() -> Option<Dsn> {+ str::parse(dotenvy_macro::dotenv!("CAP_DESKTOP_SENTRY_URL")).ok()+}diff --git a/apps/desktop/src-tauri/src/app/mod.rs b/apps/desktop/src-tauri/src/app/mod.rsindex ef68c3694..4e5652649 100644--- a/apps/desktop/src-tauri/src/app/mod.rs+++ b/apps/desktop/src-tauri/src/app/mod.rs@@ -1 +1,59 @@+use std::{+ backtrace::{Backtrace, BacktraceStatus},+ panic::PanicInfo,+ path::PathBuf,+ time::{Duration, SystemTime},+};+use tauri::{Assets, Context};+use tracing_appender::rolling::RollingFileAppender;+pub mod config;++pub fn panic_hook(info: &PanicInfo) {+ tracing::error!("Thread panicked: {:?}", info);+ // If the panic has a source location, record it as structured fields.+ if let Some(location) = info.location() {+ let backtrace = Backtrace::capture();+ tracing::error!(+ panic.file = format!("{}:{}", location.file(), location.line()),+ panic.column = location.column(),+ message = %info,+ );+ if backtrace.status() == BacktraceStatus::Captured {+ tracing::error!(backtrace = %backtrace);+ }+ } else {+ tracing::error!(message = %info);+ }+}++pub fn get_log_file<A: Assets>(context: &Context<A>) -> RollingFileAppender {+ let log_directory = tauri::api::path::app_log_dir(context.config()).unwrap_or_else(|| {+ println!("Using current directory as log directory");+ PathBuf::new().join("logs")+ });++ if let Ok(old_logs) = std::fs::read_dir(&log_directory) {+ // Only keep logs around for a week.+ // You can dodge this removal by moving logs you want to keep to a subdirectory.+ let age_limit = SystemTime::now() - Duration::from_secs(7 * 86_400);++ println!(+ "Deleting logs older than a week from {}",+ log_directory.display()+ );++ for log in old_logs+ .filter_map(|entry_result| entry_result.ok())+ .filter(|entry| {+ entry.metadata().is_ok_and(|metadata| {+ metadata.is_file() && metadata.modified().is_ok_and(|time| time < age_limit)+ })+ })+ {+ let _ = std::fs::remove_file(log.path());+ }+ }++ tracing_appender::rolling::daily(log_directory, "cap_debug.log")+}diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rsindex 49985c91e..47f2fe747 100644--- a/apps/desktop/src-tauri/src/main.rs+++ b/apps/desktop/src-tauri/src/main.rs@@ -55,52 +55,39 @@ fn main() {let _ = fix_path_env::fix();let context = tauri::generate_context!();- let log_directory = tauri::api::path::app_log_dir(&context.config()).unwrap_or_else(|| {- println!("Using current directory as log directory");- PathBuf::new().join("logs")- });- let rolling_log = tracing_appender::rolling::daily(log_directory, "cap_debug.log");+ let rolling_log = app::get_log_file(&context);let (log_writer, _log_guard) = tracing_appender::non_blocking(rolling_log);- // TODO: Move this endpoint into environment variable/other external configuration- let _guard = sentry::init(("https://efd3156d9c0a8a49bee3ee675bec80d8@o4506859771527168.ingest.us.sentry.io/4506859844403200", sentry::ClientOptions {+ let sentry_guard = sentry::init(sentry::ClientOptions {+ dsn: app::config::sentry_dsn(),release: sentry::release_name!(),..Default::default()- }));+ });+ let maybe_sentry_subscriber =+ sentry_guard+ .is_enabled()+ .then_some(+ sentry_tracing::layer().event_filter(|metadata| match metadata.level() {+ &Level::WARN => EventFilter::Event,+ _ => EventFilter::Ignore,+ }),+ );tracing_subscriber::registry().with(tracing_subscriber::fmt::layer().with_writer(std::io::stdout.with_max_level(app::config::logging_level()))- .pretty()+ .pretty(),).with(tracing_subscriber::fmt::layer().with_writer(log_writer.with_max_level(Level::DEBUG))- .with_ansi(false)+ .with_ansi(false),)- .with(sentry_tracing::layer().event_filter(|metadata| {- match metadata.level() {- &Level::WARN => EventFilter::Event,- _ => EventFilter::Ignore,- }- }))+ .with(maybe_sentry_subscriber).init();- std::panic::set_hook(Box::new(|info| {- // TODO: More expressive panic data collection (configurable backtrace capture especially)- tracing::error!("Thread panicked: {:?}", info);- // If the panic has a source location, record it as structured fields.- if let Some(location) = info.location() {- tracing::error!(- panic.file = location.file(),- panic.line = location.line(),- message = %info,- );- } else {- tracing::error!(message = %info);- }- }));+ std::panic::set_hook(Box::new(app::panic_hook));fn handle_ffmpeg_installation() -> FfmpegResult<()> {if ffmpeg_is_installed() {@@ -221,7 +208,7 @@ fn main() {Some(max_mode) => {tracing::debug!("Maximum resolution: {:?}", max_mode.size());(max_mode.size().width, max_mode.size().height)- },+ }None => {tracing::debug!("Failed to determine maximum resolution.");(0, 0)diff --git a/apps/desktop/src-tauri/src/upload.rs b/apps/desktop/src-tauri/src/upload.rsindex 38fe07566..631ea8b9f 100644--- a/apps/desktop/src-tauri/src/upload.rs+++ b/apps/desktop/src-tauri/src/upload.rs@@ -49,7 +49,7 @@ pub async fn upload_file(options.user_id, options.video_id,);- let server_url_base: &'static str = dotenv_codegen::dotenv!("NEXT_PUBLIC_URL");+ let server_url_base: &'static str = dotenvy_macro::dotenv!("NEXT_PUBLIC_URL");let server_url = format!("{}/api/upload/signed", server_url_base);let body = match file_type {@@ -150,7 +150,8 @@ pub async fn upload_file(.unwrap_or_else(|_| "<no response body>".to_string());tracing::error!("Failed to upload file. Status: {}. Body: {}",- status, error_body+ status,+ error_body);return Err(format!("Failed to upload file. Status: {}. Body: {}",