45300768bb4fc32aad9d144c8e7e5ee7bcd68d77
[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 _0xfcfb=['xcally','client','then','catch','user','no-user','data','timestamp','set','client-side-logger','logger','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s','\x20body=%s','format','method','headers','x-forwarded-for','connection','remoteAddress','statusCode','responseTime','name','role','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s','body','url','other','agent_id','agent_name','fs-extra','express-winston','path','./loggers','fileLogger','./safe-template','safeTemplate','maskSensitiveData','join','/var'];(function(_0x2f12c8,_0x2de21f){var _0x33831d=function(_0x851233){while(--_0x851233){_0x2f12c8['push'](_0x2f12c8['shift']());}};_0x33831d(++_0x2de21f);}(_0xfcfb,0x1f1));var _0xbfcf=function(_0x53e297,_0x53189b){_0x53e297=_0x53e297-0x0;var _0x4380ff=_0xfcfb[_0x53e297];return _0x4380ff;};var fs=require(_0xbfcf('0x0'));var _=require('lodash');var ewinston=require(_0xbfcf('0x1'));var path=require(_0xbfcf('0x2'));var util=require('util');var fileLogger=require(_0xbfcf('0x3'))[_0xbfcf('0x4')];var safeTemplate=require(_0xbfcf('0x5'))[_0xbfcf('0x6')];var maskSensitiveData=require('./mask-sensitive-data')[_0xbfcf('0x7')];function ClientSideLogger(){function _0x5204fe(_0x858bc1){var _0x2bb4c0=path[_0xbfcf('0x8')](_0xbfcf('0x9'),'log',_0xbfcf('0xa'));var _0x345bcb=path[_0xbfcf('0x8')](_0xbfcf('0xb'),_0x858bc1['role']+'-'+_0x858bc1['name']);return fs['ensureDir'](path[_0xbfcf('0x8')](_0x2bb4c0,_0x345bcb))[_0xbfcf('0xc')](function(){var _0x3c1012=fileLogger(_0xbfcf('0xb'),path[_0xbfcf('0x8')](_0x2bb4c0,_0x345bcb));return _0x3c1012;})[_0xbfcf('0xd')](function(_0x257ba1){throw _0x257ba1;});}this['log']=function(_0x561170,_0x2d64ee,_0x381bbd,_0x3a11d4){return _0x5204fe(_0x561170[_0xbfcf('0xe')])['then'](function(_0x288d42){var _0x41e5d4=_0x288d42[_0x2d64ee];return _0x41e5d4;})[_0xbfcf('0xc')](function(_0x39a6c9){var _0x8c1cc1=_0x561170[_0xbfcf('0xe')]?_0x561170[_0xbfcf('0xe')]['id']:_0xbfcf('0xf');var _0x5a2ebc=_0x3a11d4[_0xbfcf('0x10')];var _0x179bec=_0x3a11d4[_0xbfcf('0x11')];var _0x255904=new Date(Number(_0x179bec));return _0x39a6c9(_0x8c1cc1,_0x255904,_0x381bbd,_0x5a2ebc);})[_0xbfcf('0xd')](function(_0x826829){fileLogger('client')['error'](_0x826829);});};}function setupLoggers(_0x2a622c){return new Promise(function(_0x166d3c){var _0x51a9d7=new ClientSideLogger();var _0x4e41a9=fileLogger('api');var _0x48a8bb=fileLogger('auth');_0x2a622c[_0xbfcf('0x12')](_0xbfcf('0x13'),_0x51a9d7);_0x2a622c['use'](ewinston[_0xbfcf('0x14')]({'winstonInstance':_0x4e41a9,'meta':![],'statusLevels':!![],'msg':function(_0x1f8c07,_0x4c151d){var _0x2cd364=_0xbfcf('0x15');if(!_['isEmpty'](_0x1f8c07['body'])){_0x2cd364+=_0xbfcf('0x16');var _0x418c1a=_0x1f8c07['body'];maskSensitiveData(_0x418c1a);}return safeTemplate(util[_0xbfcf('0x17')](_0x2cd364,_0x1f8c07[_0xbfcf('0x18')],_0x1f8c07[_0xbfcf('0x19')][_0xbfcf('0x1a')]?_0x1f8c07[_0xbfcf('0x19')][_0xbfcf('0x1a')]:_0x1f8c07[_0xbfcf('0x1b')][_0xbfcf('0x1c')]||_0x1f8c07['ip'],_0x1f8c07['url'],_0x4c151d[_0xbfcf('0x1d')],_0x4c151d[_0xbfcf('0x1e')],_0x1f8c07[_0xbfcf('0xe')]?_0x1f8c07['user']['id']:null,_0x1f8c07[_0xbfcf('0xe')]?_0x1f8c07[_0xbfcf('0xe')][_0xbfcf('0x1f')]:null,_0x1f8c07['user']?_0x1f8c07[_0xbfcf('0xe')][_0xbfcf('0x20')]:null,_0x418c1a?util['inspect'](_0x418c1a,![],null):''));}}));_0x2a622c['use'](ewinston[_0xbfcf('0x14')]({'winstonInstance':_0x48a8bb,'meta':![],'statusLevels':!![],'msg':function(_0x323580,_0x2f56de){var _0x34d0ea=_0xbfcf('0x21');if(_0x323580[_0xbfcf('0x22')]&&_0x323580['body']['device']&&_0x323580[_0xbfcf('0x22')]['agent_id']){_0x34d0ea='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)';}return util[_0xbfcf('0x17')](_0x34d0ea,_0x323580[_0xbfcf('0x18')],_0x323580['headers'][_0xbfcf('0x1a')]?_0x323580['headers'][_0xbfcf('0x1a')]:_0x323580[_0xbfcf('0x1b')][_0xbfcf('0x1c')]||_0x323580['ip'],_0x323580[_0xbfcf('0x23')],_0x2f56de[_0xbfcf('0x1d')],_0x2f56de[_0xbfcf('0x1e')],_0x323580['user']?_0x323580[_0xbfcf('0xe')]['id']:null,_0x323580[_0xbfcf('0xe')]?_0x323580[_0xbfcf('0xe')]['name']:null,_0x323580[_0xbfcf('0xe')]?_0x323580['user']['role']:null,_0x323580[_0xbfcf('0x22')]&&_0x323580[_0xbfcf('0x22')]['device']?_0x323580[_0xbfcf('0x22')]['device']:_0xbfcf('0x24'),_0x323580['body']&&_0x323580[_0xbfcf('0x22')][_0xbfcf('0x25')]?_0x323580['body'][_0xbfcf('0x25')]:'',_0x323580['body']&&_0x323580[_0xbfcf('0x22')][_0xbfcf('0x26')]?_0x323580[_0xbfcf('0x22')][_0xbfcf('0x26')]:'');},'ignoreRoute':function(_0x3c723f){var _0x3bff61=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x3bff61['test'](_0x3c723f[_0xbfcf('0x23')]);}}));return _0x166d3c();});}exports['setupLoggers']=setupLoggers;