Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Nov 20, 2021
1 parent d09c75f commit 1597e4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
10 changes: 1 addition & 9 deletions file.js
Expand Up @@ -4,15 +4,7 @@ const pino = require('./pino')
const { once } = require('events')

module.exports = async function (opts = {}) {
const destination = pino.destination({ dest: normalizeDest(opts.destination || 1), sync: false })
const destination = pino.destination({ dest: opts.destination || 1, sync: false })
await once(destination, 'ready')
return destination
}

function normalizeDest (destination) {
const fd = Number(destination)
if (typeof destination === 'string' && Number.isFinite(fd)) {
return fd
}
return destination
}
19 changes: 18 additions & 1 deletion lib/tools.js
Expand Up @@ -514,6 +514,22 @@ function setMetadataProps (dest, that) {
}
}

/**
* Convert a string integer file descriptor to a proper native integer
* file descriptor.
*
* @param {string} destination The file descriptor string to attempt to convert.
*
* @returns {Number}
*/
function normalizeDestFileDescriptor (destination) {
const fd = Number(destination)
if (typeof destination === 'string' && Number.isFinite(fd)) {
return fd
}
return destination
}

module.exports = {
noop,
buildSafeSonicBoom,
Expand All @@ -524,5 +540,6 @@ module.exports = {
createArgsNormalizer,
final,
stringify,
buildFormatters
buildFormatters,
normalizeDestFileDescriptor
}
5 changes: 3 additions & 2 deletions pino.js
Expand Up @@ -15,6 +15,7 @@ const {
stringify,
buildSafeSonicBoom,
buildFormatters,
normalizeDestFileDescriptor,
noop
} = require('./lib/tools')
const { version } = require('./lib/meta')
Expand Down Expand Up @@ -175,10 +176,10 @@ module.exports = pino

module.exports.destination = (dest = process.stdout.fd) => {
if (typeof dest === 'object') {
dest.dest = dest.dest || process.stdout.fd
dest.dest = normalizeDestFileDescriptor(dest.dest || process.stdout.fd)
return buildSafeSonicBoom(dest)
} else {
return buildSafeSonicBoom({ dest, minLength: 0, sync: true })
return buildSafeSonicBoom({ dest: normalizeDestFileDescriptor(dest), minLength: 0, sync: true })
}
}

Expand Down

0 comments on commit 1597e4f

Please sign in to comment.