console-fmt-cli
v2.9.1
Published
Pretty console logger for Node.js CLI apps and services
Maintainers
Readme
console-fmt-cli
Elegant, colorized console logging for Node.js — with optional decimal-format-core formatters for prediction-market and trading bots.
Version 2.9.0 is the recommended latest release: everything from 2.8.x plus re-exported stake and currency helpers so bot repos can depend on a single package.
npm install console-fmt-cliInstall
npm install console-fmt-cli
# peer (optional but recommended for trading bots):
npm install decimal-format-coreNode.js 14+. decimal-format-core is loaded as a peer-style optional dependency — if missing, logger functions still work; formatters throw a clear require error.
Quick start
const { createLogger } = require('console-fmt-cli');
const log = createLogger('polymarket-bot', {
level: process.env.LOG_LEVEL || 'info',
timestamps: true,
child: true,
time: true,
});
const strategy = log.child('strategy');
strategy.info('started');Trading / stake formatting (2.9.0)
Re-exports from decimal-format-core:
const {
createLogger,
computeBoundedFraction,
computeKellyStake, // alias
formatCurrency,
formatStakeUsd, // alias
roundDecimal,
roundStake, // alias
} = require('console-fmt-cli');
const log = createLogger('stake', { timestamps: true });
const stake = computeKellyStake({
probability: 0.58,
allInPrice: 0.52,
bankroll: 2000,
maxStake: 100,
scaleFactor: 0.5,
});
log.info(`size $${formatStakeUsd(stake)} (${roundStake(stake)} raw)`);Logger API
createLogger(name, options?)
| Option | Default | Description |
|--------|---------|-------------|
| level | 'info' | Minimum level |
| timestamps | false | ISO-8601 prefix |
| color | true | ANSI colors |
| prefix | true | [name] tag |
| json | false | Adds log.json(obj) |
| child | false | Adds log.child(sub) |
| time | false | Adds log.time(label) |
Methods
log.debug(...args);
log.info(...args);
log.warn(...args);
log.error(...args);
log.json({ structured: true }); // when json: true
log.child('module'); // when child: true
const end = log.time('operation'); // when time: true
end();Recommended bot log.js wrapper
const { createLogger } = require('console-fmt-cli');
let root;
function getLogger(module) {
if (!root) {
root = createLogger('bot', {
level: process.env.LOG_LEVEL || 'info',
timestamps: true,
child: true,
time: process.env.LOG_TIME === '1',
color: process.stdout.isTTY,
});
}
return module ? root.child(module) : root;
}
module.exports = { getLogger };Why one dependency?
Trading templates previously imported:
- a CLI logger
- a stake math package
- duplicate rounding helpers
2.9.0 consolidates the common path: console-fmt-cli + optional decimal-format-core matches what open Polymarket bot scaffolds expect.
Version history
| Version | Highlights |
|---------|------------|
| 2.0.0 | Initial logger |
| 2.2.0 | JSON lines |
| 2.3.0 | Child loggers |
| 2.8.0 | Timers |
| 2.9.0 | decimal-format-core formatters, npm latest |
FAQ
Must I install decimal-format-core?
Only if you use formatCurrency, computeKellyStake, etc. Logging alone does not require it.
Pino / Winston?
Use this for developer-facing CLI output; pipe JSON logs from log.json() into your collector if needed.
License
MIT
