Logging Functions
Modelence provides three logging functions for different severity levels. These functions automatically integrate with your telemetry provider when enabled, while also supporting console output for local development.logDebug
UselogDebug for detailed debugging information that is typically only useful during development or troubleshooting.
- To telemetry provider: Always (when telemetry is enabled)
- To console: Only when
MODELENCE_LOG_LEVEL=debug
logInfo
UselogInfo for general informational messages about application flow and important events.
- To telemetry provider: Always (when telemetry is enabled)
- To console: When
MODELENCE_LOG_LEVEL=debugorMODELENCE_LOG_LEVEL=info
logError
UselogError for error conditions and exceptions that need attention.
- To telemetry provider: Always (when telemetry is enabled)
- To console: When
MODELENCE_LOG_LEVEL=debug,MODELENCE_LOG_LEVEL=info, orMODELENCE_LOG_LEVEL=error
Function Signature
All three logging functions accept the same parameters:- message: A descriptive string explaining what is being logged
- args: An object containing contextual data (user IDs, request details, etc.)
Environment Variables
MODELENCE_LOG_LEVEL
Controls the verbosity of console logging. This is especially useful during local development or when debugging production issues. Valid values:debug- Logs all messages (debug, info, and error) to consoleinfo- Logs info and error messages to consoleerror- Logs only error messages to console- Not set - No console logging (default when telemetry is enabled)
- When telemetry is enabled and
MODELENCE_LOG_LEVELis not set: No console logging - When telemetry is disabled and
MODELENCE_LOG_LEVELis not set: Defaults toinfolevel
Log Level Behavior Matrix
| Log Level | logDebug console | logInfo console | logError console | Telemetry |
|---|---|---|---|---|
debug | ✓ | ✓ | ✓ | ✓ (if enabled) |
info | ✗ | ✓ | ✓ | ✓ (if enabled) |
error | ✗ | ✗ | ✓ | ✓ (if enabled) |
| Not set (telemetry enabled) | ✗ | ✗ | ✗ | ✓ |
| Not set (telemetry disabled) | ✗ | ✓ | ✓ | ✗ |
Additional Telemetry Functions
Modelence also provides advanced telemetry functions for performance monitoring and error tracking:startTransaction
Track performance of operations like routes, methods, or background jobs:method- API method callsroute- HTTP route handlerscron- Scheduled jobsai- AI operationscustom- Custom operations
captureError
Capture and report errors to your telemetry provider:captureError falls back to console.error.
Best Practices
-
Use appropriate log levels: Reserve
logErrorfor actual errors, uselogInfofor important events, andlogDebugfor detailed troubleshooting information. -
Include context: Always provide relevant context in the
argsobject to make debugging easier: -
Avoid logging sensitive data: Never log passwords, API keys, or personally identifiable information (PII):
- Use transactions for performance tracking: Wrap important operations in transactions to monitor their performance and success rates.
-
Configure log levels per environment:
- Development:
MODELENCE_LOG_LEVEL=debugfor maximum visibility - Staging:
MODELENCE_LOG_LEVEL=infofor important events - Production: No
MODELENCE_LOG_LEVELset (rely on telemetry) orMODELENCE_LOG_LEVEL=errorfor critical issues only
- Development:
Telemetry Integration
By default, Modelence logs are sent to your configured telemetry provider (like Modelence Cloud). To configure telemetry for your application:- Visit cloud.modelence.com
- Select your project and environment
- Navigate to Application → Telemetry settings
- Configure your telemetry preferences
logDebug, logInfo, logError) automatically send data to your telemetry provider when it’s enabled, giving you centralized visibility into your application’s behavior.
Next Steps
- Learn about Authentication to add user management
- Explore Email configuration for transactional emails
- Review WebSockets for real-time features