94584940ebeccc464277ec36b756cf1b8e1a28f7
[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 _0x6b66=['inspect','use','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s','agent_id','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)','x-forwarded-for','name','device','other','agent_name','test','setupLoggers','fs-extra','lodash','express-winston','path','./loggers','fileLogger','safeTemplate','./mask-sensitive-data','maskSensitiveData','join','/var','log','xcally','client','catch','user','then','data','api','auth','set','client-side-logger','isEmpty','body','format','method','headers','connection','remoteAddress','statusCode','responseTime','role'];(function(_0x4d08b8,_0x34c445){var _0x70214a=function(_0x4db67c){while(--_0x4db67c){_0x4d08b8['push'](_0x4d08b8['shift']());}};_0x70214a(++_0x34c445);}(_0x6b66,0x16c));var _0x66b6=function(_0x118835,_0x5002cf){_0x118835=_0x118835-0x0;var _0x4f1c6a=_0x6b66[_0x118835];return _0x4f1c6a;};var fs=require(_0x66b6('0x0'));var _=require(_0x66b6('0x1'));var ewinston=require(_0x66b6('0x2'));var path=require(_0x66b6('0x3'));var util=require('util');var fileLogger=require(_0x66b6('0x4'))[_0x66b6('0x5')];var safeTemplate=require('./safe-template')[_0x66b6('0x6')];var maskSensitiveData=require(_0x66b6('0x7'))[_0x66b6('0x8')];function ClientSideLogger(){function _0x2cb5b5(_0xee85bb){var _0x45ddda=path[_0x66b6('0x9')](_0x66b6('0xa'),_0x66b6('0xb'),_0x66b6('0xc'));var _0x41e9fc=path[_0x66b6('0x9')](_0x66b6('0xd'),_0xee85bb['role']+'-'+_0xee85bb['name']);return fs['ensureDir'](path[_0x66b6('0x9')](_0x45ddda,_0x41e9fc))['then'](function(){var _0x95de60=fileLogger(_0x66b6('0xd'),path[_0x66b6('0x9')](_0x45ddda,_0x41e9fc));return _0x95de60;})[_0x66b6('0xe')](function(_0x588472){throw _0x588472;});}this[_0x66b6('0xb')]=function(_0x719834,_0x27e9eb,_0x51bcf3,_0x15bdfa){return _0x2cb5b5(_0x719834[_0x66b6('0xf')])['then'](function(_0x35a880){var _0x50443e=_0x35a880[_0x27e9eb];return _0x50443e;})[_0x66b6('0x10')](function(_0x2bfac7){var _0x315b8f=_0x719834[_0x66b6('0xf')]?_0x719834[_0x66b6('0xf')]['id']:'no-user';var _0x1b89f1=_0x15bdfa[_0x66b6('0x11')];var _0x2fc69e=_0x15bdfa['timestamp'];var _0x517d1a=new Date(Number(_0x2fc69e));return _0x2bfac7(_0x315b8f,_0x517d1a,_0x51bcf3,_0x1b89f1);})['catch'](function(_0x3750b0){fileLogger(_0x66b6('0xd'))['error'](_0x3750b0);});};}function setupLoggers(_0x908716){return new Promise(function(_0x2aaf8f){var _0x2bad6a=new ClientSideLogger();var _0x4268b7=fileLogger(_0x66b6('0x12'));var _0x4c60fb=fileLogger(_0x66b6('0x13'));_0x908716[_0x66b6('0x14')](_0x66b6('0x15'),_0x2bad6a);_0x908716['use'](ewinston['logger']({'winstonInstance':_0x4268b7,'meta':![],'statusLevels':!![],'msg':function(_0x3bf93d,_0x4ff5cc){var _0x5592='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s';if(!_[_0x66b6('0x16')](_0x3bf93d[_0x66b6('0x17')])){_0x5592+='\x20body=%s';var _0x56ae71=_0x3bf93d[_0x66b6('0x17')];maskSensitiveData(_0x56ae71);}return safeTemplate(util[_0x66b6('0x18')](_0x5592,_0x3bf93d[_0x66b6('0x19')],_0x3bf93d['headers']['x-forwarded-for']?_0x3bf93d[_0x66b6('0x1a')]['x-forwarded-for']:_0x3bf93d[_0x66b6('0x1b')][_0x66b6('0x1c')]||_0x3bf93d['ip'],_0x3bf93d['url'],_0x4ff5cc[_0x66b6('0x1d')],_0x4ff5cc[_0x66b6('0x1e')],_0x3bf93d[_0x66b6('0xf')]?_0x3bf93d[_0x66b6('0xf')]['id']:null,_0x3bf93d[_0x66b6('0xf')]?_0x3bf93d[_0x66b6('0xf')]['name']:null,_0x3bf93d['user']?_0x3bf93d['user'][_0x66b6('0x1f')]:null,_0x56ae71?util[_0x66b6('0x20')](_0x56ae71,![],null):''));}}));_0x908716[_0x66b6('0x21')](ewinston['logger']({'winstonInstance':_0x4c60fb,'meta':![],'statusLevels':!![],'msg':function(_0x2af2c4,_0x167300){var _0x70126d=_0x66b6('0x22');if(_0x2af2c4[_0x66b6('0x17')]&&_0x2af2c4[_0x66b6('0x17')]['device']&&_0x2af2c4[_0x66b6('0x17')][_0x66b6('0x23')]){_0x70126d=_0x66b6('0x24');}return util[_0x66b6('0x18')](_0x70126d,_0x2af2c4['method'],_0x2af2c4[_0x66b6('0x1a')]['x-forwarded-for']?_0x2af2c4[_0x66b6('0x1a')][_0x66b6('0x25')]:_0x2af2c4['connection']['remoteAddress']||_0x2af2c4['ip'],_0x2af2c4['url'],_0x167300[_0x66b6('0x1d')],_0x167300[_0x66b6('0x1e')],_0x2af2c4[_0x66b6('0xf')]?_0x2af2c4['user']['id']:null,_0x2af2c4[_0x66b6('0xf')]?_0x2af2c4[_0x66b6('0xf')][_0x66b6('0x26')]:null,_0x2af2c4[_0x66b6('0xf')]?_0x2af2c4[_0x66b6('0xf')][_0x66b6('0x1f')]:null,_0x2af2c4[_0x66b6('0x17')]&&_0x2af2c4['body'][_0x66b6('0x27')]?_0x2af2c4[_0x66b6('0x17')][_0x66b6('0x27')]:_0x66b6('0x28'),_0x2af2c4[_0x66b6('0x17')]&&_0x2af2c4[_0x66b6('0x17')][_0x66b6('0x23')]?_0x2af2c4[_0x66b6('0x17')][_0x66b6('0x23')]:'',_0x2af2c4[_0x66b6('0x17')]&&_0x2af2c4[_0x66b6('0x17')][_0x66b6('0x29')]?_0x2af2c4[_0x66b6('0x17')][_0x66b6('0x29')]:'');},'ignoreRoute':function(_0x80cd66){var _0x2501c9=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x2501c9[_0x66b6('0x2a')](_0x80cd66['url']);}}));return _0x2aaf8f();});}exports[_0x66b6('0x2b')]=setupLoggers;