Built motion from commit d5e4af8c.|2.6.23
[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 _0x37a6=['remoteAddress','url','statusCode','responseTime','use','logger','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s','device','agent_id','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)','method','other','agent_name','test','setupLoggers','fs-extra','lodash','express-winston','util','./loggers','./safe-template','safeTemplate','./mask-sensitive-data','maskSensitiveData','join','/var','log','client','role','name','ensureDir','user','no-user','data','timestamp','catch','error','api','auth','set','client-side-logger','body','\x20body=%s','format','headers','x-forwarded-for','connection'];(function(_0x2dc343,_0xf015a2){var _0x51eac5=function(_0x1adfef){while(--_0x1adfef){_0x2dc343['push'](_0x2dc343['shift']());}};_0x51eac5(++_0xf015a2);}(_0x37a6,0xfa));var _0x637a=function(_0x4b3637,_0x3657ea){_0x4b3637=_0x4b3637-0x0;var _0x2fcb89=_0x37a6[_0x4b3637];return _0x2fcb89;};var fs=require(_0x637a('0x0'));var _=require(_0x637a('0x1'));var ewinston=require(_0x637a('0x2'));var path=require('path');var util=require(_0x637a('0x3'));var fileLogger=require(_0x637a('0x4'))['fileLogger'];var safeTemplate=require(_0x637a('0x5'))[_0x637a('0x6')];var maskSensitiveData=require(_0x637a('0x7'))[_0x637a('0x8')];function ClientSideLogger(){function _0x470508(_0x4ee53c){var _0x47d4aa=path[_0x637a('0x9')](_0x637a('0xa'),_0x637a('0xb'),'xcally');var _0x2ec776=path[_0x637a('0x9')](_0x637a('0xc'),_0x4ee53c[_0x637a('0xd')]+'-'+_0x4ee53c[_0x637a('0xe')]);return fs[_0x637a('0xf')](path[_0x637a('0x9')](_0x47d4aa,_0x2ec776))['then'](function(){var _0x5d5f23=fileLogger(_0x637a('0xc'),path[_0x637a('0x9')](_0x47d4aa,_0x2ec776));return _0x5d5f23;})['catch'](function(_0x2c1622){throw _0x2c1622;});}this[_0x637a('0xb')]=function(_0x4bb919,_0x4ecffc,_0x5bf12e,_0x5e1430){return _0x470508(_0x4bb919[_0x637a('0x10')])['then'](function(_0x81c71d){var _0x1b1211=_0x81c71d[_0x4ecffc];return _0x1b1211;})['then'](function(_0x373ce0){var _0x42fa9a=_0x4bb919[_0x637a('0x10')]?_0x4bb919[_0x637a('0x10')]['id']:_0x637a('0x11');var _0x2ca626=_0x5e1430[_0x637a('0x12')];var _0x46ac18=_0x5e1430[_0x637a('0x13')];var _0x5cfcb4=new Date(Number(_0x46ac18));return _0x373ce0(_0x42fa9a,_0x5cfcb4,_0x5bf12e,_0x2ca626);})[_0x637a('0x14')](function(_0x3ac7af){fileLogger(_0x637a('0xc'))[_0x637a('0x15')](_0x3ac7af);});};}function setupLoggers(_0x3fb7b2){return new Promise(function(_0x2c2e3c){var _0x309b0a=new ClientSideLogger();var _0x3ed6a7=fileLogger(_0x637a('0x16'));var _0x5d81f=fileLogger(_0x637a('0x17'));_0x3fb7b2[_0x637a('0x18')](_0x637a('0x19'),_0x309b0a);_0x3fb7b2['use'](ewinston['logger']({'winstonInstance':_0x3ed6a7,'meta':![],'statusLevels':!![],'msg':function(_0xc55cc2,_0x2e927d){var _0x22efec='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s';if(!_['isEmpty'](_0xc55cc2[_0x637a('0x1a')])){_0x22efec+=_0x637a('0x1b');var _0x3cacef=_0xc55cc2[_0x637a('0x1a')];maskSensitiveData(_0x3cacef);}return safeTemplate(util[_0x637a('0x1c')](_0x22efec,_0xc55cc2['method'],_0xc55cc2[_0x637a('0x1d')]['x-forwarded-for']?_0xc55cc2[_0x637a('0x1d')][_0x637a('0x1e')]:_0xc55cc2[_0x637a('0x1f')][_0x637a('0x20')]||_0xc55cc2['ip'],_0xc55cc2[_0x637a('0x21')],_0x2e927d[_0x637a('0x22')],_0x2e927d[_0x637a('0x23')],_0xc55cc2[_0x637a('0x10')]?_0xc55cc2[_0x637a('0x10')]['id']:null,_0xc55cc2[_0x637a('0x10')]?_0xc55cc2['user'][_0x637a('0xe')]:null,_0xc55cc2['user']?_0xc55cc2[_0x637a('0x10')][_0x637a('0xd')]:null,_0x3cacef?util['inspect'](_0x3cacef,![],null):''));}}));_0x3fb7b2[_0x637a('0x24')](ewinston[_0x637a('0x25')]({'winstonInstance':_0x5d81f,'meta':![],'statusLevels':!![],'msg':function(_0x3e147f,_0x5ca078){var _0x322970=_0x637a('0x26');if(_0x3e147f[_0x637a('0x1a')]&&_0x3e147f[_0x637a('0x1a')][_0x637a('0x27')]&&_0x3e147f[_0x637a('0x1a')][_0x637a('0x28')]){_0x322970=_0x637a('0x29');}return util[_0x637a('0x1c')](_0x322970,_0x3e147f[_0x637a('0x2a')],_0x3e147f['headers']['x-forwarded-for']?_0x3e147f['headers'][_0x637a('0x1e')]:_0x3e147f[_0x637a('0x1f')][_0x637a('0x20')]||_0x3e147f['ip'],_0x3e147f[_0x637a('0x21')],_0x5ca078[_0x637a('0x22')],_0x5ca078[_0x637a('0x23')],_0x3e147f['user']?_0x3e147f[_0x637a('0x10')]['id']:null,_0x3e147f['user']?_0x3e147f[_0x637a('0x10')][_0x637a('0xe')]:null,_0x3e147f[_0x637a('0x10')]?_0x3e147f[_0x637a('0x10')]['role']:null,_0x3e147f['body']&&_0x3e147f[_0x637a('0x1a')][_0x637a('0x27')]?_0x3e147f[_0x637a('0x1a')]['device']:_0x637a('0x2b'),_0x3e147f['body']&&_0x3e147f['body'][_0x637a('0x28')]?_0x3e147f['body'][_0x637a('0x28')]:'',_0x3e147f[_0x637a('0x1a')]&&_0x3e147f[_0x637a('0x1a')][_0x637a('0x2c')]?_0x3e147f['body'][_0x637a('0x2c')]:'');},'ignoreRoute':function(_0xabde1){var _0xca5f37=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0xca5f37[_0x637a('0x2d')](_0xabde1['url']);}}));return _0x2c2e3c();});}exports[_0x637a('0x2e')]=setupLoggers;