File size: 1,365 Bytes
84c1942 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | import { getGlobal } from './global';
// eslint-disable-next-line
declare var __DEV__: boolean | undefined;
const shouldShowDebugger = () => {
if (typeof __DEV__ !== 'undefined' && __DEV__) {
return true;
}
if (process.env.NODE_ENV === 'development') {
return true;
}
if (
typeof document !== 'undefined' &&
document.location.search.includes('debug')
) {
return true;
}
return false;
};
const getDebugger: () => (key: string) => (...message: any[]) => void = () => {
if (!shouldShowDebugger()) {
const global = getGlobal() as any;
// Return a debugger that will log to sentry
return (key: string) => (message: string) => {
// Disable it for now, seems to affect performance. That's the last thing we want
// from this (https://github.com/codesandbox/codesandbox-client/issues/1671)
// TODO: move this to sentry
if (false || typeof global.Raven === 'object') {
try {
global.Raven.captureBreadcrumb({
message: `${key} - ${message}`,
category: 'logging',
});
} catch (e) {
console.error(e);
}
}
};
}
// @ts-ignore
const debug = require('debug'); // eslint-disable-line global-require
// debug.enable('cs:*');
// debug.disable('cs:cp-*');
return debug;
};
export default getDebugger();
|