Built motion from commit e6806ed6.|2.6.0
[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 _0xf85b=['role','name','ensureDir','then','catch','user','timestamp','error','api','auth','use','logger','isEmpty','body','\x20body=%s','format','method','headers','x-forwarded-for','url','statusCode','%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)','connection','remoteAddress','responseTime','other','agent_name','test','setupLoggers','fs-extra','lodash','path','util','fileLogger','./safe-template','join','/var','log','client'];(function(_0x43edf6,_0x4e5fe){var _0x5d813a=function(_0x55b08a){while(--_0x55b08a){_0x43edf6['push'](_0x43edf6['shift']());}};_0x5d813a(++_0x4e5fe);}(_0xf85b,0xf2));var _0xbf85=function(_0x564308,_0x3eb3bd){_0x564308=_0x564308-0x0;var _0x5a9cae=_0xf85b[_0x564308];return _0x5a9cae;};var fs=require(_0xbf85('0x0'));var _=require(_0xbf85('0x1'));var ewinston=require('express-winston');var path=require(_0xbf85('0x2'));var util=require(_0xbf85('0x3'));var fileLogger=require('./loggers')[_0xbf85('0x4')];var safeTemplate=require(_0xbf85('0x5'))['safeTemplate'];var maskSensitiveData=require('./mask-sensitive-data')['maskSensitiveData'];function ClientSideLogger(){function _0x30d866(_0x8a2b02){var _0x24d87d=path[_0xbf85('0x6')](_0xbf85('0x7'),_0xbf85('0x8'),'xcally');var _0x58bd8b=path[_0xbf85('0x6')](_0xbf85('0x9'),_0x8a2b02[_0xbf85('0xa')]+'-'+_0x8a2b02[_0xbf85('0xb')]);return fs[_0xbf85('0xc')](path['join'](_0x24d87d,_0x58bd8b))[_0xbf85('0xd')](function(){var _0x58f087=fileLogger('client',path[_0xbf85('0x6')](_0x24d87d,_0x58bd8b));return _0x58f087;})[_0xbf85('0xe')](function(_0x4821a1){throw _0x4821a1;});}this[_0xbf85('0x8')]=function(_0x11bb34,_0x45914b,_0x11eb64,_0x39da65){return _0x30d866(_0x11bb34[_0xbf85('0xf')])['then'](function(_0x2513df){var _0x26942c=_0x2513df[_0x45914b];return _0x26942c;})[_0xbf85('0xd')](function(_0x402bc5){var _0x599c72=_0x11bb34[_0xbf85('0xf')]?_0x11bb34['user']['id']:'no-user';var _0xdcd620=_0x39da65['data'];var _0x5aa863=_0x39da65[_0xbf85('0x10')];var _0x507fe4=new Date(Number(_0x5aa863));return _0x402bc5(_0x599c72,_0x507fe4,_0x11eb64,_0xdcd620);})[_0xbf85('0xe')](function(_0x38e844){fileLogger(_0xbf85('0x9'))[_0xbf85('0x11')](_0x38e844);});};}function setupLoggers(_0x37ef3d){return new Promise(function(_0xe8feaa){var _0x230bb9=new ClientSideLogger();var _0x4813be=fileLogger(_0xbf85('0x12'));var _0x32063e=fileLogger(_0xbf85('0x13'));_0x37ef3d['set']('client-side-logger',_0x230bb9);_0x37ef3d[_0xbf85('0x14')](ewinston[_0xbf85('0x15')]({'winstonInstance':_0x4813be,'meta':![],'statusLevels':!![],'msg':function(_0x59aa32,_0x59c38a){var _0x3c8353='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s';if(!_[_0xbf85('0x16')](_0x59aa32[_0xbf85('0x17')])){_0x3c8353+=_0xbf85('0x18');var _0x250db8=_0x59aa32[_0xbf85('0x17')];maskSensitiveData(_0x250db8);}return safeTemplate(util[_0xbf85('0x19')](_0x3c8353,_0x59aa32[_0xbf85('0x1a')],_0x59aa32[_0xbf85('0x1b')]['x-forwarded-for']?_0x59aa32[_0xbf85('0x1b')][_0xbf85('0x1c')]:_0x59aa32['connection']['remoteAddress']||_0x59aa32['ip'],_0x59aa32[_0xbf85('0x1d')],_0x59c38a[_0xbf85('0x1e')],_0x59c38a['responseTime'],_0x59aa32[_0xbf85('0xf')]?_0x59aa32['user']['id']:null,_0x59aa32[_0xbf85('0xf')]?_0x59aa32[_0xbf85('0xf')][_0xbf85('0xb')]:null,_0x59aa32['user']?_0x59aa32[_0xbf85('0xf')]['role']:null,_0x250db8?util['inspect'](_0x250db8,![],null):''));}}));_0x37ef3d[_0xbf85('0x14')](ewinston[_0xbf85('0x15')]({'winstonInstance':_0x32063e,'meta':![],'statusLevels':!![],'msg':function(_0x16991a,_0xcf96d7){var _0x1ea468=_0xbf85('0x1f');if(_0x16991a[_0xbf85('0x17')]&&_0x16991a[_0xbf85('0x17')][_0xbf85('0x20')]&&_0x16991a[_0xbf85('0x17')][_0xbf85('0x21')]){_0x1ea468=_0xbf85('0x22');}return util[_0xbf85('0x19')](_0x1ea468,_0x16991a['method'],_0x16991a['headers'][_0xbf85('0x1c')]?_0x16991a['headers'][_0xbf85('0x1c')]:_0x16991a[_0xbf85('0x23')][_0xbf85('0x24')]||_0x16991a['ip'],_0x16991a[_0xbf85('0x1d')],_0xcf96d7[_0xbf85('0x1e')],_0xcf96d7[_0xbf85('0x25')],_0x16991a['user']?_0x16991a[_0xbf85('0xf')]['id']:null,_0x16991a[_0xbf85('0xf')]?_0x16991a['user']['name']:null,_0x16991a['user']?_0x16991a[_0xbf85('0xf')][_0xbf85('0xa')]:null,_0x16991a[_0xbf85('0x17')]&&_0x16991a[_0xbf85('0x17')][_0xbf85('0x20')]?_0x16991a[_0xbf85('0x17')][_0xbf85('0x20')]:_0xbf85('0x26'),_0x16991a[_0xbf85('0x17')]&&_0x16991a[_0xbf85('0x17')][_0xbf85('0x21')]?_0x16991a['body']['agent_id']:'',_0x16991a['body']&&_0x16991a[_0xbf85('0x17')][_0xbf85('0x27')]?_0x16991a['body'][_0xbf85('0x27')]:'');},'ignoreRoute':function(_0x5ea02a){var _0x80c2ee=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x80c2ee[_0xbf85('0x28')](_0x5ea02a[_0xbf85('0x1d')]);}}));return _0xe8feaa();});}exports[_0xbf85('0x29')]=setupLoggers;