import { Logger } from '@salesforce/core' ; export class Loggit { private isvteLogger ; private loggerName ; public constructor ( loggerName = 'isvtePlugin' ) { this . loggerName = loggerName ; } public async logLine ( logMessage , type = '' ) { if ( this . isvteLogger == undefined ) { this . isvteLogger = await Logger . child ( this . loggerName ) ; } switch ( type ) { case 'Error' : { this . isvteLogger . error ( logMessage + ' -> ' + Loggit . getParent ( ) ) ; break ; } case 'Warn' : { this . isvteLogger . warn ( logMessage + ' -> ' + Loggit . getParent ( ) ) ; break ; } default : { this . isvteLogger . debug ( logMessage + ' -> ' + Loggit . getParent ( ) ) ; break ; } } } public async logJSON ( logMessage , type = '' ) { this . logLine ( JSON . stringify ( logMessage ) , type ) ; } ; static getParent ( ) { let parents = [ ] ; const stackRegex = /^\s+at\s+(\w+(?:\.\w+)*)\s+\(/gm ; try { throw new Error ( ) ; } catch ( e ) { let match ; while ( match = stackRegex . exec ( e . stack ) ) { parents . push ( match [ 1 ] ) ; } } return parents . join ( ':' ) ; } ; } export async function logLine ( namespace , logMessage , type = '' ) { const logger = new Loggit ( namespace ) ; logger . logLine ( logMessage , type ) ; }