Built motion from commit 06eb8eb0.|2.6.31
[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 _0xf9c4=['body','\x20body=%s','format','x-forwarded-for','headers','connection','url','statusCode','responseTime','role','inspect','%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s','device','agent_id','agent_name','test','setupLoggers','fs-extra','lodash','express-winston','./safe-template','./mask-sensitive-data','maskSensitiveData','/var','xcally','join','client','name','ensureDir','then','catch','log','user','no-user','data','timestamp','api','set','client-side-logger','use','isEmpty'];(function(_0x3846b6,_0x192ca1){var _0x39ba59=function(_0x95f850){while(--_0x95f850){_0x3846b6['push'](_0x3846b6['shift']());}};_0x39ba59(++_0x192ca1);}(_0xf9c4,0x159));var _0x4f9c=function(_0x1ae491,_0x5b83b9){_0x1ae491=_0x1ae491-0x0;var _0x4958a5=_0xf9c4[_0x1ae491];return _0x4958a5;};var fs=require(_0x4f9c('0x0'));var _=require(_0x4f9c('0x1'));var ewinston=require(_0x4f9c('0x2'));var path=require('path');var util=require('util');var fileLogger=require('./loggers')['fileLogger'];var safeTemplate=require(_0x4f9c('0x3'))['safeTemplate'];var maskSensitiveData=require(_0x4f9c('0x4'))[_0x4f9c('0x5')];function ClientSideLogger(){function _0x12aaa3(_0x70501){var _0x16f2ef=path['join'](_0x4f9c('0x6'),'log',_0x4f9c('0x7'));var _0xf6594d=path[_0x4f9c('0x8')](_0x4f9c('0x9'),_0x70501['role']+'-'+_0x70501[_0x4f9c('0xa')]);return fs[_0x4f9c('0xb')](path['join'](_0x16f2ef,_0xf6594d))[_0x4f9c('0xc')](function(){var _0x43190f=fileLogger(_0x4f9c('0x9'),path[_0x4f9c('0x8')](_0x16f2ef,_0xf6594d));return _0x43190f;})[_0x4f9c('0xd')](function(_0x4c82ee){throw _0x4c82ee;});}this[_0x4f9c('0xe')]=function(_0x5c408a,_0x5ccda8,_0x1fdcc6,_0x2cdf52){return _0x12aaa3(_0x5c408a[_0x4f9c('0xf')])[_0x4f9c('0xc')](function(_0x393a88){var _0x1db01b=_0x393a88[_0x5ccda8];return _0x1db01b;})[_0x4f9c('0xc')](function(_0xddb3){var _0x5113cd=_0x5c408a[_0x4f9c('0xf')]?_0x5c408a['user']['id']:_0x4f9c('0x10');var _0x486203=_0x2cdf52[_0x4f9c('0x11')];var _0x300c0a=_0x2cdf52[_0x4f9c('0x12')];var _0x23e75e=new Date(Number(_0x300c0a));return _0xddb3(_0x5113cd,_0x23e75e,_0x1fdcc6,_0x486203);})[_0x4f9c('0xd')](function(_0xf3e5ce){fileLogger(_0x4f9c('0x9'))['error'](_0xf3e5ce);});};}function setupLoggers(_0x1ef03a){return new Promise(function(_0x3173d1){var _0x1cd993=new ClientSideLogger();var _0x18b58a=fileLogger(_0x4f9c('0x13'));var _0x2f27c8=fileLogger('auth');_0x1ef03a[_0x4f9c('0x14')](_0x4f9c('0x15'),_0x1cd993);_0x1ef03a[_0x4f9c('0x16')](ewinston['logger']({'winstonInstance':_0x18b58a,'meta':![],'statusLevels':!![],'msg':function(_0x3bf440,_0x2a0ed8){var _0x3cd62d='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s';if(!_[_0x4f9c('0x17')](_0x3bf440[_0x4f9c('0x18')])){_0x3cd62d+=_0x4f9c('0x19');var _0x27da7a=_0x3bf440[_0x4f9c('0x18')];maskSensitiveData(_0x27da7a);}return safeTemplate(util[_0x4f9c('0x1a')](_0x3cd62d,_0x3bf440['method'],_0x3bf440['headers'][_0x4f9c('0x1b')]?_0x3bf440[_0x4f9c('0x1c')][_0x4f9c('0x1b')]:_0x3bf440[_0x4f9c('0x1d')]['remoteAddress']||_0x3bf440['ip'],_0x3bf440[_0x4f9c('0x1e')],_0x2a0ed8[_0x4f9c('0x1f')],_0x2a0ed8[_0x4f9c('0x20')],_0x3bf440[_0x4f9c('0xf')]?_0x3bf440[_0x4f9c('0xf')]['id']:null,_0x3bf440[_0x4f9c('0xf')]?_0x3bf440[_0x4f9c('0xf')][_0x4f9c('0xa')]:null,_0x3bf440[_0x4f9c('0xf')]?_0x3bf440[_0x4f9c('0xf')][_0x4f9c('0x21')]:null,_0x27da7a?util[_0x4f9c('0x22')](_0x27da7a,![],null):''));}}));_0x1ef03a['use'](ewinston['logger']({'winstonInstance':_0x2f27c8,'meta':![],'statusLevels':!![],'msg':function(_0x4fb4a7,_0x3b8900){var _0x325cf3=_0x4f9c('0x23');if(_0x4fb4a7[_0x4f9c('0x18')]&&_0x4fb4a7[_0x4f9c('0x18')][_0x4f9c('0x24')]&&_0x4fb4a7[_0x4f9c('0x18')]['agent_id']){_0x325cf3='%s\x20%s\x20%s\x20%s\x20%sms\x20id=%s\x20name=%s\x20role=%s\x20device=%s\x20(id=%s\x20name=%s)';}return util[_0x4f9c('0x1a')](_0x325cf3,_0x4fb4a7['method'],_0x4fb4a7[_0x4f9c('0x1c')][_0x4f9c('0x1b')]?_0x4fb4a7[_0x4f9c('0x1c')][_0x4f9c('0x1b')]:_0x4fb4a7[_0x4f9c('0x1d')]['remoteAddress']||_0x4fb4a7['ip'],_0x4fb4a7[_0x4f9c('0x1e')],_0x3b8900[_0x4f9c('0x1f')],_0x3b8900[_0x4f9c('0x20')],_0x4fb4a7[_0x4f9c('0xf')]?_0x4fb4a7['user']['id']:null,_0x4fb4a7['user']?_0x4fb4a7[_0x4f9c('0xf')][_0x4f9c('0xa')]:null,_0x4fb4a7[_0x4f9c('0xf')]?_0x4fb4a7['user'][_0x4f9c('0x21')]:null,_0x4fb4a7[_0x4f9c('0x18')]&&_0x4fb4a7['body'][_0x4f9c('0x24')]?_0x4fb4a7[_0x4f9c('0x18')]['device']:'other',_0x4fb4a7[_0x4f9c('0x18')]&&_0x4fb4a7[_0x4f9c('0x18')]['agent_id']?_0x4fb4a7[_0x4f9c('0x18')][_0x4f9c('0x25')]:'',_0x4fb4a7[_0x4f9c('0x18')]&&_0x4fb4a7[_0x4f9c('0x18')]['agent_name']?_0x4fb4a7[_0x4f9c('0x18')][_0x4f9c('0x26')]:'');},'ignoreRoute':function(_0x34fd02){var _0x29ab8d=/\/api\/users\/[0-9]+\/(login|logout)/gi;return!_0x29ab8d[_0x4f9c('0x27')](_0x34fd02[_0x4f9c('0x1e')]);}}));return _0x3173d1();});}exports[_0x4f9c('0x28')]=setupLoggers;