Skip to content

Commit

Permalink
Merge pull request #32 from pinojs/update-deps
Browse files Browse the repository at this point in the history
Updated dependencies, dropped through2
  • Loading branch information
mcollina authored Sep 7, 2018
2 parents d29dca2 + ffe03d8 commit ee13276
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
16 changes: 9 additions & 7 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs')
const args = require('args')
const pump = require('pump')
const split = require('split2')
const through = require('through2')
const { Transform } = require('readable-stream')
const prettyFactory = require('./')
const CONSTANTS = require('./lib/constants')

Expand All @@ -28,14 +28,16 @@ args

const opts = args.parse(process.argv)
const pretty = prettyFactory(opts)
const prettyTransport = through.obj(function (chunk, enc, cb) {
const line = pretty(chunk.toString())
if (line === undefined) return cb()
process.stdout.write(line)
cb()
const prettyTransport = new Transform({
objectMode: true,
transform (chunk, enc, cb) {
const line = pretty(chunk.toString())
if (line === undefined) return cb()
cb(null, line)
}
})

pump(process.stdin, split(), prettyTransport)
pump(process.stdin, split(), prettyTransport, process.stdout)

// https://github.com/pinojs/pino/pull/358
if (!process.stdin.isTTY && !fs.fstatSync(process.stdin.fd).isFile()) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = function prettyFactory (options) {
message: nocolor
}
if (opts.colorize) {
const ctx = new chalk.constructor({enabled: true, level: 3})
const ctx = new chalk.constructor({ enabled: true, level: 3 })
color.default = ctx.white
color[60] = ctx.bgRed
color[50] = ctx.red
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"fast-json-parse": "^1.0.3",
"jmespath": "^0.15.0",
"pump": "^3.0.0",
"split2": "^2.2.0",
"through2": "^2.0.3"
"readable-stream": "^3.0.2",
"split2": "^3.0.0"
},
"devDependencies": {
"pino": "^5.0.0",
"pino": "^5.5.0",
"pre-commit": "^1.2.2",
"snazzy": "^7.1.1",
"standard": "^11.0.1",
"standard": "^12.0.1",
"tap": "^12.0.1"
}
}
24 changes: 12 additions & 12 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Writable = require('stream').Writable
const { Writable } = require('readable-stream')
const os = require('os')
const test = require('tap').test
const pino = require('pino')
Expand Down Expand Up @@ -50,7 +50,7 @@ test('basic prettifier tests', (t) => {

t.test('will add color codes', (t) => {
t.plan(1)
const pretty = prettyFactory({colorize: true})
const pretty = prettyFactory({ colorize: true })
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
Expand All @@ -66,7 +66,7 @@ test('basic prettifier tests', (t) => {

t.test('can swap date and level position', (t) => {
t.plan(1)
const pretty = prettyFactory({levelFirst: true})
const pretty = prettyFactory({ levelFirst: true })
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
Expand All @@ -82,7 +82,7 @@ test('basic prettifier tests', (t) => {

t.test('can use different message keys', (t) => {
t.plan(1)
const pretty = prettyFactory({messageKey: 'bar'})
const pretty = prettyFactory({ messageKey: 'bar' })
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
Expand All @@ -93,12 +93,12 @@ test('basic prettifier tests', (t) => {
cb()
}
}))
log.info({bar: 'baz'})
log.info({ bar: 'baz' })
})

t.test('will format time to UTC', (t) => {
t.plan(1)
const pretty = prettyFactory({translateTime: true})
const pretty = prettyFactory({ translateTime: true })
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
Expand Down Expand Up @@ -180,7 +180,7 @@ test('basic prettifier tests', (t) => {
t.test('handles missing pid, hostname and name', (t) => {
t.plan(1)
const pretty = prettyFactory()
const log = pino({base: null}, new Writable({
const log = pino({ base: null }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.match(formatted, /\[.*\] INFO: hello world/)
Expand Down Expand Up @@ -264,7 +264,7 @@ test('basic prettifier tests', (t) => {
t.test('works without time', (t) => {
t.plan(1)
const pretty = prettyFactory()
const log = pino({timestamp: null}, new Writable({
const log = pino({ timestamp: null }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `[undefined] INFO (${pid} on ${hostname}): hello world\n`)
Expand All @@ -284,7 +284,7 @@ test('basic prettifier tests', (t) => {
cb()
}
}))
log.info({a: 'b'}, 'hello world')
log.info({ a: 'b' }, 'hello world')
})

t.test('prettifies nested properties', (t) => {
Expand Down Expand Up @@ -315,7 +315,7 @@ test('basic prettifier tests', (t) => {
t.test('treats the name with care', (t) => {
t.plan(1)
const pretty = prettyFactory()
const log = pino({name: 'matteo'}, new Writable({
const log = pino({ name: 'matteo' }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `[${epoch}] INFO (matteo/${pid} on ${hostname}): hello world\n`)
Expand Down Expand Up @@ -349,7 +349,7 @@ test('basic prettifier tests', (t) => {
t.test('handles customLogLevel', (t) => {
t.plan(1)
const pretty = prettyFactory()
const log = pino({customLevels: {testCustom: 35}}, new Writable({
const log = pino({ customLevels: { testCustom: 35 } }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.match(formatted, /USERLVL/)
Expand Down Expand Up @@ -425,7 +425,7 @@ test('basic prettifier tests', (t) => {

t.test('handles `undefined` return values', (t) => {
t.plan(2)
const pretty = prettyFactory({search: 'msg == \'hello world\''})
const pretty = prettyFactory({ search: 'msg == \'hello world\'' })
let formatted = pretty(`{"msg":"nope", "time":${epoch}, "level":30, "v":1}`)
t.is(formatted, undefined)
formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30, "v":1}`)
Expand Down
2 changes: 1 addition & 1 deletion test/crlf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('crlf', (t) => {

t.test('can use CRLF', (t) => {
t.plan(1)
const pretty = prettyFactory({crlf: true})
const pretty = prettyFactory({ crlf: true })
const formatted = pretty(logLine)
t.is(formatted.substr(-3), 'd\r\n')
})
Expand Down
14 changes: 7 additions & 7 deletions test/error-objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('error like objects tests', (t) => {

t.test('errorProps recognizes user specified properties', (t) => {
t.plan(3)
const pretty = prettyFactory({errorProps: 'statusCode,originalStack'})
const pretty = prettyFactory({ errorProps: 'statusCode,originalStack' })
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
Expand Down Expand Up @@ -77,7 +77,7 @@ test('error like objects tests', (t) => {
const expected = err.stack.split('\n')
expected.unshift(err.message)

const log = pino({serializers: {err: serializers.err}}, new Writable({
const log = pino({ serializers: { err: serializers.err } }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
const lines = formatted.split('\n')
Expand All @@ -94,7 +94,7 @@ test('error like objects tests', (t) => {
}
}))

log.info({err})
log.info({ err })
})

t.test('prettifies Error in property within errorLikeObjectKeys when stack is not the last property', (t) => {
Expand All @@ -108,7 +108,7 @@ test('error like objects tests', (t) => {
const expected = err.stack.split('\n')
expected.unshift(err.message)

const log = pino({serializers: {err: serializers.err}}, new Writable({
const log = pino({ serializers: { err: serializers.err } }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
const lines = formatted.split('\n')
Expand All @@ -126,12 +126,12 @@ test('error like objects tests', (t) => {
}
}))

log.info({err})
log.info({ err })
})

t.test('errorProps flag with "*" (print all nested props)', function (t) {
t.plan(9)
const pretty = prettyFactory({errorProps: '*'})
const pretty = prettyFactory({ errorProps: '*' })
const expectedLines = [
' error stack',
'statusCode: 500',
Expand Down Expand Up @@ -181,7 +181,7 @@ test('error like objects tests', (t) => {
}
}))

const error = {message: 'foo', stack: null}
const error = { message: 'foo', stack: null }
log.error(error)
})

Expand Down

0 comments on commit ee13276

Please sign in to comment.