tslog icon indicating copy to clipboard operation
tslog copied to clipboard

workaround for tslog inside NextJS middleware

Open devietti opened this issue 2 years ago • 1 comments

This isn't a bug, but I just wanted to document somewhere that to get tslog to work inside of NextJS middleware (which uses the Edge runtime, which is neither Node nor a browser) I had to set hideLogPositionForProduction to be true:

const middlewareLogger = logger.getSubLogger({
      name: 'middleware',
      hideLogPositionForProduction: true
})
middlewareLogger.info('hello from middleware')

Otherwise, I believe tslog thinks it's running in a browser environment, and crashes when accessing fields of globals like origin which are undefined:

error - node_modules/tslog/dist/esm/runtime/browser/index.js (32:0) @ stackLineToStackFrame
error - Cannot read properties of undefined (reading 'origin')
null

devietti avatar May 05 '23 02:05 devietti

This is also needed for cloudflare workers,

OultimoCoder avatar May 20 '23 17:05 OultimoCoder