Registry / observability / loglevel

loglevel

JSON →
library0.1.2jsnpmunverified

loglevel is a minimal, lightweight logging library for JavaScript environments, including browsers and Node.js. Currently at version 1.9.2, it maintains a steady release cadence focusing on stability and reliability. Its core functionality extends standard `console.log` methods to provide level-based logging (trace, debug, info, warn, error) and filtering, while gracefully handling environments where `console` methods might be absent or limited. Key differentiators include its small footprint (1.4 KB minified and gzipped), lack of external dependencies, preservation of original stack trace line numbers (unlike many wrapper-heavy logging frameworks), and seamless integration with various module systems (CommonJS, AMD, global). It ships with built-in TypeScript definitions and ensures consistent logging behavior across diverse JavaScript runtimes, making it a reliable choice for everyday debugging without introducing complex features like appender reconfiguration or advanced filtering rules.

npm install loglevel
INSTALL
IMPORT
SIG · LOGLEVEL
L
loglevel
observabilityjavascriptv0.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

log
import log from 'loglevel';
import { log } from 'loglevel';
loglevel exports a default object, typically aliased as 'log', which contains all logging methods and configuration.
log (CommonJS)
const log = require('loglevel');
import log from 'loglevel';
Use CommonJS require syntax for Node.js environments or older bundlers that do not support ESM.
LogLevelDesc
import log, { LogLevelDesc } from 'loglevel';
import { LogLevel } from 'loglevel';
LogLevelDesc is a type definition for valid log levels, useful for type-checking when setting levels programmatically.

Demonstrates basic usage of loglevel, including setting log levels dynamically and outputting messages at various severities.

import log from 'loglevel'; // Default log level is 'warn'. To see all messages, set the level. log.setLevel('trace'); // Or enable all messages // log.enableAll(); // Or programmatically set a specific level const currentEnv = process.env.NODE_ENV || 'development'; if (currentEnv === 'production') { log.setLevel('error'); } else { log.setLevel('debug'); } log.trace('This is a trace message'); log.debug('This is a debug message'); log.info('This is an info message'); log.warn('This is a warning message'); log.error('This is an error message'); // Example of changing the level dynamically setTimeout(() => { log.setLevel('info'); log.info('Log level changed to info after 2 seconds.'); log.debug('This debug message will now be hidden.'); }, 2000);
Debug
Known issues
gotchaBy default, loglevel's logging is filtered to 'warn' level. This means 'info', 'debug', and 'trace' messages will not appear unless you explicitly set a lower log level.
fix
Call `log.setLevel('trace');` or `log.enableAll();` at the beginning of your application to see all messages. For development, `log.setLevel('debug');` is often sufficient.
affects: >=1.0.0
gotchaWhen creating plugins that wrap loglevel's methods, you may lose the original stack trace line numbers in your console output. Loglevel explicitly avoids this issue with its core methods, but it's a trade-off for custom wrappers.
fix
Be aware of this limitation when developing custom log handlers. For most use cases, the built-in methods are sufficient to preserve stack traces.
affects: >=1.0.0
breakingVersions of loglevel older than `1.6.4` might experience webpack build issues due to an unqualified path in `package.json`'s 'main' field.
fix
Upgrade to loglevel `1.6.4` or newer to resolve webpack build problems related to module resolution.
affects: <1.6.4
breakingVersion `1.6.5` introduced bugs that caused issues in Node.js and Internet Explorer versions older than 9, which were subsequently fixed in `1.6.6`.
fix
Avoid using loglevel `1.6.5`. Upgrade to `1.6.6` or a newer version to prevent compatibility problems in Node.js and older IE browsers.
affects: 1.6.5
gotchaPrior to version `1.6.3`, loglevel's global `log` type could conflict with other global `log` types (e.g., from `core-js`), leading to TypeScript compilation errors.
fix
Upgrade to loglevel `1.6.3` or newer to benefit from fixes that prevent TypeScript type conflicts with other global `log` definitions.
affects: <1.6.3
Errors
Common errors & fixes
My log.debug() or log.info() messages are not appearing in the console.
The default log level for loglevel is 'warn', which means messages below this severity (info, debug, trace) are suppressed by default.
fix
Call `log.setLevel('debug');` (or 'info', 'trace', 'all') at the start of your application, for example, `import log from 'loglevel'; log.setLevel('debug');`.
Webpack is reporting module resolution errors for 'loglevel'.
Using loglevel versions older than `1.6.4` with webpack could lead to issues due to an improperly qualified 'main' entry in the `package.json`.
fix
Update your `loglevel` package to `1.6.4` or a newer version: `npm install loglevel@latest`.
TypeScript compile error: 'Property 'log' does not exist on type 'Global'.' or similar global type conflicts.
Before version `1.6.3`, loglevel's type definitions could clash with other libraries that define a global `log` type (like `core-js`).
fix
Upgrade `loglevel` to version `1.6.3` or higher: `npm install loglevel@latest`.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
loglevel — npm install loglevel · libregistry