denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.87k stars 5.35k forks source link

Issue with Pino's transport on Windows using Deno 2 and TypeScript - no output is written to the log file #26154

Open marvinhagemeister opened 1 week ago

marvinhagemeister commented 1 week ago

Discussed in https://github.com/denoland/deno/discussions/26150

Originally posted by **cvermeer579** October 11, 2024 I raised the problem with Pino, but they replied: "Thank you for the report. This project targets the Node.js runtime. Please file issues with the runtime if you are not using Node.js". I’m using Deno 2 with TypeScript on Windows, and I've encountered an issue when trying to log with Pino using a transport. The following code works perfectly and logs to the debug console as expected: ```ts import { pino } from 'pino'; export const logger = pino(); ``` However, when I introduce the transport to log to a file, no output appears, and the log file is not created: ```ts import { pino } from 'pino'; const transport = pino.transport({ level: 'trace', target: 'pino/file', options: { destination: '.\\log.txt' }, // Using Windows path }); export const logger = pino(transport); ``` No errors are thrown, but the expected log file doesn't appear, and no logging is written. I am running Deno with the --allow-write flag, and Deno’s internal logger is correctly logging output. Is there any known issue with using Pino's transport functionality on Deno or Windows, or is there something specific I might be missing in my configuration? Warm regards Corrie
marvinhagemeister commented 1 week ago

It seems like we have a bug with the Atomics API. Under the hood pino shells out to the thread-stream package which uses this code where Deno is stuck:

https://github.com/pinojs/thread-stream/blob/57e34022ee0b9dd6ed249fe1c0f3ca08be6cc3af/index.js#L428-L442

stream.flushSync()

let readIndex = Atomics.load(stream[kImpl].state, READ_INDEX)
Atomics.store(stream[kImpl].state, WRITE_INDEX, -1)
Atomics.notify(stream[kImpl].state, WRITE_INDEX)

// Wait for the process to complete
let spins = 0
while (readIndex !== -1) {
  Atomics.wait(stream[kImpl].state, READ_INDEX, readIndex, 1000)
  readIndex = Atomics.load(stream[kImpl].state, READ_INDEX)

  if (readIndex === -2) {
    destroy(stream, new Error('end() failed'))
    return
  }

  if (++spins === 10) {
    destroy(stream, new Error('end() took too long (10s)'))
    return
  }
}
nathanwhit commented 1 week ago

Odd, I know we have a bug with Atomics.waitAsync, but Atomics.wait should work. I can take a look on monday

smith558 commented 3 days ago

I am observing this issue as well. No logs are being outputted to the console. On Ubuntu OS.

my settings:

const loggerModule = LoggerModule.forRootAsync({
  imports: [ConfigModule],
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => ({
    pinoHttp: {
      level: configService.get('NODE_ENV') === 'development' ? 'debug' : 'warn',
      transport:
        configService.get('NODE_ENV') === 'development'
          ? {
              target: 'pino-pretty',
              options: {
                singleLine: true
              }
            }
          : undefined
    }
  })
});