bfa8347e2eb30783d898fa526546842a0216597e
[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 _0x2279=['user','no-user','data','error','auth','set','use','logger','isEmpty','\x20body=%s','body','format','headers','x-forwarded-for','connection','remoteAddress','url','statusCode','responseTime','inspect','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s','device','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)','method','agent_id','agent_name','test','fs-extra','lodash','express-winston','util','fileLogger','./safe-template','./mask-sensitive-data','/var','log','role','name','join','then','client','catch'];(function(_0x292ec5,_0x3f879f){var _0x436db9=function(_0x20d249){while(--_0x20d249){_0x292ec5['push'](_0x292ec5['shift']());}};_0x436db9(++_0x3f879f);}(_0x2279,0x1bf));var _0x9227=function(_0x562adf,_0x1f2f85){_0x562adf=_0x562adf-0x0;var _0x87c18e=_0x2279[_0x562adf];return _0x87c18e;};var fs=require(_0x9227('0x0'));var _=require(_0x9227('0x1'));var ewinston=require(_0x9227('0x2'));var path=require('path');var util=require(_0x9227('0x3'));var fileLogger=require('./loggers')[_0x9227('0x4')];var safeTemplate=require(_0x9227('0x5'))['safeTemplate'];var maskSensitiveData=require(_0x9227('0x6'))['maskSensitiveData'];function ClientSideLogger(){function _0x4a94cd(_0x1314ef){var _0x298a6e=path['join'](_0x9227('0x7'),_0x9227('0x8'),'xcally');var _0x54ead9=path['join']('client',_0x1314ef[_0x9227('0x9')]+'-'+_0x1314ef[_0x9227('0xa')]);return fs['ensureDir'](path[_0x9227('0xb')](_0x298a6e,_0x54ead9))[_0x9227('0xc')](function(){var _0x5ea284=fileLogger(_0x9227('0xd'),path[_0x9227('0xb')](_0x298a6e,_0x54ead9));return _0x5ea284;})[_0x9227('0xe')](function(_0x4214e4){throw _0x4214e4;});}this[_0x9227('0x8')]=function(_0xcc509,_0x2e16f0,_0x5ee3df,_0x4d8d45){return _0x4a94cd(_0xcc509[_0x9227('0xf')])[_0x9227('0xc')](function(_0x425645){var _0x29fc37=_0x425645[_0x2e16f0];return _0x29fc37;})[_0x9227('0xc')](function(_0x45b958){var _0x33718f=_0xcc509[_0x9227('0xf')]?_0xcc509[_0x9227('0xf')]['id']:_0x9227('0x10');var _0x518f30=_0x4d8d45[_0x9227('0x11')];var _0x5473c1=_0x4d8d45['timestamp'];var _0x2d788b=new Date(Number(_0x5473c1));return _0x45b958(_0x33718f,_0x2d788b,_0x5ee3df,_0x518f30);})['catch'](function(_0x1782c3){fileLogger(_0x9227('0xd'))[_0x9227('0x12')](_0x1782c3);});};}function setupLoggers(_0x552778){return new Promise(function(_0x583e69){var _0x9a992e=new ClientSideLogger();var _0x52567e=fileLogger('api');var _0x324495=fileLogger(_0x9227('0x13'));_0x552778[_0x9227('0x14')]('client-side-logger',_0x9a992e);_0x552778[_0x9227('0x15')](ewinston[_0x9227('0x16')]({'winstonInstance':_0x52567e,'meta':![],'statusLevels':!![],'msg':function(_0x56d29e,_0x35b227){var _0x1c2a72='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s';if(!_[_0x9227('0x17')](_0x56d29e['body'])){_0x1c2a72+=_0x9227('0x18');var _0x596bf0=_0x56d29e[_0x9227('0x19')];maskSensitiveData(_0x596bf0);}return safeTemplate(util[_0x9227('0x1a')](_0x1c2a72,_0x56d29e['method'],_0x56d29e[_0x9227('0x1b')]['x-forwarded-for']?_0x56d29e[_0x9227('0x1b')][_0x9227('0x1c')]:_0x56d29e[_0x9227('0x1d')][_0x9227('0x1e')]||_0x56d29e['ip'],_0x56d29e[_0x9227('0x1f')],_0x35b227[_0x9227('0x20')],_0x35b227[_0x9227('0x21')],_0x56d29e['user']?_0x56d29e['user']['id']:null,_0x56d29e[_0x9227('0xf')]?_0x56d29e[_0x9227('0xf')][_0x9227('0xa')]:null,_0x56d29e['user']?_0x56d29e['user'][_0x9227('0x9')]:null,_0x596bf0?util[_0x9227('0x22')](_0x596bf0,![],null):''));}}));_0x552778['use'](ewinston['logger']({'winstonInstance':_0x324495,'meta':![],'statusLevels':!![],'msg':function(_0x1f0cb0,_0x323e51){var _0xe626be=_0x9227('0x23');if(_0x1f0cb0[_0x9227('0x19')]&&_0x1f0cb0[_0x9227('0x19')][_0x9227('0x24')]&&_0x1f0cb0[_0x9227('0x19')]['agent_id']){_0xe626be=_0x9227('0x25');}return util[_0x9227('0x1a')](_0xe626be,_0x1f0cb0[_0x9227('0x26')],_0x1f0cb0[_0x9227('0x1b')][_0x9227('0x1c')]?_0x1f0cb0[_0x9227('0x1b')][_0x9227('0x1c')]:_0x1f0cb0[_0x9227('0x1d')]['remoteAddress']||_0x1f0cb0['ip'],_0x1f0cb0['url'],_0x323e51[_0x9227('0x20')],_0x323e51[_0x9227('0x21')],_0x1f0cb0['user']?_0x1f0cb0[_0x9227('0xf')]['id']:null,_0x1f0cb0[_0x9227('0xf')]?_0x1f0cb0[_0x9227('0xf')][_0x9227('0xa')]:null,_0x1f0cb0['user']?_0x1f0cb0[_0x9227('0xf')][_0x9227('0x9')]:null,_0x1f0cb0[_0x9227('0x19')]&&_0x1f0cb0['body'][_0x9227('0x24')]?_0x1f0cb0[_0x9227('0x19')][_0x9227('0x24')]:'other',_0x1f0cb0[_0x9227('0x19')]&&_0x1f0cb0[_0x9227('0x19')][_0x9227('0x27')]?_0x1f0cb0[_0x9227('0x19')]['agent_id']:'',_0x1f0cb0[_0x9227('0x19')]&&_0x1f0cb0[_0x9227('0x19')][_0x9227('0x28')]?_0x1f0cb0[_0x9227('0x19')][_0x9227('0x28')]:'');},'ignoreRoute':function(_0x22cf87){var _0x429c5b=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x429c5b[_0x9227('0x29')](_0x22cf87['url']);}}));return _0x583e69();});}exports['setupLoggers']=setupLoggers;