Add logging
This commit is contained in:
parent
524c9806e9
commit
a577541b54
|
|
@ -13,7 +13,7 @@
|
|||
"@ffmpeg/ffmpeg": "^0.12.10",
|
||||
"@tauri-apps/plugin-dialog": "~2",
|
||||
"@tauri-apps/plugin-fs": "~2",
|
||||
"@tauri-apps/plugin-log": "~2",
|
||||
"@tauri-apps/plugin-log": "^2.2.0",
|
||||
"ffmpeg": "^0.0.4",
|
||||
"ffmpeg.js": "^4.2.9003"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ importers:
|
|||
specifier: ~2
|
||||
version: 2.0.2
|
||||
'@tauri-apps/plugin-log':
|
||||
specifier: ~2
|
||||
version: 2.0.1
|
||||
specifier: ^2.2.0
|
||||
version: 2.2.0
|
||||
ffmpeg:
|
||||
specifier: ^0.0.4
|
||||
version: 0.0.4
|
||||
|
|
@ -115,8 +115,8 @@ packages:
|
|||
'@tauri-apps/plugin-fs@2.0.2':
|
||||
resolution: {integrity: sha512-4YZaX2j7ta81M5/DL8aN10kTnpUkEpkPo1FTYPT8Dd0ImHe3azM8i8MrtjrDGoyBYLPO3zFv7df/mSCYF8oA0Q==}
|
||||
|
||||
'@tauri-apps/plugin-log@2.0.1':
|
||||
resolution: {integrity: sha512-zFT3S/Q5liMKIjPPdUZL8aNbjvhHvyfkhuqct3/MQ6/7rk4ODstcUPu320KJBjZrNNH/UM+kaQBGrioIwtmP/Q==}
|
||||
'@tauri-apps/plugin-log@2.2.0':
|
||||
resolution: {integrity: sha512-g6CsQAR1lsm5ABSZZxpM/iCn86GrMDTTlhj7GPkZkYBRSm3+WczfOAl7SV7HDn77tOKCzhZffwI5uHfRoHutrw==}
|
||||
|
||||
ffmpeg.js@4.2.9003:
|
||||
resolution: {integrity: sha512-l1JBr8HwnnJEaSwg5p8K3Ifbom8O2IDHsZp7UVyr6MzQ7gc32tt/2apoOuQAr/j76c+uDOjla799VSsBnRvSTg==}
|
||||
|
|
@ -188,7 +188,7 @@ snapshots:
|
|||
dependencies:
|
||||
'@tauri-apps/api': 2.1.1
|
||||
|
||||
'@tauri-apps/plugin-log@2.0.1':
|
||||
'@tauri-apps/plugin-log@2.2.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.1.1
|
||||
|
||||
|
|
|
|||
|
|
@ -485,8 +485,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
|||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
|
|
@ -2004,6 +2006,8 @@ dependencies = [
|
|||
name = "lightningbeam"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
|
@ -2012,6 +2016,8 @@ dependencies = [
|
|||
"tauri-plugin-fs",
|
||||
"tauri-plugin-log",
|
||||
"tauri-plugin-shell",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2074,6 +2080,15 @@ dependencies = [
|
|||
"tendril",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
||||
dependencies = [
|
||||
"regex-automata 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.10"
|
||||
|
|
@ -2198,6 +2213,16 @@ version = "0.1.14"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||
dependencies = [
|
||||
"overload",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
|
|
@ -2523,6 +2548,12 @@ dependencies = [
|
|||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||
|
||||
[[package]]
|
||||
name = "pango"
|
||||
version = "0.18.3"
|
||||
|
|
@ -3023,8 +3054,17 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
|||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
"regex-automata 0.4.8",
|
||||
"regex-syntax 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
dependencies = [
|
||||
"regex-syntax 0.6.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3035,9 +3075,15 @@ checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3"
|
|||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
"regex-syntax 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
|
|
@ -3434,6 +3480,15 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shared_child"
|
||||
version = "1.0.1"
|
||||
|
|
@ -4095,6 +4150,16 @@ dependencies = [
|
|||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.36"
|
||||
|
|
@ -4261,9 +4326,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
|||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.40"
|
||||
version = "0.1.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
|
||||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
|
|
@ -4272,9 +4337,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.27"
|
||||
version = "0.1.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -4283,11 +4348,41 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.32"
|
||||
version = "0.1.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
||||
checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||
dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
|
||||
dependencies = [
|
||||
"matchers",
|
||||
"nu-ansi-term",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4451,6 +4546,12 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "value-bag"
|
||||
version = "1.10.0"
|
||||
|
|
|
|||
|
|
@ -25,4 +25,9 @@ serde_json = "1"
|
|||
tauri-plugin-fs = "2"
|
||||
tauri-plugin-dialog = "2"
|
||||
tauri-plugin-log = "2"
|
||||
tracing = "0.1.41"
|
||||
# enable env-filter feature
|
||||
tracing-subscriber = {version = "0.3.19", features = ["env-filter"] }
|
||||
log = "0.4"
|
||||
chrono = "0.4"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,64 @@
|
|||
use tauri_plugin_log::{Target, TargetKind};
|
||||
use log::{trace, info, debug, warn, error};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use chrono::Local;
|
||||
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn trace(msg: String) {
|
||||
trace!("{}",msg);
|
||||
}
|
||||
#[tauri::command]
|
||||
fn info(msg: String) {
|
||||
info!("{}",msg);
|
||||
}
|
||||
#[tauri::command]
|
||||
fn debug(msg: String) {
|
||||
debug!("{}",msg);
|
||||
}
|
||||
#[tauri::command]
|
||||
fn warn(msg: String) {
|
||||
warn!("{}",msg);
|
||||
}
|
||||
#[tauri::command]
|
||||
fn error(msg: String) {
|
||||
error!("{}",msg);
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let pkg_name = env!("CARGO_PKG_NAME").to_string();
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.plugin(
|
||||
tauri_plugin_log::Builder::new()
|
||||
.timezone_strategy(tauri_plugin_log::TimezoneStrategy::UseLocal)
|
||||
.format(|out, message, record| {
|
||||
let date = Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
||||
out.finish(format_args!(
|
||||
"{}[{}] {}",
|
||||
date,
|
||||
record.level(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.targets([
|
||||
Target::new(TargetKind::Stdout),
|
||||
Target::new(TargetKind::LogDir { file_name: Some("logs".to_string()) }),
|
||||
Target::new(TargetKind::Webview),
|
||||
])
|
||||
.build(),
|
||||
)
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.invoke_handler(tauri::generate_handler![greet, trace, debug, info, warn, error])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
tracing_subscriber::fmt().with_env_filter(EnvFilter::new(format!("{}=trace", pkg_name))).init();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
lightningbeam_lib::run()
|
||||
lightningbeam_lib::run();
|
||||
}
|
||||
|
|
|
|||
38
src/main.js
38
src/main.js
|
|
@ -74,21 +74,42 @@ const { documentDir, join, basename, appLocalDataDir } = window.__TAURI__.path;
|
|||
const { Menu, MenuItem, PredefinedMenuItem, Submenu } = window.__TAURI__.menu;
|
||||
const { getCurrentWindow } = window.__TAURI__.window;
|
||||
const { getVersion } = window.__TAURI__.app;
|
||||
const { warn, debug, trace, info, error } = window.__TAURI__.log;
|
||||
|
||||
function forwardConsole(fnName, logger) {
|
||||
window.onerror = (message, source, lineno, colno, error) => {
|
||||
invoke("error", { msg: `${message} at ${source}:${lineno}:${colno}\n${error?.stack || ''}` });
|
||||
};
|
||||
|
||||
window.addEventListener('unhandledrejection', (event) => {
|
||||
invoke("error", { msg: `Unhandled Promise Rejection: ${event.reason?.stack || event.reason}` });
|
||||
});
|
||||
|
||||
function forwardConsole(fnName, dest) {
|
||||
const original = console[fnName];
|
||||
console[fnName] = (message) => {
|
||||
const error = new Error();
|
||||
const stackLines = error.stack.split("\n");
|
||||
|
||||
if (fnName === "error") {
|
||||
// Send the full stack trace for errors
|
||||
invoke(dest, { msg: `${message}\nStack trace:\n${stackLines.slice(1).join("\n")}` });
|
||||
} else {
|
||||
// For other log levels, just extract the file and line number
|
||||
const location = stackLines[stackLines.length - 1].match(/([a-zA-Z0-9_-]+\.js:\d+)/);
|
||||
invoke(dest, { msg: `${location ? location[0] : 'unknown'}: ${message}` });
|
||||
}
|
||||
|
||||
original(message);
|
||||
logger(message);
|
||||
};
|
||||
}
|
||||
|
||||
// forwardConsole('log', trace);
|
||||
// forwardConsole('debug', debug);
|
||||
// forwardConsole('info', info);
|
||||
// forwardConsole('warn', warn);
|
||||
// forwardConsole('error', error);
|
||||
forwardConsole('trace', "trace");
|
||||
forwardConsole('log', "trace");
|
||||
forwardConsole('debug', "debug");
|
||||
forwardConsole('info', "info");
|
||||
forwardConsole('warn', "warn");
|
||||
forwardConsole('error', "error");
|
||||
|
||||
console.log("*** Starting Lightningbeam ***")
|
||||
|
||||
// Debug flags
|
||||
const debugQuadtree = false;
|
||||
|
|
@ -200,6 +221,7 @@ let tools = {
|
|||
get: () => {
|
||||
if (context.selection.length != 1) return undefined;
|
||||
const selectedObject = context.selection[0];
|
||||
if (!(selectedObject.idx in context.activeObject.currentFrame.keys)) return;
|
||||
return context.activeObject.currentFrame.keys[selectedObject.idx]
|
||||
.playFromFrame;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue