| Crates.io | matomo-logger |
| lib.rs | matomo-logger |
| version | 0.1.0 |
| created_at | 2025-08-13 04:04:25.107155+00 |
| updated_at | 2025-08-13 04:04:25.107155+00 |
| description | Global logger that forwards Rust log records to console and Matomo (_paq) with browser/worker support |
| homepage | https://github.com/security-union/videocall-rs |
| repository | https://github.com/security-union/videocall-rs |
| max_upload_size | |
| id | 1793234 |
| size | 23,129 |
Global logger for WASM apps that forwards Rust log records to both the browser console and Matomo (_paq). Provides a one-line initialization and an SPA-friendly track_page_view helper. Optional worker bridge API lets you forward logs from Web Workers to the main thread, where they are pushed into Matomo.
log::Log)_paq is absent (configurable)track_page_view(title, url)set_user_id(user_id) (Matomo User ID)use matomo_logger::{MatomoConfig, MatomoLogger};
// Call as early as possible in your `main()`
let _ = MatomoLogger::init(MatomoConfig {
base_url: Some("https://matomo.example.com/".into()),
site_id: Some(1),
console_level: log::LevelFilter::Info,
matomo_level: log::LevelFilter::Warn, // keep Matomo volume sane
..Default::default()
});
// Later, on SPA route change:
matomo_logger::track_page_view("/home", "/home");
// From anywhere in your code:
log::warn!("Network jitter high: {} ms", 120);
The logger writes to the browser console at console_level and forwards records to Matomo at matomo_level. If Matomo is blocked or not available, logging continues to console without errors.
#[derive(Clone, Debug)]
pub struct MatomoConfig {
pub base_url: Option<String>, // e.g. https://matomo.example.com/
pub site_id: Option<u32>,
pub console_level: log::LevelFilter, // default: Info
pub matomo_level: log::LevelFilter, // default: Warn
pub inject_snippet: bool, // default: true
}
inject_snippet: If true and _paq is missing, the crate injects the Matomo snippet (setTrackerUrl, setSiteId, enableLinkTracking, and matomo.js). If your HTML already includes the Matomo snippet, you can keep it; the crate detects _paq and won’t inject again.matomo_level: strongly recommend Warn or higher to avoid analytics noise. Use Info only for short experiments.Use the built-in helper:
matomo_logger::track_page_view("/meeting/123", "/meeting/123");
It sends setCustomUrl, setDocumentTitle, and trackPageView via _paq if available. Calls are safe even when Matomo is blocked.
Workers do not have access to window._paq. Use the bridge API to forward worker logs to the main thread:
// In worker (requires feature = "worker")
use matomo_logger::worker;
let send = /* a js_sys::Function that posts messages to main thread */;
worker::init_with_bridge(log::LevelFilter::Info, log::LevelFilter::Warn, send)?;
// In the main thread, handle worker messages and push to Matomo
// (Implement a tiny router that converts {type:"log", level, target, message} to
// _paq.push(['trackEvent', 'RustLog', level, `${target} — ${message}`, value]))
matomo_level at Warn or above in production.MatomoLogger::init.max_event_len.Dual-licensed under either of:
LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)LICENSE-MIT or http://opensource.org/licenses/MIT)at your option.
See the repository’s main CHANGELOG for release notes.