Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround for tslog inside NextJS middleware #232

Open
devietti opened this issue May 5, 2023 · 1 comment
Open

workaround for tslog inside NextJS middleware #232

devietti opened this issue May 5, 2023 · 1 comment

Comments

@devietti
Copy link

devietti commented May 5, 2023

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
@OultimoCoder
Copy link

This is also needed for cloudflare workers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants