I am using the console.error() console.warn() in man places in my app to track failing code. Is there anyway to automatically log these to Sentry. https://sentry.io.
It is a react app, and it seems the componentDidCatch() method they suggest only catches exceptions.
In case this helps anyone, use Sentry's CaptureConsole integration for this:
Sentry.Integrations.CaptureConsole
Official Documentation: https://docs.sentry.io/platforms/javascript/configuration/integrations/plugin/#captureconsole
Refer to this post: How to report console.error with Sentry?
Example Code:
import { CaptureConsole as CaptureConsoleIntegration } from "@sentry/integrations";
Sentry.init({
dsn: 'https://your-sentry-server-dsn',
debug: true, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
integrations: [new CaptureConsoleIntegration(
{
// array of methods that should be captured
// defaults to ['log', 'info', 'warn', 'error', 'debug', 'assert']
levels: ['log', 'info', 'warn', 'error', 'debug', 'assert']
}
)]
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With