Console Patch
The console patch is the easiest way to add Logluxe to an existing project. Just import it once, and all your existing console.* calls are automatically enhanced with colors and formatting.
How It Works
// Add this single line at the top of your entry file
import 'logluxe/patch';
// That's it! All console methods are now enhanced
console.log('Regular log');
console.info('Info message'); // ℹ Info message (cyan)
console.warn('Warning!'); // ⚠ Warning! (yellow)
console.error('Error!'); // ✖ Error! (red)
console.debug('Debug info'); // ● Debug info (gray)
Enhanced Console Output
Regular log
ℹInfo message
⚠Warning!
✖Error!
●Debug info
🎮 Try Enhanced Console
Before & After
Before (Plain Console)
Plain Console (Before)
Regular log
Info message
Warning!
Error!
Debug info
After (With Patch)
Enhanced Console (After)
Regular log
ℹInfo message
⚠Warning!
✖Error!
●Debug info
Installation Points
Import the patch at the very top of your entry file:
Node.js / Express
// index.ts or server.ts
import 'logluxe/patch';
import express from 'express';
// ... rest of your code
Next.js
// next.config.js - for server-side
// or _app.tsx - for client-side
import 'logluxe/patch';
Vite / React
// main.tsx
import 'logluxe/patch';
import React from 'react';
import ReactDOM from 'react-dom/client';
CLI Application
#!/usr/bin/env node
import 'logluxe/patch';
// Your CLI code
console.info('CLI started');
Output
ℹCLI started
Features
Automatic Object Formatting
Objects are pretty-printed with syntax highlighting:
console.log('User:', { name: 'John', age: 30, active: true });
Output
User:
{
"name": "John",
"age": 30,
"active": true
}
🎮 Try Object Logging
Error Stack Traces
Errors are automatically formatted with highlighted stack traces:
console.error('Request failed:', new Error('Network timeout'));
Output
✖Request failed:
Error: Network timeout
at fetchData (api.ts:42:11)
at handleRequest (server.ts:15:5)
🎮 Try Error Logging
Preserved Functionality
All original console features still work:
// String substitution
console.log('Hello, %s!', 'World');
// Multiple arguments
console.log('a', 'b', 'c');
// Console methods not typically styled
console.table([{ a: 1 }, { a: 2 }]); // Works normally
console.time('operation'); // Works normally
console.timeEnd('operation'); // Works normally
Output
Hello, World!
a b c
Removing the Patch
If you need to restore the original console behavior:
import 'logluxe/patch';
import { unpatch } from 'logluxe/patch';
// Later, if needed
unpatch();
// Console is now back to normal
console.info('Plain info'); // No colors or icons
After unpatch()
Plain info
Accessing Original Console
If you need the original console methods while the patch is active:
import 'logluxe/patch';
import { getOriginalConsole } from 'logluxe/patch';
const originalConsole = getOriginalConsole();
// Use original console
originalConsole.log('Plain output');
// Patched console
console.log('Enhanced output');
Output
Plain output
Enhanced output
Conditional Patching
Apply the patch only in development:
// Only patch in development
if (process.env.NODE_ENV === 'development') {
await import('logluxe/patch');
}
Or use environment variables:
if (process.env.ENABLE_LOG_COLORS !== 'false') {
await import('logluxe/patch');
}
Comparison: Patch vs Logger API
| Feature | Console Patch | Logger API |
|---|---|---|
| Zero code changes | ✅ | ❌ |
| Semantic methods | ❌ | ✅ (log.success()) |
| Style builder | ❌ | ✅ (log.paint()) |
| Effects | ❌ | ✅ (gradient, neon) |
| Performance timing | ❌ | ✅ (log.perf()) |
| Grouping | Console native | ✅ Enhanced |
When to Use Each
Use Console Patch when:
- You have an existing codebase with many
console.*calls - You want quick, zero-effort enhancement
- You don't need advanced features like gradients or style builder
Use Logger API when:
- Starting a new project
- You want access to all features
- You need semantic logging (
log.success(),log.error()) - You want performance timing and grouping
Example: Express Server with Patch
// server.ts
import 'logluxe/patch';
import express from 'express';
const app = express();
app.use((req, res, next) => {
console.info(`${req.method} ${req.url}`);
next();
});
app.get('/', (req, res) => {
console.debug('Handling home route');
res.send('Hello World');
});
app.listen(3000, () => {
console.info('Server started on port 3000');
});
// Error handler
app.use((err, req, res, next) => {
console.error('Request failed:', err);
res.status(500).send('Internal Server Error');
});
Server Output
ℹServer started on port 3000
ℹGET /
●Handling home route
ℹGET /api/users
ℹPOST /api/users
✖Request failed: Error: Database connection lost
🎮 Try Server Logging
Next: Quick Start - Full Logluxe API guide →