2016-12-07 02:36:45 +05:30
|
|
|
import Raven from 'raven-js';
|
|
|
|
|
|
|
|
const isTest = process.env.__TEST__; // eslint-disable-line
|
|
|
|
|
|
|
|
const logger = {
|
|
|
|
init({sentryCdn}) {
|
|
|
|
if (sentryCdn) {
|
|
|
|
Raven.config(sentryCdn, {
|
|
|
|
logger: 'accounts-js-app',
|
|
|
|
level: 'info',
|
2016-12-07 02:46:34 +05:30
|
|
|
environment: process.env.APP_ENV, // eslint-disable-line
|
2016-12-07 02:36:45 +05:30
|
|
|
release: process.env.__VERSION__, // eslint-disable-line
|
|
|
|
shouldSendCallback: () => !isTest,
|
|
|
|
dataCallback: (data) => {
|
|
|
|
if (!data.level) {
|
|
|
|
// log unhandled errors as info
|
|
|
|
data.level = 'info';
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}).install();
|
|
|
|
|
|
|
|
window.addEventListener('unhandledrejection',
|
|
|
|
(event) => Raven.captureException(event.reason)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setUser(user) {
|
|
|
|
Raven.setUserContext({
|
|
|
|
username: user.username,
|
|
|
|
email: user.email,
|
|
|
|
id: user.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
[
|
|
|
|
// 'fatal',
|
|
|
|
'error',
|
|
|
|
'warning',
|
|
|
|
'info',
|
|
|
|
'debug'
|
|
|
|
].forEach((level) => {
|
2017-01-02 18:39:09 +05:30
|
|
|
const method = level === 'warning' ? 'warn' : level;
|
2016-12-07 02:36:45 +05:30
|
|
|
|
2017-01-02 18:39:09 +05:30
|
|
|
logger[method] = (message, context) => {
|
2016-12-07 02:36:45 +05:30
|
|
|
if (isTest) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-02 18:39:09 +05:30
|
|
|
console[method](message, context);
|
2016-12-07 02:36:45 +05:30
|
|
|
|
|
|
|
Raven.captureException(message, {
|
|
|
|
level,
|
|
|
|
extra: context
|
2017-01-02 18:39:09 +05:30
|
|
|
});
|
2016-12-07 02:36:45 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
export default logger;
|