UNPKG

@adaptabletools/adaptable

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

63 lines (62 loc) 2.25 kB
import { debug as debugFactory } from '@infinite-table/infinite-react'; const performanceTime = (previousTime) => { const now = performance.now(); return Math.round(previousTime ? now - previousTime : now); }; export class LMLogger { constructor(options) { this.debugId = options.debugId; this.debugger = debugFactory(this.debugId ? `LayoutManager:${this.debugId}` : 'LayoutManager'); this.infoLogger = this.debugger.extend(`info`); this.infoLogger.logFn = console.info.bind(console); this.successLogger = this.debugger.extend(`success`); this.successLogger.logFn = console.log.bind(console); this.warnLogger = this.debugger.extend(`warn`); this.warnLogger.logFn = console.warn.bind(console); this.errorLogger = this.debugger.extend(`error`); this.errorLogger.logFn = console.error.bind(console); this.perfLogger = this.debugger.extend(`perf`); this.perfLogger.logFn = console.info.bind(console); } beginPerf(sectionName) { this.perfLogger(`[BEGIN] - ${sectionName}`); const startTime = performanceTime(); return { end: (additionalComment) => { this.perfLogger(`[END] - ${sectionName} ${additionalComment ? `(${additionalComment})` : ''} :: [delta +${performanceTime(startTime)}ms]`); }, }; } info(message, ...optionalParams) { if (optionalParams?.length) { this.infoLogger(message, ...optionalParams); } else { this.infoLogger(message); } } success(message, ...optionalParams) { if (optionalParams?.length) { this.successLogger(message, ...optionalParams); } else { this.successLogger(message); } } warn(message, ...optionalParams) { if (optionalParams?.length) { this.warnLogger(message, ...optionalParams); } else { this.warnLogger(message); } } error(message, ...optionalParams) { if (optionalParams?.length) { this.errorLogger(message, ...optionalParams); } else { this.errorLogger(message); } } }