Lori is a very lightweight logger for use in Node.js applications, with a middleware option for Express access logs. Lori is a colourful way to output quick logging, and is extremely easy to set up. It's not designed to take on the functionality of other libraries such as morgan, but to get something in place quickly which can provide insight into your application.
This module is built on each commit with TravisCI on the latest stable version of Node.js, although the main module is compatible all the way back to 0.8.
Lori is available on npm, so simply install it.
$ npm install lori
There are a couple of ways you can use Lori, either as a generic logger or as a piece of Middleware for Express.
As middleware, Lori will generate access logs for your Express application in the following format:
Thu 13 Aug 2015 19:14:09 INFO GET /welcome 54498ms
To set up Lori as a piece of Middleware, simply drop it into your app as early as possible in your setup:
var lori = ;app;
There are several default methods written into Lori, for the common use cases with logging:
lori;lori;lori;lori;// [Thu, 13 Aug 2015 19:14:09] [DEBUG] test// [Thu, 13 Aug 2015 19:14:09] [ERROR] test// [Thu, 13 Aug 2015 19:14:09] [INFO] test// [Thu, 13 Aug 2015 19:14:09] [WARN] test
These methods typically take
String arguments, however if a non-
String argument is provided, Lori will
JSON.stringify whatever is passed.
You can also call the
access function the Express Middleware uses, as below:
// [request]lori;// [verb, url, duration(hrtime)]lori;
Each level has a colour associated with it (which can be changed, see below). By default all logs go to
stdout, but this can also be modified.
Lori is extremely easy to use, with a few little utilities to allow for customisation.
By default, the
lori module provides a singleton logger for use throughout your application (it doesn't care about state), however if you wish to make many loggers, you can access the constructor as below:
var lori = ;var Logger = ;
This allows you to have different loggers with different configurations throughout your application.
configure function is typically called as soon as you start your application - it allows you to specify colours, logging locations, formats, etc. This function takes an object argument of the following options:
This is not the only time you can control Lori though, it's dynamic - you can modify it at any time, although naturally it will only effect the instance you're working with (instead of all of them):
// Reset Lori to the default state (as shown in the above `configure`)lori;// Modify to use a new logging method on the underlying instance.//// This example will output a colored string to the console in// non-production environments, and log to a file in production// environments. The log file is based on the log level.lori;// Change the date formatlori;// Change the theme used for colours - this will overwrite the previous themelori;// Change the theme used for colours - this will merge with the previous themelori;// Turn off coloured outputlori;// Switch to using local timelori;
Tests are written in Mocha, and can be run via npm scripts.
$ npm test
You can also generate coverage reports in HTML and lcov formats using:
$ npm run coverage$ npm run lcov
Sadly, couldn't use Grunt because it swallows the colours.
If you find any issues inside this module, feel free to open an issue here.