//// Wrapper class for client logger for below purposes //// 1. Abstracting CST framework code from manual trace log APIs. //// 2. Constrolling instantiation of CST framework code in clientLogger.js based on whether telemetry is enabled class ClientLogWrapper { /// Constructor which also creates an instance of actual logger if telemetry is enabled constructor() { try { if (Helper.isTelemetryEnabled()) { ClientLogger.getLogger(); } } catch (exception) { console.warn(exception); } } /// Gets the client log wrapper. Creates new instance if not already created static getLogger() { if (!window.clientLogWrapper) { window.clientLogWrapper = new ClientLogWrapper(); } return window.clientLogWrapper; } /// Trace info log /// For component, subComponent, action, tag, it is recommended to use standard short and crisp one worder string. /// Examples: /// for component: entity_grid, entity_form etc /// For SubComponent: filter etc /// For tag: RenderGrid etc /// For action: Render etc traceInfo(message, component, subComponent = "", action = "", tag = "", contextInfo = {}) { try { if (Helper.isTelemetryEnabled()) { return ClientLogger.getLogger().traceInfo(message, component, subComponent, action, tag, contextInfo); } } catch (exception) { console.warn(exception); } } /// Trace warning log /// For component, subComponent, action, tag, it is recommended to use standard short and crisp one worder string. /// Examples: /// for component: entity_grid, entity_form etc /// For SubComponent: filter etc /// For tag: RenderGrid etc /// For action: Render etc traceWarning(message, component, subComponent = "", action = "", tag = "", contextInfo = {}) { try { if (Helper.isTelemetryEnabled()) { return ClientLogger.getLogger().traceWarning(message, component, subComponent, action, tag, contextInfo); } } catch (exception) { console.warn(exception); } } /// Trace error log /// For component, subComponent, action, tag, it is recommended to use standard short and crisp one worder string. /// Examples: /// for component: entity_grid, entity_form etc /// For SubComponent: filter etc /// For tag: RenderGrid etc /// For action: Render etc traceError(message, component, subComponent = "", action = "", tag = "", contextInfo = {}) { try { if (Helper.isTelemetryEnabled()) { return ClientLogger.getLogger().traceError(message, component, subComponent, action, tag, contextInfo); } } catch (exception) { console.warn(exception); } } /// Trace server error log /// For component, subComponent, action, tag, it is recommended to use standard short and crisp one worder string. traceServerError(message, component, subComponent = "", action = "", tag = "", contextInfo = {}) { try { if (Helper.isTelemetryEnabled()) { return ClientLogger.getLogger().traceServerError(message, component, subComponent, action, tag, contextInfo); } } catch (exception) { console.warn(exception); } } /// Get wrapper for block perf tracker getBlockPerfTracker() { try { return new BlockPerfTrackWrapper(); } catch (exception) { console.warn(exception); } } } /// Helper for CST common utilities class Helper { /// Checks whether telemetry is enabled static isTelemetryEnabled() { if (window["Microsoft"].Dynamic365.Portal.isTelemetryEnabled.toUpperCase() == "TRUE") { return true; } else { return false; } } } /// Nested class as wrapper of block perf tracker class BlockPerfTrackWrapper { /// Constructor that helps create block perf tracker if telemetry is enabled constructor() { if (Helper.isTelemetryEnabled()) { this.blockPerfTracker = ClientLogger.getLogger().getBlockPerfTracker(); } } /// Start the timer and set required details for tracking /// For perfTag, component, subComponent, action, , it is recommended to use standard short and crisp one worder string. /// Examples: /// For perfTag: RenderGrid etc /// for component: entity_grid, entity_form etc /// For SubComponent: filter etc /// For action: Render etc start(perfTag, component, subComponent = "", action = "", message = "", contextInfo = {}) { try { if (Helper.isTelemetryEnabled()) { return this.blockPerfTracker.start(perfTag, component, subComponent, action, message, contextInfo); } } catch (exception) { console.warn(exception); } } /// End the timer and log required details for tracking stop() { try { if (Helper.isTelemetryEnabled()) { return this.blockPerfTracker.stop(); } } catch (exception) { console.warn(exception); } } }