Skip to content

Commit

Permalink
feat: logger script [WTEL-5425](https://webitel.atlassian.net/browse/…
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 11, 2024
1 parent 5349b30 commit 2d00667
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "24.10.65",
"version": "24.10.66",
"private": false,
"scripts": {
"dev": "vite",
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -46,6 +47,7 @@ export {
eventBus,
isEmpty,
convertDuration,
wtlog,

// compareSize.js
compareSize,
Expand Down
38 changes: 38 additions & 0 deletions src/scripts/logger.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 2d00667

Please sign in to comment.