useLogger.ts 558 B

12345678910111213141516171819202122232425262728293031
  1. import * as Sentry from '@sentry/nuxt'
  2. import { createConsola, consola } from 'consola'
  3. export function useLogger(tag: string) {
  4. const log = createConsola({
  5. formatOptions: {
  6. date: true,
  7. colors: true,
  8. },
  9. defaults: {
  10. tag,
  11. },
  12. reporters: [
  13. {
  14. log: (ctx) => {
  15. // Logging only on DEV
  16. if (import.meta.dev) {
  17. consola._log(ctx)
  18. }
  19. if (ctx.type === 'error') {
  20. Sentry.captureException(ctx)
  21. }
  22. },
  23. },
  24. ],
  25. })
  26. return log
  27. }