mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
chore(merge): merged 2.4.1 from master
This commit is contained in:
commit
da703cdebb
@ -1,7 +1,7 @@
|
||||
# log4js-node [](http://travis-ci.org/log4js-node/log4js-node)
|
||||
# log4js-node [](http://travis-ci.org/log4js-node/log4js-node) [](https://codecov.io/gh/log4js-node/log4js-node)
|
||||
|
||||
|
||||
[](https://nodei.co/npm/log4js/)
|
||||
[](https://codecov.io/gh/nomiddlename/log4js-node)
|
||||
|
||||
This is a conversion of the [log4js](https://github.com/stritti/log4js)
|
||||
framework to work with [node](http://nodejs.org). 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](https://logging.apache.org/log4j/2.x/), thinking that it will behave the same way will only bring you sorrow and confusion.
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
const CircularJSON = require('circular-json');
|
||||
|
||||
module.exports = (levels) => {
|
||||
/**
|
||||
* @name LoggingEvent
|
||||
@ -33,13 +35,13 @@ module.exports = (levels) => {
|
||||
// Validate that we really are in this case
|
||||
try {
|
||||
const logData = this.data.map((e) => {
|
||||
if (e && e.stack && JSON.stringify(e) === '{}') {
|
||||
if (e && e.stack && CircularJSON.stringify(e) === '{}') {
|
||||
e = { message: e.message, stack: e.stack };
|
||||
}
|
||||
return e;
|
||||
});
|
||||
this.data = logData;
|
||||
return JSON.stringify(this);
|
||||
return CircularJSON.stringify(this);
|
||||
} catch (e) {
|
||||
return new LoggingEvent(
|
||||
'log4js',
|
||||
@ -52,7 +54,7 @@ module.exports = (levels) => {
|
||||
static deserialise(serialised) {
|
||||
let event;
|
||||
try {
|
||||
event = JSON.parse(serialised);
|
||||
event = CircularJSON.parse(serialised);
|
||||
event.startTime = new Date(event.startTime);
|
||||
event.level = levels.getLevel(event.level.levelStr);
|
||||
event.data = event.data.map((e) => {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
const debug = require('debug')('log4js:multiprocess');
|
||||
const net = require('net');
|
||||
const CircularJSON = require('circular-json');
|
||||
|
||||
const END_MSG = '__LOG4JS__';
|
||||
|
||||
@ -19,7 +20,7 @@ function logServer(config, actualAppender, levels) {
|
||||
debug('deserialising log event');
|
||||
let loggingEvent;
|
||||
try {
|
||||
loggingEvent = JSON.parse(msg);
|
||||
loggingEvent = CircularJSON.parse(msg);
|
||||
loggingEvent.startTime = new Date(loggingEvent.startTime);
|
||||
loggingEvent.level = levels.getLevel(loggingEvent.level.levelStr);
|
||||
} catch (e) {
|
||||
@ -98,13 +99,13 @@ function workerAppender(config) {
|
||||
// The following allows us to serialize errors correctly.
|
||||
// Validate that we really are in this case
|
||||
const logData = loggingEvent.data.map((e) => {
|
||||
if (e && e.stack && JSON.stringify(e) === '{}') {
|
||||
if (e && e.stack && CircularJSON.stringify(e) === '{}') {
|
||||
e = { stack: e.stack };
|
||||
}
|
||||
return e;
|
||||
});
|
||||
loggingEvent.data = logData;
|
||||
socket.write(JSON.stringify(loggingEvent), 'utf8');
|
||||
socket.write(CircularJSON.stringify(loggingEvent), 'utf8');
|
||||
socket.write(END_MSG, 'utf8');
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
*/
|
||||
const debug = require('debug')('log4js:main');
|
||||
const fs = require('fs');
|
||||
const CircularJSON = require('circular-json');
|
||||
const Configuration = require('./configuration');
|
||||
const connectModule = require('./connect-logger');
|
||||
const logger = require('./logger');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "log4js",
|
||||
"version": "2.3.12",
|
||||
"version": "2.4.1",
|
||||
"description": "Port of Log4js to work with node.",
|
||||
"homepage": "https://log4js-node.github.io/log4js-node/",
|
||||
"keywords": [
|
||||
@ -38,6 +38,7 @@
|
||||
"lib": "lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"circular-json": "^0.4.0",
|
||||
"date-format": "^1.2.0",
|
||||
"debug": "^3.1.0",
|
||||
"semver": "^5.3.0",
|
||||
|
||||
@ -42,6 +42,8 @@ if (cluster.isMaster) {
|
||||
t.equal(logEvents[1].pid, workerPid);
|
||||
t.type(logEvents[1].data[1], 'Error');
|
||||
t.contains(logEvents[1].data[1].stack, 'Error: oh dear');
|
||||
t.type(logEvents[1].data[2], 'object');
|
||||
t.type(logEvents[1].data[2].me, 'object');
|
||||
t.equal(logEvents[2].categoryName, 'log4js');
|
||||
t.equal(logEvents[2].level.toString(), 'ERROR');
|
||||
t.equal(logEvents[2].data[0], 'Unable to parse log:');
|
||||
@ -61,7 +63,9 @@ if (cluster.isMaster) {
|
||||
});
|
||||
} else {
|
||||
const workerLogger = log4js.getLogger('worker');
|
||||
workerLogger.info('this is worker', new Error('oh dear'));
|
||||
const circle = {};
|
||||
circle.me = circle;
|
||||
workerLogger.info('this is worker', new Error('oh dear'), circle);
|
||||
// can't run the test in the worker, things get weird
|
||||
process.send({
|
||||
type: '::testing',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user