Built motion from commit f74363e9.|2.6.34
[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 _0xf2c9=['url','other','agent_name','test','setupLoggers','fs-extra','lodash','path','util','./loggers','./safe-template','safeTemplate','maskSensitiveData','join','/var','log','xcally','client','role','name','ensureDir','catch','user','then','data','api','auth','client-side-logger','use','logger','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s','isEmpty','body','format','method','headers','x-forwarded-for','connection','remoteAddress','statusCode','responseTime','inspect','%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)'];(function(_0x5e9af2,_0x5a2b4f){var _0x58db99=function(_0x6d62de){while(--_0x6d62de){_0x5e9af2['push'](_0x5e9af2['shift']());}};_0x58db99(++_0x5a2b4f);}(_0xf2c9,0x1a3));var _0x9f2c=function(_0x1233d2,_0x5416f4){_0x1233d2=_0x1233d2-0x0;var _0x22759e=_0xf2c9[_0x1233d2];return _0x22759e;};var fs=require(_0x9f2c('0x0'));var _=require(_0x9f2c('0x1'));var ewinston=require('express-winston');var path=require(_0x9f2c('0x2'));var util=require(_0x9f2c('0x3'));var fileLogger=require(_0x9f2c('0x4'))['fileLogger'];var safeTemplate=require(_0x9f2c('0x5'))[_0x9f2c('0x6')];var maskSensitiveData=require('./mask-sensitive-data')[_0x9f2c('0x7')];function ClientSideLogger(){function _0x1fd90c(_0x4f8ffb){var _0x3759bc=path[_0x9f2c('0x8')](_0x9f2c('0x9'),_0x9f2c('0xa'),_0x9f2c('0xb'));var _0x12c39e=path[_0x9f2c('0x8')](_0x9f2c('0xc'),_0x4f8ffb[_0x9f2c('0xd')]+'-'+_0x4f8ffb[_0x9f2c('0xe')]);return fs[_0x9f2c('0xf')](path['join'](_0x3759bc,_0x12c39e))['then'](function(){var _0xb90648=fileLogger('client',path[_0x9f2c('0x8')](_0x3759bc,_0x12c39e));return _0xb90648;})[_0x9f2c('0x10')](function(_0x3e9e04){throw _0x3e9e04;});}this[_0x9f2c('0xa')]=function(_0xac0edf,_0x533c92,_0x3979b3,_0x40b92){return _0x1fd90c(_0xac0edf[_0x9f2c('0x11')])['then'](function(_0x301809){var _0x24fb69=_0x301809[_0x533c92];return _0x24fb69;})[_0x9f2c('0x12')](function(_0x136f71){var _0x440412=_0xac0edf[_0x9f2c('0x11')]?_0xac0edf[_0x9f2c('0x11')]['id']:'no-user';var _0x54fa53=_0x40b92[_0x9f2c('0x13')];var _0xddde48=_0x40b92['timestamp'];var _0x3154ad=new Date(Number(_0xddde48));return _0x136f71(_0x440412,_0x3154ad,_0x3979b3,_0x54fa53);})['catch'](function(_0x54e7e5){fileLogger(_0x9f2c('0xc'))['error'](_0x54e7e5);});};}function setupLoggers(_0x7265d2){return new Promise(function(_0x2e1cf8){var _0x1c1868=new ClientSideLogger();var _0x55be6b=fileLogger(_0x9f2c('0x14'));var _0x276935=fileLogger(_0x9f2c('0x15'));_0x7265d2['set'](_0x9f2c('0x16'),_0x1c1868);_0x7265d2[_0x9f2c('0x17')](ewinston[_0x9f2c('0x18')]({'winstonInstance':_0x55be6b,'meta':![],'statusLevels':!![],'msg':function(_0x236053,_0xd43c7d){var _0xf152c4=_0x9f2c('0x19');if(!_[_0x9f2c('0x1a')](_0x236053[_0x9f2c('0x1b')])){_0xf152c4+='\x20body=%s';var _0x36911f=_0x236053['body'];maskSensitiveData(_0x36911f);}return safeTemplate(util[_0x9f2c('0x1c')](_0xf152c4,_0x236053[_0x9f2c('0x1d')],_0x236053[_0x9f2c('0x1e')][_0x9f2c('0x1f')]?_0x236053['headers']['x-forwarded-for']:_0x236053[_0x9f2c('0x20')][_0x9f2c('0x21')]||_0x236053['ip'],_0x236053['url'],_0xd43c7d[_0x9f2c('0x22')],_0xd43c7d[_0x9f2c('0x23')],_0x236053[_0x9f2c('0x11')]?_0x236053[_0x9f2c('0x11')]['id']:null,_0x236053[_0x9f2c('0x11')]?_0x236053[_0x9f2c('0x11')][_0x9f2c('0xe')]:null,_0x236053[_0x9f2c('0x11')]?_0x236053[_0x9f2c('0x11')][_0x9f2c('0xd')]:null,_0x36911f?util[_0x9f2c('0x24')](_0x36911f,![],null):''));}}));_0x7265d2['use'](ewinston[_0x9f2c('0x18')]({'winstonInstance':_0x276935,'meta':![],'statusLevels':!![],'msg':function(_0x3d6cda,_0x1e4e1a){var _0x140be5=_0x9f2c('0x25');if(_0x3d6cda[_0x9f2c('0x1b')]&&_0x3d6cda[_0x9f2c('0x1b')][_0x9f2c('0x26')]&&_0x3d6cda['body'][_0x9f2c('0x27')]){_0x140be5=_0x9f2c('0x28');}return util['format'](_0x140be5,_0x3d6cda[_0x9f2c('0x1d')],_0x3d6cda['headers']['x-forwarded-for']?_0x3d6cda['headers'][_0x9f2c('0x1f')]:_0x3d6cda[_0x9f2c('0x20')][_0x9f2c('0x21')]||_0x3d6cda['ip'],_0x3d6cda[_0x9f2c('0x29')],_0x1e4e1a[_0x9f2c('0x22')],_0x1e4e1a[_0x9f2c('0x23')],_0x3d6cda[_0x9f2c('0x11')]?_0x3d6cda[_0x9f2c('0x11')]['id']:null,_0x3d6cda['user']?_0x3d6cda[_0x9f2c('0x11')]['name']:null,_0x3d6cda[_0x9f2c('0x11')]?_0x3d6cda['user']['role']:null,_0x3d6cda['body']&&_0x3d6cda[_0x9f2c('0x1b')][_0x9f2c('0x26')]?_0x3d6cda[_0x9f2c('0x1b')][_0x9f2c('0x26')]:_0x9f2c('0x2a'),_0x3d6cda[_0x9f2c('0x1b')]&&_0x3d6cda['body'][_0x9f2c('0x27')]?_0x3d6cda[_0x9f2c('0x1b')][_0x9f2c('0x27')]:'',_0x3d6cda[_0x9f2c('0x1b')]&&_0x3d6cda['body']['agent_name']?_0x3d6cda[_0x9f2c('0x1b')][_0x9f2c('0x2b')]:'');},'ignoreRoute':function(_0x49b19d){var _0x427e18=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x427e18[_0x9f2c('0x2c')](_0x49b19d[_0x9f2c('0x29')]);}}));return _0x2e1cf8();});}exports[_0x9f2c('0x2d')]=setupLoggers;