Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / utils / client-side-logger.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x0aa3=['agent_id','agent_name','express-winston','path','util','fileLogger','./safe-template','safeTemplate','./mask-sensitive-data','maskSensitiveData','join','/var','log','client','role','ensureDir','catch','then','user','no-user','data','timestamp','error','api','auth','set','client-side-logger','use','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s','isEmpty','body','\x20body=%s','format','method','headers','x-forwarded-for','connection','url','statusCode','responseTime','name','logger','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)','remoteAddress','device'];(function(_0x307ed1,_0x436047){var _0x5e1470=function(_0x15c131){while(--_0x15c131){_0x307ed1['push'](_0x307ed1['shift']());}};_0x5e1470(++_0x436047);}(_0x0aa3,0x1f1));var _0x30aa=function(_0x4c63dc,_0x836ede){_0x4c63dc=_0x4c63dc-0x0;var _0x5f1d98=_0x0aa3[_0x4c63dc];return _0x5f1d98;};var fs=require('fs-extra');var _=require('lodash');var ewinston=require(_0x30aa('0x0'));var path=require(_0x30aa('0x1'));var util=require(_0x30aa('0x2'));var fileLogger=require('./loggers')[_0x30aa('0x3')];var safeTemplate=require(_0x30aa('0x4'))[_0x30aa('0x5')];var maskSensitiveData=require(_0x30aa('0x6'))[_0x30aa('0x7')];function ClientSideLogger(){function _0x4a4e0c(_0x56cbdf){var _0x333e3c=path[_0x30aa('0x8')](_0x30aa('0x9'),_0x30aa('0xa'),'xcally');var _0x16c4b0=path[_0x30aa('0x8')](_0x30aa('0xb'),_0x56cbdf[_0x30aa('0xc')]+'-'+_0x56cbdf['name']);return fs[_0x30aa('0xd')](path['join'](_0x333e3c,_0x16c4b0))['then'](function(){var _0x508f10=fileLogger(_0x30aa('0xb'),path[_0x30aa('0x8')](_0x333e3c,_0x16c4b0));return _0x508f10;})[_0x30aa('0xe')](function(_0x442071){throw _0x442071;});}this['log']=function(_0x4eaf50,_0x5d858a,_0x45052e,_0x2a6aab){return _0x4a4e0c(_0x4eaf50['user'])[_0x30aa('0xf')](function(_0x2ec100){var _0x451272=_0x2ec100[_0x5d858a];return _0x451272;})[_0x30aa('0xf')](function(_0x26c292){var _0x3b8e1e=_0x4eaf50[_0x30aa('0x10')]?_0x4eaf50[_0x30aa('0x10')]['id']:_0x30aa('0x11');var _0x26db9f=_0x2a6aab[_0x30aa('0x12')];var _0x488e31=_0x2a6aab[_0x30aa('0x13')];var _0x28d708=new Date(Number(_0x488e31));return _0x26c292(_0x3b8e1e,_0x28d708,_0x45052e,_0x26db9f);})[_0x30aa('0xe')](function(_0x27181c){fileLogger(_0x30aa('0xb'))[_0x30aa('0x14')](_0x27181c);});};}function setupLoggers(_0x5f1320){return new Promise(function(_0x2e50f2){var _0x3822e4=new ClientSideLogger();var _0x557f90=fileLogger(_0x30aa('0x15'));var _0x23adbc=fileLogger(_0x30aa('0x16'));_0x5f1320[_0x30aa('0x17')](_0x30aa('0x18'),_0x3822e4);_0x5f1320[_0x30aa('0x19')](ewinston['logger']({'winstonInstance':_0x557f90,'meta':![],'statusLevels':!![],'msg':function(_0x5dc61c,_0x438305){var _0x2adc94=_0x30aa('0x1a');if(!_[_0x30aa('0x1b')](_0x5dc61c[_0x30aa('0x1c')])){_0x2adc94+=_0x30aa('0x1d');var _0x4f738a=_0x5dc61c[_0x30aa('0x1c')];maskSensitiveData(_0x4f738a);}return safeTemplate(util[_0x30aa('0x1e')](_0x2adc94,_0x5dc61c[_0x30aa('0x1f')],_0x5dc61c[_0x30aa('0x20')][_0x30aa('0x21')]?_0x5dc61c[_0x30aa('0x20')][_0x30aa('0x21')]:_0x5dc61c[_0x30aa('0x22')]['remoteAddress']||_0x5dc61c['ip'],_0x5dc61c[_0x30aa('0x23')],_0x438305[_0x30aa('0x24')],_0x438305[_0x30aa('0x25')],_0x5dc61c['user']?_0x5dc61c[_0x30aa('0x10')]['id']:null,_0x5dc61c[_0x30aa('0x10')]?_0x5dc61c['user'][_0x30aa('0x26')]:null,_0x5dc61c[_0x30aa('0x10')]?_0x5dc61c[_0x30aa('0x10')][_0x30aa('0xc')]:null,_0x4f738a?util['inspect'](_0x4f738a,![],null):''));}}));_0x5f1320[_0x30aa('0x19')](ewinston[_0x30aa('0x27')]({'winstonInstance':_0x23adbc,'meta':![],'statusLevels':!![],'msg':function(_0x6f5966,_0x41165d){var _0x2a7f65='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s';if(_0x6f5966[_0x30aa('0x1c')]&&_0x6f5966['body']['device']&&_0x6f5966[_0x30aa('0x1c')]['agent_id']){_0x2a7f65=_0x30aa('0x28');}return util['format'](_0x2a7f65,_0x6f5966['method'],_0x6f5966[_0x30aa('0x20')]['x-forwarded-for']?_0x6f5966['headers'][_0x30aa('0x21')]:_0x6f5966['connection'][_0x30aa('0x29')]||_0x6f5966['ip'],_0x6f5966[_0x30aa('0x23')],_0x41165d['statusCode'],_0x41165d[_0x30aa('0x25')],_0x6f5966['user']?_0x6f5966[_0x30aa('0x10')]['id']:null,_0x6f5966['user']?_0x6f5966['user']['name']:null,_0x6f5966[_0x30aa('0x10')]?_0x6f5966[_0x30aa('0x10')]['role']:null,_0x6f5966['body']&&_0x6f5966[_0x30aa('0x1c')][_0x30aa('0x2a')]?_0x6f5966[_0x30aa('0x1c')][_0x30aa('0x2a')]:'other',_0x6f5966[_0x30aa('0x1c')]&&_0x6f5966[_0x30aa('0x1c')][_0x30aa('0x2b')]?_0x6f5966['body']['agent_id']:'',_0x6f5966[_0x30aa('0x1c')]&&_0x6f5966['body']['agent_name']?_0x6f5966['body'][_0x30aa('0x2c')]:'');},'ignoreRoute':function(_0x46f68a){var _0x473194=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x473194['test'](_0x46f68a[_0x30aa('0x23')]);}}));return _0x2e50f2();});}exports['setupLoggers']=setupLoggers;