Last active
July 1, 2021 13:08
-
-
Save holtwick/949d04151586cec529a671859ebbb650 to your computer and use it in GitHub Desktop.
π± Zeed sample for Sentry.io logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://github.com/holtwick/zeed | |
import * as Sentry from "@sentry/browser" | |
import { Integrations } from "@sentry/tracing" | |
import { LogHandler, LogLevel, LogMessage, renderMessages } from "zeed" | |
import { DEBUG, RELEASE, SENTRY_DSN } from "@/config" // Use your config here | |
export function LoggerSentryHandler( | |
level: LogLevel = LogLevel.debug | |
): LogHandler { | |
return (msg: LogMessage) => { | |
if (msg.level < level) return | |
const name = msg.name || "" | |
const message = (name ? `[${name}] ` : "") + renderMessages(msg.messages) | |
const category = "log" | |
switch (msg.level) { | |
case LogLevel.error: | |
Sentry.addBreadcrumb({ | |
category, | |
message, | |
level: Sentry.Severity.Error, | |
}) | |
Sentry.withScope(() => { | |
Sentry.captureMessage(message) | |
}) | |
break | |
case LogLevel.warn: | |
Sentry.addBreadcrumb({ | |
category, | |
message, | |
level: Sentry.Severity.Warning, | |
}) | |
break | |
case LogLevel.info: | |
Sentry.addBreadcrumb({ | |
category, | |
message, | |
level: Sentry.Severity.Info, | |
}) | |
break | |
case LogLevel.debug: | |
Sentry.addBreadcrumb({ | |
category, | |
message, | |
level: Sentry.Severity.Debug, | |
}) | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment