Redirects API Reference
API reference for console and Next.js redirection utilities in DoubleTie Logger.
Redirects API Reference
This reference documents the console and Next.js redirection utilities in DoubleTie Logger.
redirectConsoleMethods(customLogger?)
Redirects global console methods to use a DoubleTie logger.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
customLogger | Logger | default logger | Logger to use instead of the default one |
Example:
Console to Logger Method Mapping:
Console Method | Logger Method |
---|---|
console.log | logger.info |
console.error | logger.error |
console.warn | logger.warn |
console.debug | logger.debug |
console.info | logger.info |
redirectNextjsLogger(customLogger?)
Redirects Next.js built-in logger to use the DoubleTie logger.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
customLogger | Logger | default logger | Logger to use instead of the default one |
Returns: Boolean indicating whether the redirection was successful
Note: This function will return false
if the Next.js logger is not available, which can happen if:
- Next.js is not installed
- The redirection is attempted before Next.js is fully loaded
- You're using a version of Next.js that has a different internal logger structure
Example:
redirectAllLoggers(customLogger?)
Redirects all supported logging systems to use the DoubleTie logger.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
customLogger | Logger | default logger | Logger to use instead of the default one |
Returns: Object indicating which redirections were successfully applied
console
: Alwaystrue
(console redirection always succeeds)next
: Boolean indicating if Next.js redirection succeeded
Example:
Implementation Details
Console Redirection
The console redirection works by replacing the global console
methods with custom functions that:
- Call the corresponding logger method
- Preserve the original method's functionality (optionally)
- Handle all arguments correctly
Next.js Redirection
The Next.js redirection works by:
- Attempting to access the internal Next.js logger object
- Replacing its log functions with redirected versions
- Preserving its behavior while sending logs through the DoubleTie logger
Best Practices
Early Initialization
Environment-Specific Configuration
Client vs Server Handling
For Next.js applications with both client and server rendering:
Troubleshooting
Next.js Redirection Failing
If Next.js redirection fails, try:
- Delaying the redirection until after Next.js has initialized:
- Using a different approach for server vs client: