import { ILogger } from 'polar-shared/src/logger/ILogger' ; import { isPresent } from 'polar-shared/src/Preconditions' ; import process from "process" ; let initialized = false ; let ready = false ; export class SentryNodeLogger implements ILogger { public readonly name : string = 'sentry-node-logger' ; public notice ( msg , ... args ) { SentryNodeLogger . initWhenNecessary ( ) ; } public warn ( msg , ... args ) { SentryNodeLogger . initWhenNecessary ( ) ; } public error ( msg , ... args ) { SentryNodeLogger . initWhenNecessary ( ) ; if ( ready ) { args . forEach ( arg => { if ( arg instanceof Error ) { try { } catch ( e ) { console . error ( "Failed to process exception for sentry: " , e ) ; } } } ) ; } } public info ( msg , ... args ) { SentryNodeLogger . initWhenNecessary ( ) ; } public verbose ( msg , ... args ) { SentryNodeLogger . initWhenNecessary ( ) ; } public debug ( msg , ... args ) { SentryNodeLogger . initWhenNecessary ( ) ; } public async sync ( ) { SentryNodeLogger . initWhenNecessary ( ) ; } public static isEnabled ( ) { if ( isPresent ( process . env . POLAR_SENTRY_ENABLED ) ) { return process . env . POLAR_SENTRY_ENABLED === 'true' ; } return ! isPresent ( process . env . SNAP ) ; } private static initWhenNecessary ( ) { if ( initialized ) { return ; } try { if ( SentryNodeLogger . isEnabled ( ) ) { } ready = true ; } catch ( e ) { console . error ( "Unable to initialize sentry: " , e ) ; } finally { initialized = true ; } } }