6.9.1 • Published 2 years ago

log4js v6.9.1

Weekly downloads
2,652,489
License
Apache-2.0
Repository
github
Last release
2 years ago

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 * as 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.

karmawaowalmart-d2dzikix-coreff-genercodebluej-pm2api-utilityself-application-health-check@freekits/rmakedotclub-admin-web-backenddora-mockminimajsyangfan-test-dingding-es6node-dingding-push1local-aprszcmzcmexauto-principaltest-ans-node-sdk@valtech-sd/coronado-bridgeui_automation_dd_cc@lunares/lunares@finaccel/loggerswytch-x-notification-clientrequest-json-errorhandlersandbox-js-frameworklooneyjsloopsailorharbbor-js@ai-workspace/canvasdanukoa2-middleware-slackerjoresion_pkgoctopus-error-handleredgegrid-update-log4js@monogoto.io/node-red-contrib-monogoto-customer@monogoto.io/node-red-contrib-monogoto-operatorlozitadsy-styleguidelog4js-rest-lognjjs_jkathene.apiazero-sdk-loggerelectron-quick-start-typescriptnoi-loggersyntress@antsomi/core-servicesazero-sdk-mongodb-persistenceazero-sdk-mongodb-persistence-adapterlg-react-ssrlg-react-ssr-componentaccellion_orchestration_clientgbl-redisgblredisgblredis-clientgblredisclientaruba-clearpass-csv2apiconfig-centerimpm@arisageha/react-lazyloadmehdi_benhamouche_libraraypoc-shared-server@skhon/hong-corewmzy-mobilehezhouyuanrenchain@teamviewer/teamviewer-iot-sdk-nodejsepoos@payid-org/payid-metricspayid-metricskoa-bpm-clienthttp-mpcloud@ethpos/ethpos-remote-signerethpos-remote-signer@belldata-dx/log4js-newrelic-logsaegon-node-common2tingz-libmirai-bot@carlosgutierrez/corenavatech-commonha-loggerserver-mysqlreact-antd-ssr-spa-demostaking-logging2@niklasz/jspurefix-forkrzh_mods@niklasz-org/jspurefix-forkjust-rpcct-webservicekarma-3wickrio-basic-botcsgo-demo-helper-tmpjupysync@plumage/fxconfigyxapimoduleapi-free-express@red-unica/bitacorastsimportsorternode-okex-api@yuanhong/artipub@crawlab-team/artipub-backend
6.8.0

2 years ago

6.9.0

2 years ago

6.9.1

2 years ago

6.7.1

2 years ago

6.7.0

2 years ago

6.5.0

2 years ago

6.6.1

2 years ago

6.6.0

2 years ago

6.5.2

2 years ago

6.5.1

2 years ago

6.4.7

2 years ago

6.4.6

2 years ago

6.4.3

3 years ago

6.4.5

2 years ago

6.4.4

3 years ago

6.4.2

3 years ago

6.4.1

3 years ago

6.4.0

3 years ago

6.3.0

4 years ago

6.2.1

4 years ago

6.2.0

4 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

5 years ago

5.2.2

5 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.0

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.1

5 years ago

4.1.0

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.11.0

6 years ago

2.10.0

6 years ago

2.9.0

6 years ago

2.8.0

6 years ago

2.7.0

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.3

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.1

7 years ago

2.3.12

7 years ago

2.3.11

7 years ago

2.3.10

7 years ago

2.3.9

7 years ago

2.3.8

7 years ago

2.3.7

7 years ago

2.3.6

7 years ago

2.3.5

7 years ago

2.3.4

7 years ago

2.3.3

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.6.38

8 years ago

0.6.37

8 years ago

0.6.36

8 years ago

0.6.35

8 years ago

0.6.34

8 years ago

0.6.33

9 years ago

0.6.32

9 years ago

0.6.31

9 years ago

0.6.30

9 years ago

0.6.29

9 years ago

0.6.28

9 years ago

0.6.27

9 years ago

0.6.26

9 years ago

0.6.25

9 years ago

0.6.24

9 years ago

0.6.23

9 years ago

0.6.22

10 years ago

0.6.21

10 years ago

0.6.20

10 years ago

0.6.19

10 years ago

0.6.18

10 years ago

0.6.17

10 years ago

0.6.16

10 years ago

0.6.15

10 years ago

0.6.14

10 years ago

0.6.13

11 years ago

0.6.12

11 years ago

0.6.11

11 years ago

0.6.10

11 years ago

0.6.9

11 years ago

0.6.8

11 years ago

0.6.7

11 years ago

0.6.6

11 years ago

0.6.5

11 years ago

0.6.4

11 years ago

0.6.3

12 years ago

0.6.2

12 years ago

0.5.8

12 years ago

0.6.1

12 years ago

0.6.0

12 years ago

0.5.7

12 years ago

0.5.6

12 years ago

0.5.5

12 years ago

0.5.4

12 years ago

0.5.3

12 years ago

0.5.2

12 years ago

0.5.1

12 years ago

0.5.0

12 years ago

0.4.3

13 years ago

0.4.2

13 years ago

0.4.1

13 years ago

0.4.0

13 years ago

0.3.9

13 years ago

0.3.8

13 years ago

0.3.7

13 years ago

0.3.6

13 years ago

0.3.5

13 years ago

0.3.4

13 years ago

0.3.3

13 years ago

0.3.2

13 years ago

0.3.1

13 years ago

0.3.0

13 years ago

0.2.6

13 years ago

0.2.5

13 years ago

0.2.4

14 years ago

0.2.3

14 years ago

0.2.2

14 years ago

0.2.0

14 years ago

0.1.0

14 years ago