A beautiful, intelligent logger for Node.js with AI-powered error analysis
- Beautiful colored output with timestamps and file locations
- AI-powered error analysis with intelligent insights and fix suggestions
- Structured JSON logging for production environments
- Security hardened with input validation and sanitization
- TypeScript first with full type safety
- Zero dependencies for core functionality (AI features optional)
npm install @calphonse/loggerimport { logger } from '@calphonse/logger';
logger.info('Application started');
logger.warn('High memory usage detected');
logger.error('Database connection failed', { error: 'Connection timeout' });
logger.info('User login', {
userId: '12345',
method: 'email',
timestamp: new Date().toISOString(),
});
try {
throw new Error('Invalid JWT token');
} catch (error) {
logger.error('Auth failed', error);
}Errors automatically get intelligent analysis:
logger.error('Database error', new Error('Connection refused'));
// Output includes AI insights:
// AI Insight: Database connection failed
// Likely Causes: Service down, network issues, wrong credentials
// Suggested Fix: Check database service status and connection stringcurl -fsSL https://ollama.ai/install.sh | sh
ollama pull llama3.2:3b
# Or use cloud providers (OpenAI, Claude)
# Set environment variables: OPENAI_API_KEY, etc.import { Logger, LogLevel } from '@calphonse/logger';
const logger = new Logger({
level: LogLevel.INFO,
colors: true,
timestamps: true,
showSource: true,
prefix: '[MY-APP]',
json: false, // Set to true for production
ai: {
enabled: true,
provider: 'ollama', // 'openai' | 'claude' | 'disabled'
caching: true,
},
});import { LoggerFactory } from '@calphonse/logger';
const jsonLogger = LoggerFactory.createJsonLogger();
const minimalLogger = LoggerFactory.createMinimalLogger();
const verboseLogger = LoggerFactory.createVerboseLogger();const userLogger = logger.child('[USER]');
const dbLogger = logger.child('[DB]');
userLogger.info('User created', { userId: '123' });
dbLogger.error('Query failed', { query: 'SELECT * FROM users' });logger.error(message: string, data?: any): void
logger.warn(message: string, data?: any): void
logger.info(message: string, data?: any): void
logger.debug(message: string, data?: any): void
logger.trace(message: string, data?: any): void
logger.table(data: any[]): void
logger.child(prefix: string): Logger
logger.setLevel(level: LogLevel): voidenum LogLevel {
ERROR = 0, // Only errors
WARN = 1, // Warnings and errors
INFO = 2, // Info, warnings, and errors (default)
DEBUG = 3, // Debug and above
TRACE = 4, // Everything
}import express from 'express';
import { logger } from '@calphonse/logger';
const app = express();
app.use((req, res, next) => {
logger.info('Request', {
method: req.method,
url: req.url,
userAgent: req.get('User-Agent'),
});
next();
});
app.use((err, req, res, next) => {
logger.error('Request failed', err);
res.status(500).json({ error: 'Internal server error' });
});MIT License - see LICENSE file for details.
Made with care for the Node.js community
If this logger helps you debug faster, please give it a star on GitHub!