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 d63257d commit 3e7f00b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
19 changes: 18 additions & 1 deletion lib/tools.js
Expand Up @@ -520,6 +520,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 @@ -530,5 +546,6 @@ module.exports = {
createArgsNormalizer,
final,
stringify,
buildFormatters
buildFormatters,
normalizeDestFileDescriptor
}
9 changes: 5 additions & 4 deletions pino.js
Expand Up @@ -15,8 +15,9 @@ const {
final,
buildSafeSonicBoom,
buildFormatters,
noop,
stringify
stringify,
normalizeDestFileDescriptor,
noop
} = require('./lib/tools')
const { version } = require('./lib/meta')
const {
Expand Down Expand Up @@ -191,10 +192,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 3e7f00b

Please sign in to comment.