Logging & Crashlytics
Zudoku supports Firebase Crashlytics and Google Cloud Logging for structured observability. All logs use a consistent format and never include secrets or PII.
Structured Log Format
Logs use JSON with these fields:
- event: Event name/category
- level:
debug|info|warn|error - component: Component/module name (e.g.
zudoku,zudoku-cli) - message: Human-readable message
- timestamp: ISO 8601 (when applicable)
Example:
Code
Never log secrets or PII. Use sanitizeForLogging() from zudoku/lib/logging when handling
user input or sensitive data.
Server-Side: Cloud Logging (Node/TS)
When FIREBASE_PROJECT_ID and GOOGLE_APPLICATION_CREDENTIALS are set, the Zudoku dev server sends
info, warn, and error logs to Google Cloud Logging.
Setup
- Create a Google Cloud service account with Logs Writer role.
- Download the JSON key.
- Set environment variables:
Code
Or use .env:
Code
Usage
The Zudoku logger automatically forwards logs when Cloud Logging is enabled. No code changes are required.
Client-Side: Firebase Crashlytics (React)
To enable Firebase Crashlytics for client-side error reporting:
- Install the Firebase peer dependency:
pnpm add firebase - Set public env vars (via
.envorZUDOKU_PUBLIC_*in config):
Code
Crashlytics initializes automatically when these are set. Uncaught errors and unhandled promise rejections are reported to Firebase Crashlytics.
Go CLI: Cloud Logging
The Zudoku CLI (zudoku-cli) uses structured JSON logs. When FIREBASE_PROJECT_ID and
GOOGLE_APPLICATION_CREDENTIALS are set, logs are also sent to Google Cloud Logging.
Code
Firebase Config
A minimal firebase.json at the project root can be used for Firebase CLI tooling:
Code
Replace your-firebase-project-id with your actual Firebase/GCP project ID.
Best Practices
- Use structured fields (
event,level,component,message) consistently. - Never log API keys, passwords, tokens, or PII (emails, SSNs, etc.).
- Prefer
infofor normal operations,warnfor recoverable issues,errorfor failures. - In production, keep
LOG_LEVELatinfoorwarnto avoid excessive logs.