Logging Guide
Best practices for effective logging with Logstack, including log levels, context, and metadata.
Logging guide
Patterns that apply to all Logstack SDKs (JavaScript, Go, Python). Examples below use TypeScript; the same levels and metadata shape work in every client.
Zero-config collection: each SDK can auto-capture existing loggers —
JS console.* (source: "console"), Go stdlib log
(source: "go-log"), Python logging
(source: "python-logging"). Explicit SDK calls still win for structured metadata.
Log levels
Choose the appropriate level for each entry. All official SDKs support:
| Level | Color (Dev) | Use Case |
|---|---|---|
debug | Magenta | Detailed debugging information |
info | Cyan | General information, successful operations |
warn | Yellow | Warning conditions, potential issues |
error | Red | Errors that affect functionality |
critical | Red BG | Severe failures requiring immediate attention |
debug — Detailed Debugging
Use for verbose information useful during development.
Debug logs are great for development. In production, consider filtering them out or using sparingly.
info — General Information
Use for normal operations and successful events.
warn — Warning Conditions
Use for potentially harmful situations that don't block execution.
error — Error Conditions
Use for errors that affect functionality but allow continued operation.
critical — Critical Failures
Use for severe errors requiring immediate attention.
Set up alerts for critical logs to get notified immediately via push
notifications.
Log Context
Logstack automatically captures contextual information to help you trace where logs originated.
Automatic Context (Browser)
When captureContext: true (default), Logstack automatically captures:
Manual Context
Set context for a request or operation:
Context in Middleware
Structured Metadata
Always include relevant context as metadata:
Good: Structured and Searchable
Avoid: Unstructured Strings
Common Patterns
Request/Response Logging
Error with Stack Trace
Performance Metrics
User Actions
Best Practices
1. Be Consistent
Use the same metadata keys across your application:
2. Use Source Tags
Identify which service generated the log:
3. Avoid Sensitive Data
Never log passwords, tokens, or PII:
4. Include Correlation IDs
Track requests across services:
5. Log at Boundaries
Log when entering/exiting important operations: