slick-log
v1.0.6
Published
A powerful and flexible logging utility for Node.js applications
Readme
slick-log
A simple, yet flexible & powerful logging utility for Node.js applications with beautiful console output and file logging capabilities.
Features
- Beautiful colored console output with decorative borders for errors
- File logging disabled by default - only console logging until explicitly enabled
- File logging with automatic rotation
- Separate error log file
- Configurable log levels
- Timestamp formatting
- Log file size management
- Automatic log rotation
- TypeScript support
- Easy enable/disable file logging control
Installation
npm install slick-logQuick Start
import { Logger, LogLevel } from 'slick-log';
// Console logging only (default behavior)
Logger.info('This only goes to console');
Logger.success('Success message');
Logger.error('Error with decorative border');
// Optional: Set log level (defaults to INFO)
Logger.setLogLevel(LogLevel.DEBUG);
// Optional: Enable file logging
Logger.setLogFiles('./logs/app.log', './logs/error.log');
Logger.info('This goes to both console and files');
// Optional: Disable file logging again
Logger.disableFileLogging();
Logger.info('Back to console only');Log Levels
The logger supports the following log levels (in order of severity):
DEBUG(DEBG) - Detailed debugging informationINFO(INFO) - General information about program executionSUCCESS(SUCC) - Successful operationsWARN(WARN) - Warning messagesERROR(EROR) - Error messagesFATAL(FATL) - Fatal errors that may lead to program termination
Configuration
Log Level
import { Logger, LogLevel } from 'slick-log';
// Set minimum log level
Logger.setLogLevel(LogLevel.DEBUG);
// Get current log level
const currentLevel = Logger.getLogLevel();File Logging Control
import { Logger } from 'slick-log';
// Check if file logging is enabled (false by default)
const isEnabled = Logger.isFileLoggingEnabled();
// Enable file logging
Logger.setLogFiles('./logs/app.log', './logs/error.log');
// Disable file logging (console logging continues)
Logger.disableFileLogging();
// Configure file size (default: 100MB)
Logger.setMaxFileSize(50); // 50MB
// Configure number of rotated files (default: 5)
Logger.setMaxRotatedFiles(3);
// Wait for all pending file writes to complete
await Logger.waitForWrites();Output Format
Console Output
The logger provides beautiful, color-coded console output with centered log level labels:
- DEBUG: Gray background with white text
- INFO: Blue background with white text
- SUCCESS: Green background with black text
- WARN: Yellow background with black text
- ERROR: Red background with white text + decorative borders
- FATAL: Bright red background with white text + decorative borders
File Output
Log files contain entries in the following format:
YYYY-MM-DD HH:mm:ss [LEVEL] MessageDefault Behavior
- Console logging: Always enabled
- File logging: Disabled by default - only starts when you call
setLogFiles() - Log level: INFO (logs INFO, SUCCESS, WARN, ERROR, FATAL)
- File rotation: 100MB max size, keeps 5 rotated files
TypeScript Support
This package is written in TypeScript and includes type definitions.
License
ISC
