loggix
v1.0.4
Published
Une bibliothèque de logging moderne et extensible
Maintainers
Readme
Loggix 🚀
A powerful, feature-rich logging library for Node.js applications that combines beautiful formatting with robust error handling and advanced features.
✨ Features
🎨 Beautiful Console Output
- Colored log levels
- Emoji support
- Customizable formatting
- Progress bars
- Tables and separators
- Title formatting
🔍 Advanced Logging
- Multiple log levels (error, warn, info, debug, verbose)
- Context and tags support
- Metadata handling
- Stack trace formatting
- Environment awareness
🛡️ Error Handling
- Automatic error catching
- Stack trace beautification
- Node.js internals filtering
- Custom error formatting
📊 Progress Tracking
- Customizable progress bars
- Speed calculation
- ETA estimation
- Percentage display
- Custom characters
💾 File Management
- Automatic log rotation
- Size-based rotation
- Configurable retention
- Multiple log formats (JSON/Pretty)
🚀 Quick Start
import { Loggix } from 'loggix';
// Create a logger instance
const logger = new Loggix({
level: 'info',
colors: true,
useEmojis: true,
environment: 'DEV'
});
// Basic logging
logger.info('Application started');
logger.error('Something went wrong', { error: new Error('Oops!') });
// With context and tags
logger.withTag('auth').withMetadata({ userId: 123 })
.info('User logged in');
// Pretty formatting
logger.separator('double');
logger.title('System Status');
logger.table({
status: 'running',
uptime: '2h 30m',
memory: '1.2GB'
});
// Progress tracking
const progress = logger.createProgressBar({
total: 100,
message: 'Processing files',
showSpeed: true,
showTimeRemaining: true
});
// Update progress
progress.increment(10);🎨 Formatting Examples
// Error with stack trace
logger.error(new Error('Database connection failed'));
// Output:
// ❌ ERROR [2024-03-14 10:30:15] Database connection failed
// Error: Database connection failed
// at Database.connect (/app/db.ts:42)
// at Server.start (/app/server.ts:15)
// Table output
logger.table({
'User ID': 123,
'Status': 'active',
'Last Login': '2024-03-14'
});
// Output:
// ┌──────────┬────────┐
// │ User ID │ 123 │
// │ Status │ active │
// │ Last │ 2024-03│
// └──────────┴────────┘
// Progress bar
const progress = logger.createProgressBar({
total: 100,
message: 'Downloading'
});
// Output:
// Downloading [████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 20% (50 units/s) ETA: 1m 30s⚙️ Configuration
const logger = new Loggix({
// Log level
level: 'info', // error, warn, info, debug, verbose
// Output options
colors: true,
useEmojis: true,
format: 'pretty', // or 'json'
// File options
logDir: 'logs',
maxFiles: 5,
maxSize: '10m',
// Environment
environment: 'PROD',
// Custom formatters
customFormatters: [/* ... */]
});🔧 Advanced Usage
Error Handling
// Errors are automatically caught and formatted
// No additional configuration needed!
// Custom error formatting with context
logger.error(new Error('Custom error'), {
context: 'Payment',
tags: ['critical', 'payment'],
metadata: {
orderId: '123',
amount: 99.99
}
});
// Output:
// ❌ ERROR [2024-03-14 10:30:15] [Payment] [critical, payment] Custom error
// Error: Custom error
// at PaymentProcessor.process (/app/payment.ts:42)
// at OrderService.create (/app/order.ts:15)
// Metadata: { orderId: '123', amount: 99.99 }Progress Tracking
const progress = logger.createProgressBar({
total: 100,
message: 'Processing',
width: 40,
showPercentage: true,
showSpeed: true,
showTimeRemaining: true,
character: '=',
incompleteCharacter: '-',
newLine: true
});
// Update progress
for (let i = 0; i < 100; i++) {
await processItem();
progress.increment();
}Custom Formatting
logger.separator('double');
logger.title('System Report');
logger.table({
'CPU Usage': '45%',
'Memory': '2.1GB',
'Disk Space': '75%'
});📦 Installation
npm install loggix
# or
yarn add loggix🔍 TypeScript Support
Full TypeScript support with comprehensive type definitions and interfaces.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📝 License
MIT License - feel free to use this library in your projects!
