trentm / node-bunyan

a simple and fast JSON logging module for node.js services
Other
7.15k stars 513 forks source link

Inconsistent behaviour on Windows with PowerShell #699

Open TeamDman opened 1 year ago

TeamDman commented 1 year ago

Problem

The non-cmd bin file works to format log entries from a piped node process, unless that process is running an http server.

Versions

node: v18.6.0 bunyan: "^1.8.15" typescript: "^4.7.4"

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Demo

asd 3.js

const bunyan = require("bunyan");
const http = require("http");
const log = bunyan.createLogger({name: "beans"});

log.info("Starting");
http.createServer(undefined).listen(8080);
log.info("howdy");

Desired, but not working

PS> node '.\asd 3.js' | .\node_modules\.bin\bunyan
<nothing>

No formatting

PS> node '.\asd 3.js'                             
{"name":"beans","hostname":"Teamy-Desktop","pid":1280,"level":30,"msg":"Starting","time":"2022-07-27T02:56:24.297Z","v":0}
{"name":"beans","hostname":"Teamy-Desktop","pid":1280,"level":30,"msg":"howdy","time":"2022-07-27T02:56:24.301Z","v":0}

Works

PS> node '.\asd 3.js' | .\node_modules\.bin\bunyan.cmd
[2022-07-27T02:56:48.222Z]  INFO: beans/3192 on Teamy-Desktop: Starting
[2022-07-27T02:56:48.226Z]  INFO: beans/3192 on Teamy-Desktop: howdy

It took me longer than it should have to realize there was a .cmd version of the bin file, rather than some weird magical extension behaviour with powershell causing it to work.

asd 2.js

const bunyan = require("bunyan");

const log = bunyan.createLogger({ name: "radica backend", level: "debug", stream: process.stdout });

async function main() {
    log.info("howdy");
}
main();

Works without using the .cmd

PS> node '.\asd 2.js' | .\node_modules\.bin\bunyan
[2022-07-27T03:01:34.528Z]  INFO: radica backend/17224 on Teamy-Desktop: howdy