43a067eb52f4e6c03ae9a3328f5fc158f7c962fe
[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 _0x48b0=['meta','keys','length','stringify','[%s]\x20[%s]\x20%s\x20-\x20%s\x20%s','Console','warn','Logger','transports','error','File','fileLogger','path','../config/environment','debugLevel','toLowerCase','info','redBG\x20white','white','bold\x20white','bold\x20green','gray','bold\x20magenta','bold\x20blue','bold\x20cyan','addColors','/var/log/xcally','join','format','%s-%s.log','message','replace','{{{','}}}','[%s]\x20[%s]\x20%s\x20-\x20%s','YYYY-MM-DD\x20HH:mm:ss','level','toUpperCase'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x48b0,0xf0));var _0x048b=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x48b0[_0x321bb2];return _0x9c12ed;};'use strict';var path=require(_0x048b('0x0'));var util=require('util');var moment=require('moment');var winston=require('winston');var config=require(_0x048b('0x1'));var debugLevel=config[_0x048b('0x2')]?config[_0x048b('0x2')][_0x048b('0x3')]():_0x048b('0x4');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':_0x048b('0x5'),'error':'red','warn':'bold\x20yellow','info':_0x048b('0x6'),'print':_0x048b('0x7'),'success':_0x048b('0x8'),'http':_0x048b('0x9'),'verbose':_0x048b('0xa'),'debug':_0x048b('0xb'),'silly':_0x048b('0xc')};winston[_0x048b('0xd')](XC_LOG_COLORS);function getLogFileName(_0xac94b9,_0x19c48e,_0x4fb453){var _0xbfef47=_0xac94b9||_0x048b('0xe');return path[_0x048b('0xf')](_0xbfef47,util[_0x048b('0x10')](_0x048b('0x11'),_0x19c48e,_0x4fb453));}function formatter(_0x7ff51e,_0x154084){_0x154084[_0x048b('0x12')]=_0x154084[_0x048b('0x12')][_0x048b('0x13')](/@@{/g,_0x048b('0x14'))['replace'](/}@@/g,_0x048b('0x15'))[_0x048b('0x13')](/@{/g,'{{')[_0x048b('0x13')](/}@/g,'}}');return util[_0x048b('0x10')](_0x048b('0x16'),moment()[_0x048b('0x10')](_0x048b('0x17')),_0x154084[_0x048b('0x18')][_0x048b('0x19')](),_0x7ff51e,_0x154084[_0x048b('0x12')]);}function fileFormat(_0x3c5a66,_0x347b75){_0x347b75[_0x048b('0x12')]=_0x347b75['message']['replace'](/@@{/g,_0x048b('0x14'))[_0x048b('0x13')](/}@@/g,_0x048b('0x15'))[_0x048b('0x13')](/@{/g,'{{')[_0x048b('0x13')](/}@/g,'}}');var _0x471107=_0x347b75[_0x048b('0x1a')]&&Object[_0x048b('0x1b')](_0x347b75['meta'])[_0x048b('0x1c')]?'\x0a\x09'+JSON[_0x048b('0x1d')](_0x347b75[_0x048b('0x1a')]):'';return util['format'](_0x048b('0x1e'),moment()[_0x048b('0x10')](_0x048b('0x17')),_0x347b75[_0x048b('0x18')][_0x048b('0x19')](),_0x3c5a66,_0x347b75[_0x048b('0x12')],_0x471107);}function consoleLogger(){var _0x1dbee0=new winston['Logger']({'levels':XC_LOG_LEVELS,'transports':[new winston['transports'][(_0x048b('0x1f'))]({'level':_0x048b('0x20'),'json':![],'formatter':function(_0x454421){return formatter('',_0x454421);}})]});return _0x1dbee0;}function fileLogger(_0x17f27f,_0x2aa73f){var _0x437d0c=new winston[(_0x048b('0x21'))]({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0x048b('0x22'))]['File']({'name':util[_0x048b('0x10')]('%s-%s',_0x17f27f,_0x048b('0x23')),'filename':getLogFileName(_0x2aa73f,_0x17f27f,_0x048b('0x23')),'level':_0x048b('0x23'),'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x1a2e5c){return fileFormat(_0x17f27f,_0x1a2e5c);}}),new winston[(_0x048b('0x22'))][(_0x048b('0x24'))]({'name':util[_0x048b('0x10')]('%s-%s',_0x17f27f,debugLevel),'filename':getLogFileName(_0x2aa73f,_0x17f27f,debugLevel),'level':debugLevel,'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x3a0f20){return fileFormat(_0x17f27f,_0x3a0f20);}}),new winston['transports'][(_0x048b('0x1f'))]({'level':_0x048b('0x20'),'json':![],'formatter':function(_0xc55fcd){return fileFormat(_0x17f27f,_0xc55fcd);}})]});return _0x437d0c;}exports['consoleLogger']=consoleLogger;exports[_0x048b('0x25')]=fileLogger;