399d9944a72f20d15551518075ab5605b6b671eb
[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 _0x98f6=['%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s','device','agent_id','test','setupLoggers','fs-extra','util','./loggers','./safe-template','./mask-sensitive-data','maskSensitiveData','join','log','xcally','client','role','ensureDir','then','catch','user','no-user','data','error','api','auth','set','use','logger','%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','remoteAddress','url','statusCode','responseTime'];(function(_0x326a63,_0x12d847){var _0xae56f8=function(_0xd860f8){while(--_0xd860f8){_0x326a63['push'](_0x326a63['shift']());}};_0xae56f8(++_0x12d847);}(_0x98f6,0xd2));var _0x698f=function(_0x467cb0,_0x303070){_0x467cb0=_0x467cb0-0x0;var _0x2153f7=_0x98f6[_0x467cb0];return _0x2153f7;};var fs=require(_0x698f('0x0'));var _=require('lodash');var ewinston=require('express-winston');var path=require('path');var util=require(_0x698f('0x1'));var fileLogger=require(_0x698f('0x2'))['fileLogger'];var safeTemplate=require(_0x698f('0x3'))['safeTemplate'];var maskSensitiveData=require(_0x698f('0x4'))[_0x698f('0x5')];function ClientSideLogger(){function _0x3d8bd8(_0x37defd){var _0x55e3fe=path[_0x698f('0x6')]('/var',_0x698f('0x7'),_0x698f('0x8'));var _0x171c56=path[_0x698f('0x6')](_0x698f('0x9'),_0x37defd[_0x698f('0xa')]+'-'+_0x37defd['name']);return fs[_0x698f('0xb')](path[_0x698f('0x6')](_0x55e3fe,_0x171c56))[_0x698f('0xc')](function(){var _0x13759f=fileLogger(_0x698f('0x9'),path[_0x698f('0x6')](_0x55e3fe,_0x171c56));return _0x13759f;})[_0x698f('0xd')](function(_0x159aa8){throw _0x159aa8;});}this['log']=function(_0x5ec182,_0x4e2e00,_0x3d8e68,_0x5ad43d){return _0x3d8bd8(_0x5ec182['user'])['then'](function(_0x179a50){var _0x43ff4b=_0x179a50[_0x4e2e00];return _0x43ff4b;})[_0x698f('0xc')](function(_0x385b69){var _0x51720a=_0x5ec182[_0x698f('0xe')]?_0x5ec182['user']['id']:_0x698f('0xf');var _0x588b9f=_0x5ad43d[_0x698f('0x10')];var _0x348de6=_0x5ad43d['timestamp'];var _0x1d06ed=new Date(Number(_0x348de6));return _0x385b69(_0x51720a,_0x1d06ed,_0x3d8e68,_0x588b9f);})['catch'](function(_0x40f00f){fileLogger('client')[_0x698f('0x11')](_0x40f00f);});};}function setupLoggers(_0x2aba14){return new Promise(function(_0xe92df0){var _0x4c3ff1=new ClientSideLogger();var _0x563a71=fileLogger(_0x698f('0x12'));var _0x31d4ae=fileLogger(_0x698f('0x13'));_0x2aba14[_0x698f('0x14')]('client-side-logger',_0x4c3ff1);_0x2aba14[_0x698f('0x15')](ewinston[_0x698f('0x16')]({'winstonInstance':_0x563a71,'meta':![],'statusLevels':!![],'msg':function(_0x572b9d,_0x2d7d47){var _0x3e97ae=_0x698f('0x17');if(!_[_0x698f('0x18')](_0x572b9d[_0x698f('0x19')])){_0x3e97ae+=_0x698f('0x1a');var _0x16b816=_0x572b9d[_0x698f('0x19')];maskSensitiveData(_0x16b816);}return safeTemplate(util[_0x698f('0x1b')](_0x3e97ae,_0x572b9d[_0x698f('0x1c')],_0x572b9d[_0x698f('0x1d')][_0x698f('0x1e')]?_0x572b9d[_0x698f('0x1d')]['x-forwarded-for']:_0x572b9d[_0x698f('0x1f')][_0x698f('0x20')]||_0x572b9d['ip'],_0x572b9d[_0x698f('0x21')],_0x2d7d47[_0x698f('0x22')],_0x2d7d47[_0x698f('0x23')],_0x572b9d[_0x698f('0xe')]?_0x572b9d[_0x698f('0xe')]['id']:null,_0x572b9d[_0x698f('0xe')]?_0x572b9d[_0x698f('0xe')]['name']:null,_0x572b9d[_0x698f('0xe')]?_0x572b9d['user'][_0x698f('0xa')]:null,_0x16b816?util['inspect'](_0x16b816,![],null):''));}}));_0x2aba14[_0x698f('0x15')](ewinston['logger']({'winstonInstance':_0x31d4ae,'meta':![],'statusLevels':!![],'msg':function(_0x42f36c,_0x26154a){var _0x44e959=_0x698f('0x24');if(_0x42f36c[_0x698f('0x19')]&&_0x42f36c[_0x698f('0x19')][_0x698f('0x25')]&&_0x42f36c[_0x698f('0x19')][_0x698f('0x26')]){_0x44e959='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)';}return util[_0x698f('0x1b')](_0x44e959,_0x42f36c[_0x698f('0x1c')],_0x42f36c[_0x698f('0x1d')][_0x698f('0x1e')]?_0x42f36c['headers'][_0x698f('0x1e')]:_0x42f36c[_0x698f('0x1f')][_0x698f('0x20')]||_0x42f36c['ip'],_0x42f36c[_0x698f('0x21')],_0x26154a[_0x698f('0x22')],_0x26154a[_0x698f('0x23')],_0x42f36c[_0x698f('0xe')]?_0x42f36c[_0x698f('0xe')]['id']:null,_0x42f36c[_0x698f('0xe')]?_0x42f36c['user']['name']:null,_0x42f36c['user']?_0x42f36c[_0x698f('0xe')][_0x698f('0xa')]:null,_0x42f36c[_0x698f('0x19')]&&_0x42f36c['body'][_0x698f('0x25')]?_0x42f36c['body'][_0x698f('0x25')]:'other',_0x42f36c[_0x698f('0x19')]&&_0x42f36c[_0x698f('0x19')][_0x698f('0x26')]?_0x42f36c[_0x698f('0x19')][_0x698f('0x26')]:'',_0x42f36c[_0x698f('0x19')]&&_0x42f36c['body']['agent_name']?_0x42f36c[_0x698f('0x19')]['agent_name']:'');},'ignoreRoute':function(_0x4e0933){var _0x38778f=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x38778f[_0x698f('0x27')](_0x4e0933[_0x698f('0x21')]);}}));return _0xe92df0();});}exports[_0x698f('0x28')]=setupLoggers;