pretty-pino-logger
v2.0.2
Published
A colorized logger utility similar to pino-pretty with support for multiple log levels, timestamps, and formatted output.
Maintainers
Readme
🪵 Logger System
A beautiful, feature-rich logging system for TypeScript/JavaScript applications with colorized output, emoji icons, and flexible configuration options.
✨ Features
- 🎨 Colorized Output - Beautiful ANSI color codes for different log levels
- 🎯 Emoji Icons - Visual indicators for each log level
- ⏰ Timestamps - ISO 8601 formatted timestamps (configurable)
- 📊 Multiple Log Levels - Trace, Debug, Info, Success, Warn, Error, and Fatal
- 🔧 Flexible Configuration - Customize timestamp and colorization per log call
- 🚀 Zero Dependencies - Lightweight and fast
- 📦 TypeScript Support - Full type safety included
📦 Installation
npm install your-logger-package
# or
yarn add your-logger-package🚀 Quick Start
import logger from './index';
// Simple logging
logger.info('Application started');
logger.success('Database connection established');
logger.warn('This is a warning');
logger.error('Something went wrong');
// With additional arguments
logger.debug('User data:', { id: 123, name: 'John' });
logger.error('Failed to connect:', error);📚 API Reference
Log Levels
The logger supports seven log levels, each with its own color and emoji:
| Level | Emoji | Color | Use Case |
|-------|-------|-------|----------|
| trace | 🔍 | Gray | Very detailed tracing information |
| debug | 🐛 | Cyan | Debug information for development |
| info | ℹ️ | Green | General informational messages |
| success | ✅ | Bright Green | Success messages and completed operations |
| warn | ⚠️ | Yellow | Warning messages |
| error | ❌ | Red | Error messages |
| fatal | 💀 | Magenta | Critical errors that may cause termination |
Methods
logger.trace(message: string, ...args: any[]): void
Logs a trace-level message.
logger.trace('Entering function');logger.debug(message: string, ...args: any[]): void
Logs a debug-level message.
logger.debug('Variable value:', variable);logger.info(message: string, ...args: any[]): void
Logs an info-level message.
logger.info('Server listening on port 3000');logger.success(message: string, ...args: any[]): void
Logs a success-level message. Perfect for indicating successful operations, completed tasks, or positive outcomes.
logger.success('User registration completed');
logger.success('Payment processed successfully', { transactionId: '12345' });logger.warn(message: string, ...args: any[]): void
Logs a warning-level message.
logger.warn('Deprecated API used');logger.error(message: string, ...args: any[]): void
Logs an error-level message.
logger.error('Failed to process request:', error);logger.fatal(message: string, ...args: any[]): void
Logs a fatal-level message.
logger.fatal('Critical system failure');logger.log(level: LogLevel, message: string, ...args: any[]): void
Generic log method that accepts a log level as the first parameter.
logger.log('info', 'Custom log level');🎨 Output Format
The logger formats messages as follows:
[2024-01-15T10:30:45.123Z] ℹ️ INFO Your message hereFormat breakdown:
[timestamp]- ISO 8601 formatted timestamp (optional)emoji- Visual indicator for the log levelLEVEL- Uppercase log level name (padded to 5 characters)message- Your log message- Color coding applied based on log level
💡 Examples
Basic Usage
import logger from './index';
// Different log levels
logger.trace('Detailed trace information');
logger.debug('Debugging information');
logger.info('Application started successfully');
logger.success('User logged in successfully');
logger.warn('This feature is deprecated');
logger.error('An error occurred');
logger.fatal('Critical failure');With Additional Data
// Logging objects and arrays
logger.debug('User object:', { id: 1, name: 'Alice' });
logger.info('Processing items:', [1, 2, 3, 4, 5]);
// Logging errors
try {
// some code
} catch (error) {
logger.error('Exception caught:', error);
}Dynamic Logging
const level = 'info';
logger.log(level, 'Dynamic log level');🔧 Configuration
The logger uses sensible defaults but supports configuration through the LogOptions interface:
interface LogOptions {
level?: LogLevel;
timestamp?: boolean; // Default: true
colorize?: boolean; // Default: true
}Note: Currently, the logger applies default formatting to all messages. Future versions may support per-message configuration.
🎯 Use Cases
- Development - Use
traceanddebugfor detailed development logs - Production - Use
info,warn, anderrorfor production logging - Monitoring - Use
fatalfor critical issues that require immediate attention - Debugging - Use
debugto track variable values and execution flow
🌟 Best Practices
- Use appropriate log levels - Don't use
errorfor warnings orinfofor debug messages - Include context - Add relevant data to help diagnose issues
- Avoid logging sensitive data - Never log passwords, tokens, or personal information
- Use structured logging - Pass objects as additional arguments for better parsing
- Set log levels per environment - Consider filtering logs based on environment
📝 Example Output
[2024-01-15T10:30:45.123Z] 🔍 TRACE Entering authentication function
[2024-01-15T10:30:45.124Z] 🐛 DEBUG User ID: 12345
[2024-01-15T10:30:45.125Z] ℹ️ INFO Processing authentication request
[2024-01-15T10:30:45.126Z] ✅ SUCCESS User authenticated successfully
[2024-01-15T10:30:45.127Z] ⚠️ WARN Using deprecated authentication method
[2024-01-15T10:30:45.128Z] ❌ ERROR Failed to connect to database
[2024-01-15T10:30:45.129Z] 💀 FATAL Critical system failure detected🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
[Your License Here]
🙏 Acknowledgments
Built with ❤️ for the developer community.
Made with care | Simple, beautiful, and effective logging for your applications
