import { getCurrentHub } from '@sentry/core' ; import { Integration } from '@sentry/types' ; import { fill , severityFromString } from '@sentry/utils' ; import * as util from 'util' ; /** Console module integration */ export class Console implements Integration { inheritDoc public static id : string = 'Console' ; inheritDoc public name : string = Console . id ; inheritDoc public setupOnce ( ) { for ( const level of [ 'debug' , 'info' , 'warn' , 'error' , 'log' ] ) { fill ( console , level , createConsoleWrapper ( level ) ) ; } } } /**
 * Wrapper function that'll be used for every console level
 */ function createConsoleWrapper ( level ) { return function consoleWrapper ( originalConsoleMethod ) : ( ) => void { const sentryLevel = severityFromString ( level ) ; return function ( this ) : void { if ( getCurrentHub ( ) . getIntegration ( Console ) ) { getCurrentHub ( ) . addBreadcrumb ( { category : 'console' , level : sentryLevel , message : util . format . apply ( undefined , arguments ) , } , { input : [ ... arguments ] , level , } ) ; } originalConsoleMethod . apply ( this , arguments ) ; } ; } ; }