155490b44dcc2f43685bca27e9b46edbcb84e735
[motion2.git] / server / utils / loggers.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 _0x095c=['[%s]\x20[%s]\x20%s\x20-\x20%s','YYYY-MM-DD\x20HH:mm:ss','toUpperCase','message','{{{','meta','keys','length','stringify','Logger','transports','Console','warn','File','%s-%s','error','consoleLogger','fileLogger','path','util','winston','../config/environment','debugLevel','redBG\x20white','red','bold\x20yellow','white','bold\x20white','bold\x20green','gray','bold\x20magenta','bold\x20blue','bold\x20cyan','addColors','/var/log/xcally','join','format','%s-%s.log','replace','}}}'];(function(_0x49d848,_0x28871c){var _0x4309a7=function(_0xf70d01){while(--_0xf70d01){_0x49d848['push'](_0x49d848['shift']());}};_0x4309a7(++_0x28871c);}(_0x095c,0x8a));var _0xc095=function(_0x7fa92b,_0x31d3aa){_0x7fa92b=_0x7fa92b-0x0;var _0x258325=_0x095c[_0x7fa92b];return _0x258325;};'use strict';var path=require(_0xc095('0x0'));var util=require(_0xc095('0x1'));var moment=require('moment');var winston=require(_0xc095('0x2'));var config=require(_0xc095('0x3'));var debugLevel=config[_0xc095('0x4')]?config[_0xc095('0x4')]['toLowerCase']():'info';var XC_LOG_LEVELS={'fatal':0x0,'error':0x0,'warn':0x1,'info':0x2,'print':0x2,'success':0x2,'http':0x3,'verbose':0x4,'debug':0x5,'silly':0x6};var XC_LOG_COLORS={'fatal':_0xc095('0x5'),'error':_0xc095('0x6'),'warn':_0xc095('0x7'),'info':_0xc095('0x8'),'print':_0xc095('0x9'),'success':_0xc095('0xa'),'http':_0xc095('0xb'),'verbose':_0xc095('0xc'),'debug':_0xc095('0xd'),'silly':_0xc095('0xe')};winston[_0xc095('0xf')](XC_LOG_COLORS);function getLogFileName(_0x13877e,_0xe0085f,_0x5dee14){var _0x2c5736=_0x13877e||_0xc095('0x10');return path[_0xc095('0x11')](_0x2c5736,util[_0xc095('0x12')](_0xc095('0x13'),_0xe0085f,_0x5dee14));}function formatter(_0x1770ec,_0x472f3a){_0x472f3a['message']=_0x472f3a['message'][_0xc095('0x14')](/@@{/g,'{{{')[_0xc095('0x14')](/}@@/g,_0xc095('0x15'))['replace'](/@{/g,'{{')['replace'](/}@/g,'}}');return util[_0xc095('0x12')](_0xc095('0x16'),moment()[_0xc095('0x12')](_0xc095('0x17')),_0x472f3a['level'][_0xc095('0x18')](),_0x1770ec,_0x472f3a[_0xc095('0x19')]);}function fileFormat(_0x29bd70,_0x5807f9){_0x5807f9[_0xc095('0x19')]=_0x5807f9[_0xc095('0x19')]['replace'](/@@{/g,_0xc095('0x1a'))[_0xc095('0x14')](/}@@/g,_0xc095('0x15'))[_0xc095('0x14')](/@{/g,'{{')[_0xc095('0x14')](/}@/g,'}}');var _0x5ac8e2=_0x5807f9[_0xc095('0x1b')]&&Object[_0xc095('0x1c')](_0x5807f9['meta'])[_0xc095('0x1d')]?'\x0a\x09'+JSON[_0xc095('0x1e')](_0x5807f9[_0xc095('0x1b')]):'';return util[_0xc095('0x12')]('[%s]\x20[%s]\x20%s\x20-\x20%s\x20%s',moment()[_0xc095('0x12')]('YYYY-MM-DD\x20HH:mm:ss'),_0x5807f9['level'][_0xc095('0x18')](),_0x29bd70,_0x5807f9[_0xc095('0x19')],_0x5ac8e2);}function consoleLogger(){var _0x47129c=new winston[(_0xc095('0x1f'))]({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0xc095('0x20'))][(_0xc095('0x21'))]({'level':_0xc095('0x22'),'json':![],'formatter':function(_0x44e076){return formatter('',_0x44e076);}})]});return _0x47129c;}function fileLogger(_0x4e7cb2,_0x10ffd5){var _0x309137=new winston['Logger']({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0xc095('0x20'))][(_0xc095('0x23'))]({'name':util[_0xc095('0x12')](_0xc095('0x24'),_0x4e7cb2,'error'),'filename':getLogFileName(_0x10ffd5,_0x4e7cb2,'error'),'level':_0xc095('0x25'),'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x205b9c){return fileFormat(_0x4e7cb2,_0x205b9c);}}),new winston[(_0xc095('0x20'))][(_0xc095('0x23'))]({'name':util[_0xc095('0x12')](_0xc095('0x24'),_0x4e7cb2,debugLevel),'filename':getLogFileName(_0x10ffd5,_0x4e7cb2,debugLevel),'level':debugLevel,'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x335cab){return fileFormat(_0x4e7cb2,_0x335cab);}}),new winston[(_0xc095('0x20'))][(_0xc095('0x21'))]({'level':_0xc095('0x22'),'json':![],'formatter':function(_0xbeecbc){return fileFormat(_0x4e7cb2,_0xbeecbc);}})]});return _0x309137;}exports[_0xc095('0x26')]=consoleLogger;exports[_0xc095('0x27')]=fileLogger;