{"id":11250,"library":"loglevel","title":"Loglevel: Minimal Logging for JavaScript","description":"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.","status":"active","version":"1.9.2","language":"javascript","source_language":"en","source_url":"git://github.com/pimterry/loglevel","tags":["javascript","log","logger","logging","browser","typescript"],"install":[{"cmd":"npm install loglevel","lang":"bash","label":"npm"},{"cmd":"yarn add loglevel","lang":"bash","label":"yarn"},{"cmd":"pnpm add loglevel","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"loglevel exports a default object, typically aliased as 'log', which contains all logging methods and configuration.","wrong":"import { log } from 'loglevel';","symbol":"log","correct":"import log from 'loglevel';"},{"note":"Use CommonJS require syntax for Node.js environments or older bundlers that do not support ESM.","wrong":"import log from 'loglevel';","symbol":"log (CommonJS)","correct":"const log = require('loglevel');"},{"note":"LogLevelDesc is a type definition for valid log levels, useful for type-checking when setting levels programmatically.","wrong":"import { LogLevel } from 'loglevel';","symbol":"LogLevelDesc","correct":"import log, { LogLevelDesc } from 'loglevel';"}],"quickstart":{"code":"import log from 'loglevel';\n\n// Default log level is 'warn'. To see all messages, set the level.\nlog.setLevel('trace');\n\n// Or enable all messages\n// log.enableAll();\n\n// Or programmatically set a specific level\nconst currentEnv = process.env.NODE_ENV || 'development';\nif (currentEnv === 'production') {\n  log.setLevel('error');\n} else {\n  log.setLevel('debug');\n}\n\nlog.trace('This is a trace message');\nlog.debug('This is a debug message');\nlog.info('This is an info message');\nlog.warn('This is a warning message');\nlog.error('This is an error message');\n\n// Example of changing the level dynamically\nsetTimeout(() => {\n  log.setLevel('info');\n  log.info('Log level changed to info after 2 seconds.');\n  log.debug('This debug message will now be hidden.');\n}, 2000);","lang":"typescript","description":"Demonstrates basic usage of loglevel, including setting log levels dynamically and outputting messages at various severities."},"warnings":[{"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.","message":"By 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to loglevel `1.6.4` or newer to resolve webpack build problems related to module resolution.","message":"Versions of loglevel older than `1.6.4` might experience webpack build issues due to an unqualified path in `package.json`'s 'main' field.","severity":"breaking","affected_versions":"<1.6.4"},{"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.","message":"Version `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`.","severity":"breaking","affected_versions":"1.6.5"},{"fix":"Upgrade to loglevel `1.6.3` or newer to benefit from fixes that prevent TypeScript type conflicts with other global `log` definitions.","message":"Prior 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.","severity":"gotcha","affected_versions":"<1.6.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Call `log.setLevel('debug');` (or 'info', 'trace', 'all') at the start of your application, for example, `import log from 'loglevel'; log.setLevel('debug');`.","cause":"The default log level for loglevel is 'warn', which means messages below this severity (info, debug, trace) are suppressed by default.","error":"My log.debug() or log.info() messages are not appearing in the console."},{"fix":"Update your `loglevel` package to `1.6.4` or a newer version: `npm install loglevel@latest`.","cause":"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`.","error":"Webpack is reporting module resolution errors for 'loglevel'."},{"fix":"Upgrade `loglevel` to version `1.6.3` or higher: `npm install loglevel@latest`.","cause":"Before version `1.6.3`, loglevel's type definitions could clash with other libraries that define a global `log` type (like `core-js`).","error":"TypeScript compile error: 'Property 'log' does not exist on type 'Global'.' or similar global type conflicts."}],"ecosystem":"npm"}