loglevel-plugin-prefix review
loglevel-plugin-prefix 0.8.4 wraps loglevel's method factory so console messages can start with a timestamp, severity, or named-logger label. `reg(log)` installs the plugin once; `apply(logger, options)` selects a token template or a formatter. It changes presentation only. There are no JSON records, transports, redaction rules, files, or remote delivery. Our full browser build was 2.3 KB minified and 1.2 KB gzipped. The latest npm release is still the June 2018 build, and its README continues to label the API unstable despite years of practical immobility.
loglevel-plugin-prefix 0.8.4 installed in 0.5 seconds and added a 1.2 KB gzipped browser bundle in our sandbox, but npm has not released it since 2018. Keep it as small browser glue for an existing loglevel stack; do not mistake it for a production logging backend.
We installed it
| Install | ✓ · 0.5s | 1 package on disk · 1 MB |
| Import | ✓ | ESM import works · require() works · CommonJS package |
| Browser | 1.2 KB | gzipped (2.3 KB minified), bundled with esbuild |
| Types | ✓ | TypeScript types bundled |
| Known vulns | 0 | 0 critical · 0 high · 0 moderate · 0 low (npm audit) |
Answers from our run
Does loglevel-plugin-prefix install cleanly?
Yes. In a fresh container with an empty cache, npm install loglevel-plugin-prefix finished in 0.5s, leaving 1 package and 1 MB on disk. npm audit reported no known vulnerabilities.
How much does loglevel-plugin-prefix add to a browser bundle?
1.2 KB gzipped (2.3 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.
Does loglevel-plugin-prefix work with both ESM and CommonJS?
Yes. Both import 'loglevel-plugin-prefix' and require('loglevel-plugin-prefix') worked in Node 22 in our run. The package is published as CommonJS.
Does loglevel-plugin-prefix include TypeScript types?
Yes, type declarations ship inside the package, so no @types install is needed.
loglevel-plugin-prefix or loglevel: which should you use?
loglevel: Use loglevel alone and own a short methodFactory wrapper when one prefix convention is enough. loglevel-plugin-prefix 0.8.4 installed in 0.5 seconds and added a 1.2 KB gzipped browser bundle in our sandbox, but npm has not released it since 2018.
When should you not use loglevel-plugin-prefix?
Production needs structured JSON, serializers, redaction, child bindings, or transports; this plugin only prepends text
Use it if
- A browser application already uses loglevel and needs readable prefixes with little added code
- Named loglevel channels need distinct labels such as api, auth, or cache
- You only need synchronous formatting of level, logger name, and time
- A legacy script-tag page loads both packages as browser globals
- Production needs structured JSON, serializers, redaction, child bindings, or transports; this plugin only prepends text
- A new Node service needs a complete logging system; Pino or Winston covers output pipelines and active maintenance
- API guarantees matter because the README calls 0.8.4 unstable and promises compatibility only for patch releases
- TypeScript accuracy is mandatory; the bundled declaration types the custom formatter timestamp as Date although runtime supplies formatted text
- Several bundles may load separate plugin instances; an unresolved issue reports option inheritance surprises across modules
Setup reality
We installed loglevel-plugin-prefix 0.8.4 in 0.5 seconds. The clean sandbox contained 1 package and used 1 MB on disk; the tarball was 128 KB unpacked with 0 dependencies and 0 peers. npm audit found 0 known vulnerabilities. CommonJS and ESM imports both worked even though there is no exports map. TypeScript declarations are bundled.
Install loglevel separately because this package does not declare it as a dependency or peer. Import both modules, call prefix.reg(log) with the root logger, then call prefix.apply() on the root or a named logger. Applying first currently warns. The README says a future release would throw, but no release after 0.8.4 has delivered that change.
Our namespace browser bundle measured 2.3 KB minified and 1.2 KB gzipped. Templates recognize %t, %l, and %n; version 0.8.4 replaces only the first instance of each token. When format and template are both present, template formatting wins. Reapplying options asks loglevel to rebuild its methods instead of stacking another wrapper.
A string message receives the prefix inside its first argument, preserving console substitutions. For an object, the prefix becomes a separate leading argument, which can change custom sink behavior. timestampFormatter receives a Date, then its return value reaches format; the included declaration incorrectly types that later value as Date. Test one string, one object, a named logger, and reconfiguration in the bundling arrangement you ship.
Patterns
Prefix the root logger register-prefix
const log = require('loglevel')
const prefix = require('loglevel-plugin-prefix')
prefix.reg(log)
prefix.apply(log)
log.setLevel('info')
log.info('connected')Call `reg()` before `apply()`; the default uses local `HH:MM:SS` time and an uppercase level.
Print time, level, and logger name configure-template
prefix.apply(log, { template: '[%t] %l %n:' })
log.getLogger('api').warn('slow response')Only `%t`, `%l`, and `%n` are recognized, and 0.8.4 replaces the first occurrence of each.
Emit an ISO timestamp format-iso-time
prefix.apply(log, {
template: '[%t] %l:',
timestampFormatter: (date) => date.toISOString(),
})`timestampFormatter` receives a Date; its returned string is what the template and custom formatter see.
Build the prefix in one function customize-format
prefix.apply(log, {
format(level, name, timestamp) {
return `${timestamp} ${level} [${name}]`
},
})Runtime passes a string for `timestamp`; version 0.8.4's declaration says Date and is inaccurate here.
Give auth logs a separate label prefix-named-logger
const authLog = log.getLogger('auth')
prefix.apply(authLog, { template: '%l (%n):' })
authLog.error('token expired')Register the root object once, then apply named options to loggers returned by `getLogger()`.
Change the active template reconfigure-prefix
prefix.apply(log, { template: '%l:' })
log.info('plain')
prefix.apply(log, { template: '[%t] %l:' })
log.info('timed')The second application replaces configuration and rebuilds loglevel methods; it does not add a second prefix.
Keep console placeholders aligned preserve-substitutions
prefix.apply(log, { template: '%l:' })
log.info('processed %d records in %d ms', count, elapsedMs)For a string first argument, the prefix joins that same string, leaving `%d` arguments in their original positions.
Register from pinned script tags load-browser-globals
<script src="https://unpkg.com/loglevel/dist/loglevel.min.js"></script>
<script src="https://unpkg.com/loglevel-plugin-prefix@0.8.4/dist/loglevel-plugin-prefix.min.js"></script>
<script>
prefix.reg(log)
prefix.apply(log, { template: '[%t] %l:' })
</script>Pin 0.8.4 in production. The global names are `log` and `prefix`, and both libraries offer `noConflict()`.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| loglevel | npm | Use loglevel alone and own a short methodFactory wrapper when one prefix convention is enough. |
| pino | npm | Use it for structured Node logs, child bindings, serializers, and redaction. |
| winston | npm | Use it when a Node process needs multiple transports and a configurable formatting pipeline. |
| debug | npm | Use it for namespaced diagnostics that operators enable through the DEBUG setting. |
More web frontend guides
postcss · react · react-dom · tailwindcss · htmlparser2 · tailwind-merge · the whole shelf →
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.

