94c35963fe641c8e42c0b514e90b45aaf590640c
[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 _0x25d1=['data','timestamp','api','auth','set','use','logger','body','\x20body=%s','format','method','headers','x-forwarded-for','connection','remoteAddress','url','statusCode','responseTime','role','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)','other','agent_name','setupLoggers','lodash','path','util','./loggers','./safe-template','safeTemplate','./mask-sensitive-data','maskSensitiveData','join','/var','log','xcally','client','name','user','then','no-user'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x25d1,0x6d));var _0x125d=function(_0x1e9dcc,_0x461662){_0x1e9dcc=_0x1e9dcc-0x0;var _0x49637d=_0x25d1[_0x1e9dcc];return _0x49637d;};var fs=require('fs-extra');var _=require(_0x125d('0x0'));var ewinston=require('express-winston');var path=require(_0x125d('0x1'));var util=require(_0x125d('0x2'));var fileLogger=require(_0x125d('0x3'))['fileLogger'];var safeTemplate=require(_0x125d('0x4'))[_0x125d('0x5')];var maskSensitiveData=require(_0x125d('0x6'))[_0x125d('0x7')];function ClientSideLogger(){function _0x2c5371(_0x1f9b8c){var _0x1fe204=path[_0x125d('0x8')](_0x125d('0x9'),_0x125d('0xa'),_0x125d('0xb'));var _0x473de4=path[_0x125d('0x8')](_0x125d('0xc'),_0x1f9b8c['role']+'-'+_0x1f9b8c[_0x125d('0xd')]);return fs['ensureDir'](path['join'](_0x1fe204,_0x473de4))['then'](function(){var _0x244f6b=fileLogger(_0x125d('0xc'),path[_0x125d('0x8')](_0x1fe204,_0x473de4));return _0x244f6b;})['catch'](function(_0x1a0729){throw _0x1a0729;});}this['log']=function(_0x1a6de3,_0x407607,_0x30165a,_0x620c60){return _0x2c5371(_0x1a6de3[_0x125d('0xe')])[_0x125d('0xf')](function(_0x1c0931){var _0x567a14=_0x1c0931[_0x407607];return _0x567a14;})[_0x125d('0xf')](function(_0x59e6e0){var _0x5330d8=_0x1a6de3['user']?_0x1a6de3[_0x125d('0xe')]['id']:_0x125d('0x10');var _0x35ed55=_0x620c60[_0x125d('0x11')];var _0x4c4d1d=_0x620c60[_0x125d('0x12')];var _0x18ec45=new Date(Number(_0x4c4d1d));return _0x59e6e0(_0x5330d8,_0x18ec45,_0x30165a,_0x35ed55);})['catch'](function(_0x5ae25d){fileLogger(_0x125d('0xc'))['error'](_0x5ae25d);});};}function setupLoggers(_0x4a072e){return new Promise(function(_0x21cd03){var _0x55501d=new ClientSideLogger();var _0x50b535=fileLogger(_0x125d('0x13'));var _0x5e9bf6=fileLogger(_0x125d('0x14'));_0x4a072e[_0x125d('0x15')]('client-side-logger',_0x55501d);_0x4a072e[_0x125d('0x16')](ewinston[_0x125d('0x17')]({'winstonInstance':_0x50b535,'meta':![],'statusLevels':!![],'msg':function(_0x12307f,_0x1de4ff){var _0x4ca998='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s';if(!_['isEmpty'](_0x12307f[_0x125d('0x18')])){_0x4ca998+=_0x125d('0x19');var _0xedc87c=_0x12307f[_0x125d('0x18')];maskSensitiveData(_0xedc87c);}return safeTemplate(util[_0x125d('0x1a')](_0x4ca998,_0x12307f[_0x125d('0x1b')],_0x12307f[_0x125d('0x1c')][_0x125d('0x1d')]?_0x12307f[_0x125d('0x1c')][_0x125d('0x1d')]:_0x12307f[_0x125d('0x1e')][_0x125d('0x1f')]||_0x12307f['ip'],_0x12307f[_0x125d('0x20')],_0x1de4ff[_0x125d('0x21')],_0x1de4ff[_0x125d('0x22')],_0x12307f['user']?_0x12307f[_0x125d('0xe')]['id']:null,_0x12307f[_0x125d('0xe')]?_0x12307f['user'][_0x125d('0xd')]:null,_0x12307f[_0x125d('0xe')]?_0x12307f[_0x125d('0xe')][_0x125d('0x23')]:null,_0xedc87c?util['inspect'](_0xedc87c,![],null):''));}}));_0x4a072e[_0x125d('0x16')](ewinston[_0x125d('0x17')]({'winstonInstance':_0x5e9bf6,'meta':![],'statusLevels':!![],'msg':function(_0x410036,_0x38f77d){var _0x35951f='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s';if(_0x410036[_0x125d('0x18')]&&_0x410036[_0x125d('0x18')][_0x125d('0x24')]&&_0x410036['body'][_0x125d('0x25')]){_0x35951f=_0x125d('0x26');}return util[_0x125d('0x1a')](_0x35951f,_0x410036[_0x125d('0x1b')],_0x410036['headers'][_0x125d('0x1d')]?_0x410036['headers']['x-forwarded-for']:_0x410036[_0x125d('0x1e')][_0x125d('0x1f')]||_0x410036['ip'],_0x410036['url'],_0x38f77d[_0x125d('0x21')],_0x38f77d[_0x125d('0x22')],_0x410036[_0x125d('0xe')]?_0x410036[_0x125d('0xe')]['id']:null,_0x410036[_0x125d('0xe')]?_0x410036[_0x125d('0xe')]['name']:null,_0x410036['user']?_0x410036[_0x125d('0xe')][_0x125d('0x23')]:null,_0x410036[_0x125d('0x18')]&&_0x410036[_0x125d('0x18')][_0x125d('0x24')]?_0x410036[_0x125d('0x18')][_0x125d('0x24')]:_0x125d('0x27'),_0x410036[_0x125d('0x18')]&&_0x410036['body'][_0x125d('0x25')]?_0x410036['body'][_0x125d('0x25')]:'',_0x410036[_0x125d('0x18')]&&_0x410036[_0x125d('0x18')][_0x125d('0x28')]?_0x410036[_0x125d('0x18')][_0x125d('0x28')]:'');},'ignoreRoute':function(_0x360689){var _0x1171d2=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x1171d2['test'](_0x360689[_0x125d('0x20')]);}}));return _0x21cd03();});}exports[_0x125d('0x29')]=setupLoggers;