-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: logger script [WTEL-5425](https://webitel.atlassian.net/browse/…
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |