log4js

Port of Log4js to work with node.

0.x is no longer supported. Please upgrade to 6.x or higher.
Last updated 8 years ago by csausdev .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install log4js 
SYNC missed versions from official npm registry.

log4js-node CodeQL Node.js CI

NPM

This is a conversion of the log4js framework to work with node. I started out just stripping out the browser-specific code and tidying up some of the javascript to work better in node. It grew from there. Although it's got a similar name to the Java library log4j, thinking that it will behave the same way will only bring you sorrow and confusion.

The full documentation is available here.

Changes in version 3.x

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:

Getting help

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.

installation

npm install log4js

usage

Minimalist version:

var log4js = require("log4js");
var logger = log4js.getLogger();
logger.level = "debug";
logger.debug("Some debug messages");

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 examples/fromreadme.js):

const log4js = require("log4js");
log4js.configure({
  appenders: { cheese: { type: "file", filename: "cheese.log" } },
  categories: { default: { appenders: ["cheese"], level: "error" } },
});

const logger = log4js.getLogger("cheese");
logger.trace("Entering cheese testing");
logger.debug("Got cheese.");
logger.info("Cheese is Comté.");
logger.warn("Cheese is quite smelly.");
logger.error("Cheese is too ripe!");
logger.fatal("Cheese was breeding ground for listeria.");

Output (in cheese.log):

[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 for listeria.

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.

Documentation

Available here.

There's also an example application.

TypeScript

import log4js from "log4js";
log4js.configure({
  appenders: { cheese: { type: "file", filename: "cheese.log" } },
  categories: { default: { appenders: ["cheese"], level: "error" } },
});

const logger = log4js.getLogger();
logger.level = "debug";
logger.debug("Some debug messages");

Contributing

We're always looking for people to help out. Jump on slack and discuss what you want to do. Also, take a look at the rules before submitting a pull request.

License

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.

Current Tags

  • 6.7.0                                ...           latest (2 years ago)

148 Versions

  • 6.7.0                                ...           2 years ago
  • 6.6.1                                ...           2 years ago
  • 6.6.0                                ...           2 years ago
  • 6.5.2                                ...           3 years ago
  • 6.5.1                                ...           3 years ago
  • 6.5.0                                ...           3 years ago
  • 6.4.7                                ...           3 years ago
  • 6.4.6                                ...           3 years ago
  • 6.4.5                                ...           3 years ago
  • 6.4.4                                ...           3 years ago
  • 6.4.3                                ...           3 years ago
  • 6.4.2                                ...           3 years ago
  • 6.4.1                                ...           3 years ago
  • 6.4.0                                ...           3 years ago
  • 6.3.0                                ...           5 years ago
  • 6.2.1                                ...           5 years ago
  • 6.2.0                                ...           5 years ago
  • 6.1.2                                ...           5 years ago
  • 6.1.1                                ...           5 years ago
  • 6.1.0                                ...           5 years ago
  • 6.0.0                                ...           5 years ago
  • 5.3.0 [deprecated]           ...           5 years ago
  • 5.2.2 [deprecated]           ...           5 years ago
  • 5.2.1 [deprecated]           ...           5 years ago
  • 5.2.0 [deprecated]           ...           5 years ago
  • 5.1.0 [deprecated]           ...           5 years ago
  • 5.0.0 [deprecated]           ...           5 years ago
  • 4.5.1 [deprecated]           ...           5 years ago
  • 4.5.0 [deprecated]           ...           5 years ago
  • 4.4.0 [deprecated]           ...           5 years ago
  • 4.3.2 [deprecated]           ...           5 years ago
  • 4.3.1 [deprecated]           ...           6 years ago
  • 4.3.0 [deprecated]           ...           6 years ago
  • 4.2.0 [deprecated]           ...           6 years ago
  • 4.1.1 [deprecated]           ...           6 years ago
  • 4.1.0 [deprecated]           ...           6 years ago
  • 4.0.2 [deprecated]           ...           6 years ago
  • 4.0.1 [deprecated]           ...           6 years ago
  • 4.0.0 [deprecated]           ...           6 years ago
  • 3.0.6 [deprecated]           ...           6 years ago
  • 3.0.5 [deprecated]           ...           6 years ago
  • 3.0.4 [deprecated]           ...           6 years ago
  • 3.0.3 [deprecated]           ...           6 years ago
  • 3.0.2 [deprecated]           ...           6 years ago
  • 3.0.1 [deprecated]           ...           6 years ago
  • 3.0.0 [deprecated]           ...           6 years ago
  • 2.11.0 [deprecated]           ...           6 years ago
  • 2.10.0 [deprecated]           ...           6 years ago
  • 2.9.0 [deprecated]           ...           6 years ago
  • 2.8.0 [deprecated]           ...           7 years ago
  • 2.7.0 [deprecated]           ...           7 years ago
  • 2.6.1 [deprecated]           ...           7 years ago
  • 2.6.0 [deprecated]           ...           7 years ago
  • 2.5.3 [deprecated]           ...           7 years ago
  • 2.5.2 [deprecated]           ...           7 years ago
  • 2.5.1 [deprecated]           ...           7 years ago
  • 2.5.0 [deprecated]           ...           7 years ago
  • 2.4.1 [deprecated]           ...           7 years ago
  • 2.3.12 [deprecated]           ...           7 years ago
  • 2.3.11 [deprecated]           ...           7 years ago
  • 2.3.10 [deprecated]           ...           7 years ago
  • 2.3.9 [deprecated]           ...           7 years ago
  • 2.3.8 [deprecated]           ...           7 years ago
  • 2.3.7 [deprecated]           ...           7 years ago
  • 2.3.6 [deprecated]           ...           7 years ago
  • 2.3.5 [deprecated]           ...           7 years ago
  • 2.3.4 [deprecated]           ...           7 years ago
  • 2.3.3 [deprecated]           ...           7 years ago
  • 2.3.2 [deprecated]           ...           7 years ago
  • 2.3.1 [deprecated]           ...           7 years ago
  • 2.3.0 [deprecated]           ...           7 years ago
  • 2.2.0 [deprecated]           ...           7 years ago
  • 2.1.0 [deprecated]           ...           7 years ago
  • 2.0.1 [deprecated]           ...           7 years ago
  • 2.0.0 [deprecated]           ...           7 years ago
  • 1.1.1 [deprecated]           ...           8 years ago
  • 1.1.0 [deprecated]           ...           8 years ago
  • 1.0.1 [deprecated]           ...           8 years ago
  • 1.0.0 [deprecated]           ...           8 years ago
  • 0.6.38 [deprecated]           ...           8 years ago
  • 0.6.37 [deprecated]           ...           8 years ago
  • 0.6.36 [deprecated]           ...           9 years ago
  • 0.6.35 [deprecated]           ...           9 years ago
  • 0.6.34 [deprecated]           ...           9 years ago
  • 0.6.33 [deprecated]           ...           9 years ago
  • 0.6.32 [deprecated]           ...           9 years ago
  • 0.6.31 [deprecated]           ...           9 years ago
  • 0.6.30 [deprecated]           ...           9 years ago
  • 0.6.29 [deprecated]           ...           9 years ago
  • 0.6.28 [deprecated]           ...           9 years ago
  • 0.6.27 [deprecated]           ...           9 years ago
  • 0.6.26 [deprecated]           ...           10 years ago
  • 0.6.25 [deprecated]           ...           10 years ago
  • 0.6.24 [deprecated]           ...           10 years ago
  • 0.6.23 [deprecated]           ...           10 years ago
  • 0.6.22 [deprecated]           ...           10 years ago
  • 0.6.21 [deprecated]           ...           10 years ago
  • 0.6.20 [deprecated]           ...           10 years ago
  • 0.6.19 [deprecated]           ...           10 years ago
  • 0.6.18 [deprecated]           ...           10 years ago
  • 0.6.17 [deprecated]           ...           10 years ago
  • 0.6.16 [deprecated]           ...           10 years ago
  • 0.6.15 [deprecated]           ...           10 years ago
  • 0.6.14 [deprecated]           ...           11 years ago
  • 0.6.13 [deprecated]           ...           11 years ago
  • 0.6.12 [deprecated]           ...           11 years ago
  • 0.6.11 [deprecated]           ...           11 years ago
  • 0.6.10 [deprecated]           ...           11 years ago
  • 0.6.9 [deprecated]           ...           11 years ago
  • 0.6.8 [deprecated]           ...           11 years ago
  • 0.6.7 [deprecated]           ...           11 years ago
  • 0.6.6 [deprecated]           ...           12 years ago
  • 0.6.5 [deprecated]           ...           12 years ago
  • 0.6.4 [deprecated]           ...           12 years ago
  • 0.6.3 [deprecated]           ...           12 years ago
  • 0.6.2 [deprecated]           ...           12 years ago
  • 0.5.8 [deprecated]           ...           12 years ago
  • 0.6.1 [deprecated]           ...           12 years ago
  • 0.6.0 [deprecated]           ...           12 years ago
  • 0.5.7 [deprecated]           ...           12 years ago
  • 0.5.6 [deprecated]           ...           12 years ago
  • 0.5.5 [deprecated]           ...           12 years ago
  • 0.5.4 [deprecated]           ...           12 years ago
  • 0.5.3 [deprecated]           ...           12 years ago
  • 0.5.2 [deprecated]           ...           12 years ago
  • 0.5.1 [deprecated]           ...           12 years ago
  • 0.5.0 [deprecated]           ...           13 years ago
  • 0.4.3 [deprecated]           ...           13 years ago
  • 0.4.2 [deprecated]           ...           13 years ago
  • 0.4.1 [deprecated]           ...           13 years ago
  • 0.4.0 [deprecated]           ...           13 years ago
  • 0.3.9 [deprecated]           ...           13 years ago
  • 0.3.8 [deprecated]           ...           13 years ago
  • 0.3.7 [deprecated]           ...           13 years ago
  • 0.3.6 [deprecated]           ...           13 years ago
  • 0.3.5 [deprecated]           ...           13 years ago
  • 0.3.4 [deprecated]           ...           13 years ago
  • 0.3.3 [deprecated]           ...           13 years ago
  • 0.3.2 [deprecated]           ...           13 years ago
  • 0.3.1 [deprecated]           ...           13 years ago
  • 0.3.0 [deprecated]           ...           13 years ago
  • 0.2.6 [deprecated]           ...           14 years ago
  • 0.2.5 [deprecated]           ...           14 years ago
  • 0.2.4 [deprecated]           ...           14 years ago
  • 0.2.3 [deprecated]           ...           14 years ago
  • 0.2.2 [deprecated]           ...           14 years ago
  • 0.2.0 [deprecated]           ...           14 years ago
  • 0.1.0 [deprecated]           ...           14 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 60
Last Day 0
Last Week 60
Last Month 0
Dependencies (2)
Dev Dependencies (3)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |