Open sentisso opened 2 years ago
bin/bunyan
).process.stdin
's "data"
event is fired (line 1148)\n
or \r\n
) (line 1149)What is the purpose of the leftover
?
(1) no newline chunks are generated by readline.prompt
by design because we want to let the user write in the console right after the output of the prompt, not below it
(2) chunks with a newline in them generates for example a simple console.log("asd")
or bunyan's logger.info("asd")
etc.
Created a PR #683
stdin
? I removed it in my PR, because in order to process prompts correctly, the leftover wouldn't get used at all, since we have to process the newline-less chunks immediately, please correct me if leftovers are actually needed in some cases when processing stdin
.\n
's everywhere when the input is not a valid JSON nor a valid bunyan record, cause the developer may have intended not to include the newline at the end of the message that he tried to log to console\n
's when calling handleLogLine
because they got removed by the split(/\r\n|\n/)
, so when the line is not a valid bunyan record, there's still a newline after it when it gets emitted, because it was there originally (and if it is a valid bunyan record, it doesn't matter, cause JSON.parse
will ignore the newline).var read = require('read');
const logger = bunyan.createLogger({name: 'read'})
logger.info("1) Before read")
read({
prompt: "Enter password:",
silent: true // this should make sure that the text the user types remains hidden
}, (err, res) => {
logger.info(`2) Entered password: ${res}`)
logger.info(`3) Password has been entered`)
})
The above code now performs better than before:
$ node test.js | ../bin/bunyan [2022-02-09T20:31:27.225Z] INFO: read/57815 on asd: 1) Before read Enter password: asd [2022-02-09T20:31:27.882Z] INFO: read/57815 on asd: 2) Entered password: asd [2022-02-09T20:31:27.882Z] INFO: read/57815 on asd: 3) Password has been entered
Although the password (asd
) that is supposed to be hidden is still visible. This problem is a bit deeper and currently above my capacity.
I'm using a npm package called read for silently reading passwords from stdin. When bunyan CLI is used for parsing the output, it gets a little bit broken
Code to reprouce:
The incorrect output of the code above (notice the visible passw0rd123):
The expected output:
What breaks bunyan
I've looked into the
read
's source code and found out what part actually breaks bunyan: node's readline -.prompt()
.The "error" can be reproduced with this code:
The incorrect output of the code above:
The expected output: