Skip to content

Commit

Permalink
feat: add new line for each log for verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
makeros committed Jul 19, 2019
1 parent 7510da8 commit dcce7dc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 52 deletions.
37 changes: 0 additions & 37 deletions .circleci/config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: npm test
- run: npm test
2 changes: 1 addition & 1 deletion lib/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function (opts) {
if (opts.verbose) {
const stringify = utils.stringify(opts)
const messageString = stringify(message)
setImmediate(function () { process.stdout.write(messageString) })
setImmediate(function () { process.stdout.write(messageString + '\n') })
}

const transport = new Transport(opts)
Expand Down
47 changes: 34 additions & 13 deletions test/pino-gelf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function pinoOutput (msg, level) {
return `{"level":${level},"time":1531171074631,"msg":"${msg}","pid":657,"hostname":"box","name":"app","v":1}`
}

describe('pinoGelf', function () {
describe('pinoGelf in verbose mode', function () {
test('no logs are processed when non-json message is passed to stdin', done => {
const pg = cp.spawn('node', [pgPath, 'log', '-v'])

Expand All @@ -32,7 +32,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -46,7 +46,7 @@ describe('pinoGelf', function () {
const expected = `{"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,"facility":"app"}`

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -59,7 +59,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":7,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -72,7 +72,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":7,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -85,7 +85,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":4,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -98,7 +98,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":3,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -111,7 +111,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":2,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -124,7 +124,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":2,"facility":"app"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -138,7 +138,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6,"facility":"app","req":{"method":"GET","url":"/","headers":"{\\"accept\\":\\"text/html\\"}"},"res":{"statusCode":304,"header":"\\"HTTP/1.1 304 Not Modified\\""},"responseTime":8}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -152,7 +152,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6,"facility":"app","test1":666,"test2":"red"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -166,7 +166,7 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"box","short_message":"hello world","full_message":"hello world","timestamp":1531171074.631,"level":6,"facility":"app","test2":"222"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
Expand All @@ -180,10 +180,31 @@ describe('pinoGelf', function () {
const expected = '{"version":"1.1","host":"han","short_message":"request completed","full_message":"request completed","timestamp":1481840140.708,"level":6,"facility":"pino-gelf-test-app","_status_code":304,"_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14","customField":"test"}'

pg.stdout.on('data', data => {
expect(data.toString()).toEqual(expected)
expect(data.toString()).toEqual(expected + '\n')
pg.kill()
done()
})
pg.stdin.write(pinoCustomOutput + '\n')
})

test('should output logs delimited with a new line', done => {
const pg = cp.spawn('node', [pgPath, 'log', '-v'])
const pinoCustomOutput = '{"pid":16699,"hostname":"han","name":"pino-gelf-test-app","level":30,"time":1481840140708,"msg":"request completed","customField":"test","res":{"statusCode":304},"responseTime":8,"req":{"method":"GET","headers":{"host":"localhost:3000","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14"}},"v":1}'
let result = ''
pg.stdout.on('data', data => {
result += data.toString()
// expect(dataStr.split(pinoCustomOutput)[1]).toEqual('\n')
})

pg.on('close', () => {
const newLines = result.match(/[\n]/g)
expect(newLines.length).toEqual(2)
done()
pg.kill()
})

pg.stdin.write(pinoCustomOutput + '\n')
pg.stdin.write(pinoCustomOutput + '\n')
pg.stdin.end()
})
})

0 comments on commit dcce7dc

Please sign in to comment.