podchat-browser
Version:
Javascript SDK to use POD's Chat Service - Browser Only
58 lines (57 loc) • 1.88 kB
JavaScript
function LogsManager(app) {
const tags = {
CHAT_MESSAGE: {
id: 'CHAT_MESSAGE',
enabled: false,
label: '[chatMessage]',
labelColor: 'green'
},
CALL_SERVER_MESSAGE: {
id: 'CALL_SERVER_MESSAGE',
enabled: false,
label: '[callMessage]',
labelColor: 'blue'
},
CALL_PROCESS: {
id: 'CALL_PROCESS',
enabled: false,
label: '[callProcess]',
labelColor: 'purple'
}
};
return {
tags,
processInitConfig(config) {
Object.keys(config).forEach(item => {
if(config[item]) {
if(typeof config[item] == "boolean") {
tags[item].enabled = config[item];
} else
console.warn('[SDK] loggerConfig is incorrect.');
}
});
},
enableTag(id){
tags[id].enabled = true;
},
disableTag(id){
tags[id].enabled = false;
},
log(tagId, label, data) {
if(tags[tagId] && tags[tagId].enabled) {
console.log(`%c[SDK]${tags[tagId].label}${label} `, `color: ${tags[tagId].labelColor};`, data);
}
},
error(tagId, label, data){
if(tags[tagId] && tags[tagId].enabled) {
console.error(`%c[SDK]${tags[tagId].label}${label} `, `color: ${tags[tagId].labelColor};`, data);
}
},
warn(tagId, label, data){
if(tags[tagId] && tags[tagId].enabled) {
console.warn(`%c[SDK]${tags[tagId].label}${label} `, `color: ${tags[tagId].labelColor};`, data);
}
}
}
}
export default LogsManager;