prettlog
v4.7.0
Published
A terminal logging utility that overwrites previous output, ideal for progress bars, live updates, and animations.
Downloads
8,934
Maintainers
Readme
prettlog
Log by overwriting the previous output in the terminal.
Useful for rendering progress bars, animations, etc.

It performs partial redraws when possible to reduce flicker.
Install
npm install prettlogUsage
import prettlog from 'prettlog';
const frames = ['-', '\\', '|', '/'];
let index = 0;
setInterval(() => {
const frame = frames[index = ++index % frames.length];
prettlog(
`
♥♥
${frame} unicorns ${frame}
♥♥
`
);
}, 80);You can use yoctocolors or chalk to colorize the output.
API
prettlog(text…)
Log to stdout.
prettlog.clear()
Clear the logged output.
prettlog.done()
Persist the logged output.
Useful if you want to start a new log session below the current one.
prettlog.persist(text…)
Write text to the terminal that persists, similar to console.log().
Unlike the main prettlog() method which upgrades in place, persist() writes to the terminal in a way that preserves the output in the scrollback history.
import prettlog from 'prettlog';
// Upgrade in place
prettlog('Processing...');
prettlog('Still processing...');
// Write permanent output
prettlog.persist('✓ Task complete');
// Continue updating
prettlog('Next task...');prettlogStderr(text…)
Log to stderr.
prettlogStderr.clear()
prettlogStderr.done()
prettlogStderr.persist(text…)
createprettlog(stream, options?)
Get a prettlog method that logs to the specified stream.
options
Type: object
showCursor
Type: boolean
Default: false
Show the cursor. This can be useful when a CLI accepts input from a user.
import {createprettlog} from 'prettlog';
// Write output but don't hide the cursor
const log = createprettlog(process.stdout, {
showCursor: true
});defaultWidth
Type: number
Default: 80
The width to use when the stream doesn't provide a columns property.
This is useful when the output is piped, redirected, or in environments where the terminal size is not available.
import {createprettlog} from 'prettlog';
// Use custom width when the stream doesn't provide columns
const log = createprettlog(process.stdout, {
defaultWidth: 120
});defaultHeight
Type: number
Default: 24
The height to use when the stream doesn't provide a rows property.
This is useful when the output is piped, redirected, or in environments where the terminal size is not available.
import {createprettlog} from 'prettlog';
// Use custom height when the stream doesn't provide rows
const log = createprettlog(process.stdout, {
defaultHeight: 50
});Examples
- listr - Uses this module to render an interactive task list
- ora - Uses this module to render awesome spinners
- speed-test - Uses this module to render a spinner
