The full documentation is available here.
There have been a few changes between log4js 1.x and 2.x (and 0.x too). You should probably read this migration guide if things aren't working.
Out of the box it supports the following features:
- coloured console logging to stdout or stderr
- file appender, with configurable log rolling based on file size or date
- a logger for connect/express servers
- configurable log message layout/patterns
- different log levels for different log categories (make some parts of your app log as DEBUG, others only ERRORS, etc.)
Optional appenders are available:
- Logstash (UDP and HTTP)
- logFaces (UDP and HTTP)
Having problems? Jump on the slack channel, or create an issue. If you want to help out with the development, the slack channel is a good place to go as well.
npm install log4js
var log4js = ;var logger = log4js;loggerlevel = "debug";logger;
By default, log4js will not output any logs (so that it can safely be used in libraries). The
level for the
default category is set to
OFF. To enable logs, set the level (as in the example). This will then output to stdout with the coloured layout (thanks to masylum), so for the above you would see:
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
See example.js for a full example, but here's a snippet (also in
const log4js = ;log4js;const logger = log4js;logger;logger;logger;logger;logger;logger;
[2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe![2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground
Note for library makers
If you're writing a library and would like to include support for log4js, without introducing a dependency headache for your users, take a look at log4js-api.
There's also an example application.
;configure"./filename";;logger.level = "debug";logger.debug"Some debug messages";configure;
The original log4js was distributed under the Apache 2.0 License, and so is this. I've tried to keep the original copyright and author credits in place, except in sections that I have rewritten extensively.