Skip to content

Instantly share code, notes, and snippets.

@kpheasey
Created February 2, 2020 19:49
Show Gist options
  • Save kpheasey/c973cebfd739ca3a21d67c03cdd408fa to your computer and use it in GitHub Desktop.
Save kpheasey/c973cebfd739ca3a21d67c03cdd408fa to your computer and use it in GitHub Desktop.
Sentry Logger
import Logger from './logger';
// console.log('ye message')
Logger.log('my message')
// console.error('error message')
Logger.log('error message', 'error');
Logger.error('error message')
try {
NotReal.call()
} catch(e) {
Logger.captureException(e)
}
import * as Sentry from 'sentry-expo';
const log = (message, level) => {
console.log(message);
Sentry.addBreadcrumb({
message,
level,
})
};
const captureMessage = (message, level) => {
try {
console.reportErrorsAsExceptions = false;
Sentry.captureMessage(message, level)
} catch {
console.log('Failed to send message to Sentry')
} finally {
console.reportErrorsAsExceptions = true
}
};
const captureException = (exception) => {
try {
console.reportErrorsAsExceptions = false;
Sentry.captureException(exception)
} catch {
console.log('Failed to send exception to Sentry');
console.reportErrorsAsExceptions = true
}
};
const Logger = {
debug: msg => log(msg, 'debug'),
info: msg => log(msg, 'info'),
error: msg => log(msg, 'error'),
captureMessage,
captureException,
};
export default Logger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment