parallel-logger
v1.0.1
Published
A creative two-column side-by-side logging system for Node.js
Maintainers
Readme
Parallel Logger
A creative two-column side-by-side logging system for Node.js that displays logs in separate columns simultaneously.
Features
- Side-by-side logging: Display multiple log streams in parallel columns
- ANSI color support: Color-coded loggers for better visual distinction
- TypeScript support: Full TypeScript definitions included
- Flexible positioning: Automatic column calculation or custom positioning
- Real-time output: Concurrent logging with proper cursor positioning
Installation
npm install parallel-loggerUsage
Basic Example
import { ParallelLogger, colors, clearScreen, getColumnPosition } from 'parallel-logger';
// Clear the screen
clearScreen();
// Create loggers for different columns
const systemLogger = new ParallelLogger('SYSTEM', getColumnPosition('left'), colors.RED);
const appLogger = new ParallelLogger('APP', getColumnPosition('right'), colors.GREEN);
// Start logging
systemLogger.log('System starting...');
appLogger.log('Application initialized');
// Continue logging...
setInterval(() => {
systemLogger.log(`Heartbeat ${Math.random().toFixed(2)}`);
}, 1000);
setInterval(() => {
appLogger.log(`Event ${Math.random().toFixed(2)}`);
}, 1500);Advanced Usage
import { ParallelLogger, colors } from 'parallel-logger';
// Custom column positions
const logger1 = new ParallelLogger('Logger1', 1, colors.BLUE);
const logger2 = new ParallelLogger('Logger2', 40, colors.YELLOW);
const logger3 = new ParallelLogger('Logger3', 80, colors.CYAN);
// Log with different intervals
setInterval(() => logger1.log('Fast log'), 500);
setInterval(() => logger2.log('Medium log'), 1000);
setInterval(() => logger3.log('Slow log'), 2000);CommonJS (require) Usage
If you're in a CommonJS environment (e.g., older Node setups without type: module):
const { ParallelLogger, colors, clearScreen, getColumnPosition } = require('parallel-logger');
clearScreen();
const left = new ParallelLogger('LEFT', getColumnPosition('left'), colors.BLUE);
const right = new ParallelLogger('RIGHT', getColumnPosition('right'), colors.GREEN);
left.log('Hello from CJS');
right.log('Hi from CJS');API Reference
ParallelLogger
Constructor
new ParallelLogger(name: string, column: number, color?: string)name: The logger name that appears in bracketscolumn: The column position (1-based)color: Optional ANSI color code
Methods
log(message: string): Log a message to the columnreset(): Reset the row position to 1
Utility Functions
clearScreen(): Clear the terminal screengetColumnPosition(position: 'left' | 'right' | number): Get column position'left': Column 1'right': Middle of terminal widthnumber: Custom column position
Colors
Available color constants:
colors.REDcolors.GREENcolors.BLUEcolors.YELLOWcolors.CYANcolors.MAGENTAcolors.WHITEcolors.RESET
Demo
Run the included demo:
npm run demoOr with Bun:
bun run demoRequirements
- Node.js >= 16.0.0
- Terminal that supports ANSI escape codes
License
MIT
Changelog
See CHANGELOG.md for release history.
Contributing
Contributions welcome! Please feel free to submit issues and pull requests.
