Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/schema/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
host: { type: 'string' },
short_message: { type: 'string' },
full_message: { type: 'string' },
timestamp: { type: 'integer' },
timestamp: { type: 'number' },
level: { type: 'integer' }
},
patternProperties: {
Expand Down
20 changes: 10 additions & 10 deletions test/pino-gelf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ function pinoOutput(msg, level) {

function testPinoToSyslogLevel(pinoLevel, syslogLevel, testCallback) {
const pg = cp.spawn('node', [pgPath, 'log', '-v']);
const expected = `{"_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":${syslogLevel}}\n`;
const expected = {"_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":syslogLevel};

pg.stdout.on('data', data => {
pg.kill();
expect(data.toString()).toEqual(expected);
expect(JSON.parse(data.toString())).toStrictEqual(expected);
testCallback();
});

Expand Down Expand Up @@ -120,10 +120,10 @@ describe('pinoGelf', function() {

test('pino output is transformed to gelf output', done => {
const pg = cp.spawn('node', [pgPath, 'log', '-v']);
const expected = '{"_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6}\n';
const expected = {"_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6};

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected);
expect(JSON.parse(data.toString())).toStrictEqual(expected);
pg.kill();
done();
});
Expand All @@ -134,10 +134,10 @@ describe('pinoGelf', function() {
test('short message is trimmed down', done => {
const pg = cp.spawn('node', [pgPath, 'log', '-v']);
const msg = 'hello world world world world world world world world world world world world';
const expected = `{"_name":"app","version":"1.1","host":"box","short_message":"hello world world world world world world world world world world","full_message":"${msg}","timestamp":1531171074.631,"level":6}\n`;
const expected = {"_name":"app","version":"1.1","host":"box","short_message":"hello world world world world world world world world world world","full_message":msg,"timestamp":1531171074.631,"level":6};

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected);
expect(JSON.parse(data.toString())).toStrictEqual(expected);
pg.kill();
done();
});
Expand Down Expand Up @@ -168,11 +168,11 @@ describe('pinoGelf', function() {
test('pino output with express-pino-middleware content is transformed to gelf output', done => {
const pg = cp.spawn('node', [pgPath, 'log', '-v']);
const pinoExpressOutput = '{"level":30,"time":1531171074631,"msg":"hello world","res":{"statusCode":304,"header":"HTTP/1.1 304 Not Modified"},"responseTime":8,"req":{"method":"GET","url":"/","headers":{"accept":"text/html"}},"pid":657,"hostname":"box","name":"app","v":1}';
const expected = '{"_res":"{\\"statusCode\\":304,\\"header\\":\\"HTTP/1.1 304 Not Modified\\"}","_responseTime":"8","_req":"{\\"method\\":\\"GET\\",\\"url\\":\\"/\\",\\"headers\\":{\\"accept\\":\\"text/html\\"}}","_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6}\n';
const expected = {"_res":'{"statusCode":304,"header":"HTTP/1.1 304 Not Modified"}',"_responseTime":"8","_req":'{"method":"GET","url":"/","headers":{"accept":"text/html"}}',"_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6};

pg.stdout.on('data', data => {
pg.kill();
expect(data.toString()).toEqual(expected);
expect(JSON.parse(data.toString())).toStrictEqual(expected);
done();
});

Expand All @@ -182,11 +182,11 @@ describe('pinoGelf', function() {
test('pino output with custom fields is transformed to gelf output', done => {
const pg = cp.spawn('node', [pgPath, 'log', '-v']);
const pinoCustomOutput = '{"level":30,"time":1531171074631,"msg":"hello world","environment":"dev","colour":"red","pid":657,"hostname":"box","name":"app","v":1}';
const expected = '{"_environment":"dev","_colour":"red","_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6}\n';
const expected = {"_environment":"dev","_colour":"red","_name":"app","version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6};

pg.stdout.on('data', data => {
pg.kill();
expect(data.toString()).toEqual(expected);
expect(JSON.parse(data.toString())).toStrictEqual(expected);
done();
});

Expand Down