2023-01-25 08:43:11 +00:00
|
|
|
import { useRef } from 'react';
|
|
|
|
import { BrowserTracing } from '@sentry/tracing';
|
|
|
|
import * as Sentry from '@sentry/browser';
|
2023-04-21 15:29:30 +00:00
|
|
|
import type { LocalLogger, LoggerConf } from '@vegaprotocol/utils';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { localLoggerFactory } from '@vegaprotocol/utils';
|
2023-01-25 08:43:11 +00:00
|
|
|
|
2023-04-21 15:29:30 +00:00
|
|
|
interface Props extends LoggerConf {
|
2023-01-25 08:43:11 +00:00
|
|
|
dsn?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useLogger = ({ dsn, ...props }: Props) => {
|
|
|
|
const logger = useRef<LocalLogger | null>(null);
|
|
|
|
if (!logger.current) {
|
|
|
|
logger.current = localLoggerFactory(props);
|
|
|
|
if (dsn) {
|
|
|
|
Sentry.init({
|
|
|
|
dsn,
|
|
|
|
integrations: [new BrowserTracing()],
|
|
|
|
tracesSampleRate: 1,
|
|
|
|
defaultIntegrations: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return logger.current;
|
|
|
|
};
|