|
| 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 `LAND_DEV_LOG` 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 | +//! `LAND_DEV_LOG=channel-stub,git tail -f Mountain.dev.log` captures both |
| 17 | +//! sides filtered identically. |
| 18 | +//! |
| 19 | +//! ## Contract |
| 20 | +//! |
| 21 | +//! - `Tag` is matched against `LAND_DEV_LOG` exactly as Rust tags are; |
| 22 | +//! disabled tags produce no output (cheap no-op on the Mountain side). |
| 23 | +//! - `Message` is the fully-formatted log string - the caller has |
| 24 | +//! already done any interpolation. |
| 25 | +//! - The command is fire-and-forget from the renderer's perspective |
| 26 | +//! (returns `()` immediately); failures to write are swallowed. |
| 27 | +//! - Prefix `[RenderDevLog]` is added so grep can always separate |
| 28 | +//! TS-originated lines from native `dev_log!` entries that share the |
| 29 | +//! same tag. |
| 30 | +
|
| 31 | +#![allow(non_snake_case)] |
| 32 | + |
| 33 | +use crate::dev_log; |
| 34 | + |
| 35 | +#[tauri::command] |
| 36 | +pub fn RenderDevLog(Tag:String, Message:String) { |
| 37 | + // The `dev_log!` macro expands to a conditional on `IsEnabled(Tag)` |
| 38 | + // - when the tag is off, the entire call is a no-op besides the |
| 39 | + // string allocation on the caller side. `$Tag:expr` in the macro |
| 40 | + // accepts `&str` / `&String` / `String` interchangeably. |
| 41 | + let TagRef:&str = &Tag; |
| 42 | + dev_log!(TagRef, "[RenderDevLog] {}", Message); |
| 43 | +} |
0 commit comments