DoubleTie Logger Best Practices
Best practices and recommended patterns for using DoubleTie Logger effectively.
Best Practices
This page outlines best practices and recommended patterns for using DoubleTie Logger effectively in your applications.
Configure Log Levels by Environment
Adjust log levels based on the environment to balance visibility and performance:
Create Domain-Specific Loggers
Create specialized loggers for different parts of your application:
This approach:
- Makes logging calls more semantic
- Reduces repetition in your code
- Centralizes logging logic
- Makes it easier to add context specific to each domain
Never Log Sensitive Information
Be careful about what you log to avoid security issues:
Consider creating a utility function to sanitize data before logging:
Use Telemetry for Performance Insights
Integrate with OpenTelemetry for better performance monitoring:
Use Context Objects Consistently
Structure your log context objects consistently:
Keep Messages Actionable
Write log messages that help you understand what happened and what to do about it:
Use Proper Log Levels
Use the right log level for each message:
Level | When to Use |
---|---|
error | For fatal issues that need immediate attention - things that are broken |
warn | For potential issues that don't break functionality but should be addressed |
info | For important events in normal operation that should always be visible |
success | For successful completion of important operations |
debug | For detailed information useful during development or debugging |
Create a Logging Strategy
Define a consistent logging strategy across your application:
-
Entry/Exit Logs: Log at the beginning and end of important operations
-
Error Boundary Logs: Log at error boundaries
-
State Transition Logs: Log significant state changes
Initialize Early and Use Throughout
Initialize your logger early in your application lifecycle:
Then import and use it throughout your application:
Use with Dependency Injection
If you're using dependency injection, inject the logger:
Use Type Safety
Take advantage of TypeScript for better typing: