fancy-log
fancy-log is a CommonJS console wrapper from the Gulp project. Every call writes a local-time `[HH:mm:ss]` prefix, then delegates its arguments to Node's Console formatting. The default function plus info and dir write to stdout; warn and error put their message on stderr. When terminal color support is detected, the timestamp uses Node's util.inspect date style. That is the complete product: it adds readable timestamps to build-script output, not structured fields, transports, filtering, persistence, or application logging policy.
Good at one narrow job: timestamping human-readable Gulp and build-script output. Do not mistake it for an application logger; once logs need structure, filtering, test injection, or transport, use a purpose-built package.
Use it if
- You maintain a Gulpfile or small Node build script and want its existing output to match Gulp's timestamped console style
- You want console.log-style placeholders and object formatting with no logger configuration
- You need warn and error output routed to stderr while ordinary messages stay on stdout
- You need a simple --color and --no-color convention for build output
- You are logging from a production service: there are no JSON records, levels, serializers, redaction, child loggers, destinations, rotation, or async buffering
- You need timestamps that sort across hosts: the implementation prints locale time only, with no date, time zone, milliseconds, or ISO option
- You need log-level filtering: log.info, log.warn, and log.error select console methods and streams but every call is always emitted
- You need TypeScript or first-class ESM metadata: 2.0.0 has no declaration file, no exports map, and only a CommonJS main entry
- You need a currently evolving logger: 2.0.0 was published in January 2022 and GitHub reports the last repository push in December 2023
Setup reality
Installation is one command, npm install fancy-log, with no peer dependencies, native build, credentials, or config file. Version 2.0.0 requires Node 10.13 or newer and exposes a CommonJS function, so traditional Gulpfiles use const log = require('fancy-log'). In a native ESM file, Node can usually synthesize a default import from the CommonJS export, but the package publishes no exports map or TypeScript declarations. The behavior is deliberately global and fixed. On module load it creates a Node Console bound to process.stdout and process.stderr; there is no constructor for injecting a file, test stream, or remote destination. Each call writes the timestamp separately before Console writes the message, so output from concurrent writers can interleave between prefix and content. log and info use stdout; warn and error write their prefixes and messages to stderr; dir uses stdout. Color detection comes from color-support unless process.argv contains --color or --no-color, with --no-color checked first. Changing util.inspect.styles.date changes timestamp color for the whole process and can also affect other date inspection. The timestamp comes from Date.toLocaleTimeString('en', { hour12: false }), so it is local wall-clock time with seconds only. There is no setting for ISO time, UTC, milliseconds, labels, or suppressing the prefix. For testable or machine-ingested logs, wrap it behind your own function or choose a logger with stream injection and structured records.
Patterns
Write a timestamped messagelog-message
const log = require('fancy-log');
log('Compiling templates');
// [16:27:02] Compiling templatesThe timestamp uses the machine's local time and includes no date, time zone, or milliseconds.
Use Console-style placeholdersformat-values
const log = require('fancy-log');
log('Built %d files in %d ms', fileCount, elapsedMs);
log('Manifest: %j', manifest);Formatting follows Node Console behavior. Circular data cannot be rendered through the %j JSON placeholder.
Write an informational message to stdoutlog-info
log.info('Watching', sourceGlob);info is not a filterable severity level here. It always emits and uses stdout, just like the default log function.
Write a warning to stderrlog-warning
log.warn('Source map is missing for', filename);warn writes both its timestamp prefix and formatted message to stderr. The package does not count or suppress repeated warnings.
Write an error to stderrlog-error
try {
await build();
} catch (error) {
log.error('Build failed:', error);
process.exitCode = 1;
}Logging does not set a failing exit status or throw. Set process.exitCode or propagate the error yourself.
Inspect an object with log.dirinspect-object
log.dir({
task: 'styles',
inputs: ['src/main.css'],
cached: false,
});log.dir delegates to Console.dir and writes to stdout. fancy-log exposes no parameter for changing inspect depth or colors per call.
Disable timestamp color in CI outputdisable-color
node build.js --no-colorThe package scans process.argv for the literal --no-color flag on every call. This affects the timestamp, not ANSI codes produced by your message arguments.
Force timestamp colorforce-color
node build.js --colorIf both --color and --no-color are present, --no-color wins because it is checked first.
Change the timestamp's inspect colorchange-timestamp-color
const util = require('util');
const log = require('fancy-log');
util.inspect.styles.date = 'red';
log('Timestamp is red when color is enabled');util.inspect.styles is process-wide. This can change how other code styles Date values, not only fancy-log timestamps.
Report progress from a Gulp taskuse-in-gulp-task
const { src, dest } = require('gulp');
const log = require('fancy-log');
function copyAssets() {
log('Copying assets');
return src('src/assets/**/*').pipe(dest('dist/assets'));
}
exports.assets = copyAssets;Return the stream so Gulp knows when the task finishes. fancy-log only reports progress and does not participate in task completion.
Log a build-stream error without hiding itreport-stream-error
function reportError(error) {
log.error(error.stack || error.message);
this.emit('end');
}
stream.on('error', reportError);Emitting end is appropriate only for watch workflows that should continue. In CI, rethrow or fail the task so an error does not produce a successful build.
Use the CommonJS export from an ESM fileimport-from-esm
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const log = require('fancy-log');
log('Running from ESM');Version 2.0.0 publishes only a CommonJS main and no exports map. createRequire avoids depending on synthetic default-import behavior.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| pino | npm | Production Node services that need fast structured JSON, child loggers, redaction, and transports |
| winston | npm | Applications that need configurable levels, formats, and multiple output destinations |
| consola | npm | Developer-facing CLIs that want polished output, log levels, prompts, and reporter customization |
| debug | npm | Libraries that want namespace-based diagnostic output enabled through an environment variable |