loglevelnext is a modern logging library for Node.js and modern browsers,
written with modern patterns and practices which provides log level mapping of the
First thing's first, install the module:
npm install loglevelnext --save
Users can choose to use
loglevelnext in Node.js or in the client (browser).
// Node.jsconst log = ;log;
<!-- browser -->
loglevelnext ships supporting the following log level name-value
TRACE: 0DEBUG: 1INFO: 2WARN: 3ERROR: 4SILENT: 5
loglevelnext in Node.js the default export will be an instance
LogLevel wrapped with some extra sugar.
When loading the
loglevelnext.js script in the client (browser), the script
window.log to an instance of
wrapped with that same extra sugar.
LogLevel for documentation of all methods and
properties of every log instance, including the default instance.
These methods correspond to the available log levels and accept parameters
identical to their
console counterparts. eg.
console;console;// ... etc
Returns a new
LogLevel instance. The
options parameter should be an
matching the options for the
Note: the logger returned is cached, and subsequent requests for a logger of
the same name will return the same logger instance. If you require multiple
unique loggers of the same name, pass an
id property with a unique identifier
getLogger will use that over the
loglevelnext in a browser environment, you may encounter a scenario
window.log is already assigned when the script loads, resulting in
window.log being reassigned to
loglevelnext. This method will restore
window.log to it's original value and return the default logger.
Array [ Class ]
Array containing the factory classes available within
to outside modules. Particularily useful when creating plugins. eg.
const log = ;const MethodFactory = logfactories;...
Array [ LogLevel ]
Array containing references to the currently instantiated loggers.
Factories aka Plugins
If you're used to using plugins with
loglevel, fear not. The same capabilities
are available in
loglevelnext, but in a much more straightforward and structured
loglevelnext supports by way of "Factories." A
Factory is nothing more
than a class which defines several base methods that operate on the
and provide functionality to a
LogLevel instance. All factories must inherit from the
MethodFactory class, and may override any defined class functions.
For an example factory, please have a look at the
which provides similar functionality as the loglevel-prefix plugin,
and is the factory which is used when a user passes the
prefix option to a
Persisting the Level
Persisting the level of a log between sessions in a browser isn't the job of a
logging library. Primarily because working with
localStorage these days is a
breeze. If you need to store and retrieve a log level value between sessions,
please look into leveraging the excellent and very tiny
loglevelnext is a logging library for Node.js and modern
browsers, which means the latest versions of the major browsers. Unfortunately
"oldIE" versions aren't officially supported. The minimum Internet Exploder
version supported is IE10, though Microsoft no longer supports it.
If you're in need of support for old or outdated browser versions, please use the older loglevel, which supports browsers as old as IE6.
Note: This library's distribution file is compiled in a way that will
technically work all the way back to IE8 - as that version and above support
localStorage. However, IE8 and IE9 require that the developer tools be open
prior to invoking this library.
We welcome your contributions! Please have a read of CONTRIBUTING.md for more information on how to get involved.
This project is a fork of the much-loved loglevel module.