tslog
tslog copied to clipboard
workaround for tslog inside NextJS middleware
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
This is also needed for cloudflare workers,