Skip to main content

Mountain/Binary/IPC/
RenderDevLogCommand.rs

1//! # RenderDevLogCommand
2//!
3//! Bridges TypeScript-side tagged logs (Wind / Sky / Cocoon running in the
4//! WebView) into Mountain's `dev_log!` file sink so a single
5//! `Mountain.dev.log` carries the complete tag-filterable picture of a
6//! session, not just the Rust portion.
7//!
8//! ## Why
9//!
10//! Wind's `Function/DevLog.ts` prints to `console.log`, visible only in
11//! DevTools. Mountain's `dev_log!` writes to a timestamped
12//! `Mountain.dev.log` with `Trace` tag filtering. The two observe
13//! the same boot but the outputs live in two places - reviewing a session
14//! means cross-referencing browser console + tail-f on the file. This
15//! command lets any TS caller mirror a tagged line into the file sink so
16//! `Trace=channel-stub,git tail -f Mountain.dev.log` captures both
17//! sides filtered identically.
18//!
19//! ## Contract
20//!
21//! - `Tag` is matched against `Trace` exactly as Rust tags are; disabled tags
22//!   produce no output (cheap no-op on the Mountain side).
23//! - `Message` is the fully-formatted log string - the caller has already done
24//!   any interpolation.
25//! - The command is fire-and-forget from the renderer's perspective (returns
26//!   `()` immediately); failures to write are swallowed.
27//! - Prefix `[RenderDevLog]` is added so grep can always separate TS-originated
28//!   lines from native `dev_log!` entries that share the same tag.
29
30#![allow(non_snake_case)]
31
32use crate::dev_log;
33
34/// Accept BOTH casings for the tag/message parameter names so the JS
35/// caller doesn't have to guess Tauri's param-case transform. In Tauri
36/// v2 default convention, Rust snake_case params get mapped to/from JS
37/// camelCase; Rust PascalCase params are passed through case-sensitive.
38/// Callers that send `{ Tag, Message }` (PascalCase) and callers that
39/// send `{ tag, message }` (snake_case) both work - the command
40/// coalesces whichever is populated. Empty → silent no-op.
41#[tauri::command]
42pub async fn RenderDevLog(
43	Tag:Option<String>,
44	Message:Option<String>,
45	tag:Option<String>,
46	message:Option<String>,
47) -> Result<(), String> {
48	let ResolvedTag = Tag.or(tag).unwrap_or_default();
49	let ResolvedMessage = Message.or(message).unwrap_or_default();
50	if ResolvedTag.is_empty() {
51		return Ok(());
52	}
53	let TagRef:&str = &ResolvedTag;
54	dev_log!(TagRef, "[RenderDevLog] {}", ResolvedMessage);
55	Ok(())
56}