DEV.co
Open-Source Observability · pimterry

loglevel

loglevel is a lightweight, dependency-free logging library for JavaScript that provides level-based filtering (trace, debug, info, warn, error) without the overhead of larger logging frameworks. It weighs 1.4 KB gzipped and works consistently across browsers, Node.js, and environments without a console object.

Source: GitHub — github.com/pimterry/loglevel
2.7k
GitHub stars
160
Forks
JavaScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorypimterry/loglevel
Ownerpimterry
Primary languageJavaScript
LicenseMIT — OSI-approved
Stars2.7k
Forks160
Open issues19
Latest releasev1.9.2 (2024-09-06)
Last updated2025-03-20
Sourcehttps://github.com/pimterry/loglevel

What loglevel is

A UMD module wrapping console.log methods with graceful fallbacks, level filtering, and stacktrace preservation. It includes TypeScript definitions, supports CommonJS/AMD/ES6 module systems, and automatically detects console availability. The API is minimal: five logging methods, setLevel filtering, and plugin support via method replacement.

Quickstart

Get the loglevel source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/pimterry/loglevel.gitcd loglevel# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Frontend Web Applications

Browser logging with dynamic level control via console without clobbering stacktraces. Ideal for production debugging where you can toggle log levels without redeploying.

Node.js Services with Minimal Footprint

Lightweight logging for CLI tools, small servers, or IoT applications where bundle size and dependencies are constraints. Single 1.4 KB file reduces dependency tree complexity.

Cross-Platform JavaScript Libraries

Universal packages targeting both browser and Node.js. Reliable fallback behavior ensures logging never breaks in environments with limited console support (e.g., older IE, headless runtimes).

Implementation considerations

  • Default level is 'warn'; explicitly call log.enableAll() or log.setLevel() at initialization if you need lower-level logs visible in development.
  • Stacktrace line numbers are preserved only for direct console calls; wrapping loglevel in custom plugins will lose source attribution.
  • In IE8/9, console may not exist until developer tools are opened; loglevel handles this gracefully but initial logs in those environments will be silent.
  • TypeScript definitions are included; no @types package needed, but verify module syntax (default import vs. wildcard) matches your bundler/transpiler.
  • No built-in way to persist logs client-side or send to a server; you must layer such behavior via custom code or a separate logging backend.

When to avoid it — and what to weigh

  • Structured Logging Required — No built-in JSON logging, log correlation IDs, or structured metadata support. Incompatible with observability platforms expecting JSON-formatted logs.
  • Complex Filtering or Routing Needed — Single global level filter only; cannot send different log streams to different outputs. No appender or transport system for multi-destination logging.
  • High-Volume Production Telemetry — Designed for console output only. No batching, sampling, or remote log aggregation. For production observability at scale, use dedicated APM/logging services.
  • Plugin-Heavy Custom Logging Pipelines — Plugin support exists but replaces internal methods, clobbering stacktraces. Not designed as a foundation for complex custom logging architectures.

License & commercial use

MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with minimal restrictions (retain license and copyright notice).

MIT license clearly permits commercial use in closed-source products without royalty or attribution requirements (beyond retaining the license header). No known restrictions on commercial redistribution. Suitable for proprietary SaaS and enterprise applications.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Minimal attack surface: no network calls, no external dependencies, no eval or dynamic code execution. Logs only mirror console output. When used in browser, ensure sensitive data is never logged. No built-in encryption or obfuscation; treat logs as plain text.

Alternatives to consider

winston

Full-featured Node.js logging framework with transports, formatters, and structured logging. Larger footprint and more configuration; choose if you need multi-destination routing or JSON logs.

pino

High-performance structured JSON logging for Node.js with minimal overhead. Better for production services requiring observability platform integration; overkill for simple level-based console logging.

console-log-level

Similar lightweight alternative providing level filtering for console. Slightly smaller scope but comparable functionality; evaluate if you have specific compatibility requirements.

Software development agency

Build on loglevel with DEV.co software developers

loglevel integrates in seconds and weighs less than 2 KB. Perfect for frontend apps, Node.js services, and cross-platform libraries. Get started with npm install loglevel or explore the live demo.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

loglevel FAQ

Will loglevel break if console is not available?
No. Calls to log methods succeed silently if console is absent. loglevel automatically enables logging once console becomes available (e.g., when developer tools open in IE8/9).
Does loglevel support sending logs to a remote server?
Not built-in. You can write a custom adapter by wrapping log methods (e.g., replacing log.error with a function that calls the original and sends to your backend), but this will lose stacktrace info.
Can I use loglevel in a TypeScript project?
Yes. Type definitions are included; import as `import log from 'loglevel'` and TypeScript will resolve the types automatically. No @types package required.
What's the performance impact of using loglevel?
Negligible. It's a thin wrapper around native console methods. The main cost is in log method calls themselves, which is the same whether you use loglevel or console directly. Filtered-out logs (e.g., debug logs at 'warn' level) do not execute the underlying console call.

Software development & web development with DEV.co

Need help beyond evaluating loglevel? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and open-source observability integrations — and maintain them long-term.

Ready to Add Reliable Logging to Your JavaScript Project?

loglevel integrates in seconds and weighs less than 2 KB. Perfect for frontend apps, Node.js services, and cross-platform libraries. Get started with npm install loglevel or explore the live demo.