log4js-node

NPM

This is a conversion of the log4js framework to work with node. 这是对log4jss框架的转换,以使用node。I started out just stripping out the browser-specific code and tidying up some of the javascript to work better in node. 我一开始只是剥离了特定于浏览器的代码,并整理了一些javascript,以便在节点中更好地工作。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.它从那里生长起来。尽管它的名称与Java库log4j相似,但认为它的行为方式相同只会给你带来悲伤和困惑。

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). log4js 1x和2x(以及0x)之间有一些更改。You should probably read this migration guide if things aren't working.如果不起作用,您可能应该阅读本迁移指南

Out of the box it supports the following features:开箱即用,它支持以下功能:

Optional appenders are available:可选的附加程序可用:

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.有问题吗?跳过slack通道,或者制造问题。如果你想帮助开发,松弛通道也是一个很好的地方。

npm install log4js

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). 默认情况下,log4js不会输出任何日志(以便在库中安全使用)。The level for the default category is set to OFF. default类别的级别设置为OFFTo 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:然后,它将输出到带有彩色布局的stdout(感谢masylum),因此对于上面的内容,您将看到:

[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):有关完整示例,请参阅example.js,但这里有一个片段(也在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.

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.如果您正在编写一个库,并且希望包含对log4js的支持,而不给用户带来依赖性问题,请查看log4js-api

Available here.此处提供。

There's also an example application.还有一个示例应用程序

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");

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.此外,在提交拉取请求之前,请查看规则。

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.最初的log4js是在Apache 2.0许可证下分发的,这也是。我试着保留原始版权和作者署名,除了我大量重写的部分。