diff --git a/package.json b/package.json index d7ee6ffbe..eb56183e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@webitel/ui-sdk", - "version": "24.10.65", + "version": "24.10.66", "private": false, "scripts": { "dev": "vite", diff --git a/src/scripts/index.js b/src/scripts/index.js index 26c28c9fc..2827eb235 100644 --- a/src/scripts/index.js +++ b/src/scripts/index.js @@ -7,6 +7,7 @@ import prettifyTime from './prettifyTime.js'; import preventHiddenPageCallsDecorator from './preventHiddenPageCallsDecorator.js'; import saveAsJSON from './saveAsJSON.js'; +import { wtlog } from './logger.js'; import { sortToQueryAdapter, queryToSortAdapter, @@ -46,6 +47,7 @@ export { eventBus, isEmpty, convertDuration, + wtlog, // compareSize.js compareSize, diff --git a/src/scripts/logger.js b/src/scripts/logger.js new file mode 100644 index 000000000..93219793d --- /dev/null +++ b/src/scripts/logger.js @@ -0,0 +1,38 @@ +import isObject from 'lodash/isObject.js'; + +const validateConfig = (config) => { + return isObject(config) && (config.entity || config.module); +}; + +const logger = + (globalApp) => + (type) => + (...params) => { + if (validateConfig(params[0])) { + const config = params[0]; + + const { app = globalApp, entity = '', module = '' } = config; + const timestamp = new Date(); + const path = window?.location?.href || 'non-browser env'; + + return (...msgs) => { + const prependix = `@webitel/${app}:${entity}:${module}:`; + + const appendix = `[${timestamp}][${path}]`; + + return console[type](prependix, ...msgs, appendix); + }; + } + + return console[type](...params); + }; + +export const wtlog = (app) => ({ + info: logger(app)('info'), + warn: logger(app)('warn'), + error: logger(app)('error'), + log: logger(app)('log'), +}); + +// only for ui-sdk usage +export const _wtUiLog = wtlog('ui-sdk');