Ребят, кто как организует логирование в приложении?
Интересует не логирование во время разработки, а например на этапе тестирования, когда отдел тестеру билд (или первым пользователям) и тут тебе приходит скрин с минимальным описанием. Чтобы в такие моменты больше информации иметь
Sentry использую.
Для самописных ошибок/логов и для тех что вылетают по эксепшенам и так далее.
/**
* Using Sentry service log all warnings/errors which can be thown by the app.
*/
import { Platform } from 'react-native';
import { Sentry, SentrySeverity } from 'react-native-sentry';
import Config from 'react-native-config';
import R from 'ramda';
const capitalize = R.replace(/^./, R.toUpper);
class SentryLogger {
install = () => {
Sentry.config(
Config.SENTRY_URL,
...(Platform.OS === 'ios' && {
deactivateStacktraceMerging: true,
}),
).install();
};
logToSentry = ({ error, type = 'error', description = '', ...rest }) => {
if (!__DEV__) {
if (typeof error === 'object') {
Sentry.captureException(error);
} else {
const errorInfo = `${type}: ${description}: ${error}, rest: ${JSON.stringify(
{ ...rest },
)}`;
Sentry.captureMessage(errorInfo, {
level: SentrySeverity[capitalize(type)],
});
}
}
};
log = ({ error, type = 'debug', description = '', ...rest }) => {
if (__DEV__) {
const errorInfo = `${type}: ${description}: ${error}, rest: ${JSON.stringify(
{ ...rest },
)}`;
/* eslint-disable no-console */
if (type === 'error') console.error(errorInfo);
else if (type === 'warning') console.warn(errorInfo);
else console.log(errorInfo);
/* eslint-enable no-console */
}
};
warning = errorProps => {
this.log({ ...errorProps, type: 'warning' });
this.logToSentry({ ...errorProps, type: 'warning' });
};
error = errorProps => {
this.log({ ...errorProps, type: 'error' });
this.logToSentry({ ...errorProps, type: 'error' });
};
}
export default new SentryLogger();