import { inject , injectable } from 'inversify' ; import { isEmpty } from 'lodash' ; import * as util from 'util' ; import { iocTypes } from '../ioc/ioc-types' ; import { BaseTelemetryProperties } from './base-telemetry-properties' ; import { LoggerClient , LogLevel } from './logger-client' ; import { LoggerProperties } from './logger-properties' ; @ injectable ( ) export class ConsoleLoggerClient implements LoggerClient { private baseProperties ? : BaseTelemetryProperties ; constructor ( @ inject ( iocTypes . Console ) private readonly consoleObject ) { } public async setup ( baseProperties ? ) { this . baseProperties = baseProperties ; } public log ( message , logLevel , properties ? ) { this . logInConsole ( `[Trace][${ LogLevel [ logLevel ] }]${ this . getPrintablePropertiesString ( properties ) }` , message ) ; } public trackException ( error ) { this . logInConsole ( `[Exception]${ this . getPrintablePropertiesString ( ) }` , this . getPrintableString ( error ) ) ; } public setCustomProperties ( properties ) { this . baseProperties = { ... this . baseProperties , ... properties } ; } private getPrintablePropertiesString ( properties ? ) { const allProperties = { ... this . baseProperties , ... properties , } ; return isEmpty ( allProperties ) ? '' : `[properties - ${ this . getPrintableString ( allProperties ) }]` ; } private getPrintableString ( obj ) { return util . inspect ( obj , { depth : null } ) ; } private logInConsole ( tag , content ) { this . consoleObject . log ( `${ tag } === ${ content }` ) ; } }