Socket
Socket
Sign inDemoInstall

log4js-json-layout

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

.idea/watcherTasks.xml

19

lib/jsonLayout.js

@@ -24,11 +24,13 @@ /**

}
function isObject(value) {
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
function jsonLayout(config) {
function formatter(data) {
delete data.logger;
let messageParam = config.messageParam || 'msg';
var output = {
"startTime": data.startTime,
"categoryName": data.categoryName,
"data": data.data,
"level": data.level.levelStr

@@ -39,4 +41,11 @@ };

}
if (output.data) {
output.data = formatLogData(output.data);
if (data.data.length === 2 && isObject(data.data[1])) {
output.data = data.data[0]; // the message
Object.assign(output, data.data[1]);
} else if (data.data.length === 1 && data.data[0].hasOwnProperty(messageParam)) {
output.data = data.data[0][messageParam]; // the message
delete data.data[0][messageParam];
Object.assign(output, data.data[0]);
} else if (data.data) {
output.data = formatLogData(data.data);
}

@@ -43,0 +52,0 @@ if (config.include && config.include.length) {

{
"name": "log4js-json-layout",
"version": "1.0.3",
"version": "1.0.4",
"description": "provides a slim and easy to use json-layout for log4js-node",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,2 +26,3 @@ # log4js-json-layout

type: 'console',
messageParam : 'msg',
layout: {

@@ -28,0 +29,0 @@ type: 'json',

@@ -14,4 +14,4 @@ /**

categoryName: "572efdaaa64be9dbc56369ae",
data: "Deserunt mollit nisi ipsum ipsum ea quis in eiusmod ipsum officia labore qui amet. Cupidatat ut do Lorem ad veniam irure proident enim aliqua nisi aliquip velit voluptate. Laborum minim occaecat commodo nulla labore ex ullamco. Eu incididunt quis quis Lorem do nostrud enim consectetur. Voluptate in occaecat proident aliqua Lorem pariatur officia dolor.\r\n",
level: "strong"
level: "strong",
data: "Deserunt mollit nisi ipsum ipsum ea quis in eiusmod ipsum officia labore qui amet. Cupidatat ut do Lorem ad veniam irure proident enim aliqua nisi aliquip velit voluptate. Laborum minim occaecat commodo nulla labore ex ullamco. Eu incididunt quis quis Lorem do nostrud enim consectetur. Voluptate in occaecat proident aliqua Lorem pariatur officia dolor.\r\n"
};

@@ -53,2 +53,20 @@ describe('log4js-json-layout', function () {

});
it('should format data when passed as message + object', function () {
data.data = ['aaa', {id: 123}];
var output = JSON.parse(layout({})(data));
output.id.should.equal(123);
output.data.should.equal('aaa')
});
it('should format data when passed as object with default msg param', function () {
data.data = [{id: 123, msg: 'aaa'}];
var output = JSON.parse(layout({})(data));
output.id.should.equal(123);
output.data.should.equal('aaa')
});
it('should format data when passed as object with different msg param', function () {
data.data = [{id: 123, data: 'aaa'}];
var output = JSON.parse(layout({messageParam : 'data'})(data));
output.id.should.equal(123);
output.data.should.equal('aaa')
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc