89bc07418779a9d327eadeccbc658b162a519df1
[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 _0xabb9=['bold\x20magenta','bold\x20blue','addColors','/var/log/xcally','join','message','replace','{{{','}}}','format','[%s]\x20[%s]\x20%s\x20-\x20%s','YYYY-MM-DD\x20HH:mm:ss','level','toUpperCase','meta','keys','length','stringify','[%s]\x20[%s]\x20%s\x20-\x20%s\x20%s','Logger','transports','Console','File','error','consoleLogger','fileLogger','path','util','moment','debugLevel','toLowerCase','red','bold\x20yellow','bold\x20white','gray'];(function(_0x55c387,_0x25cf3d){var _0x21683d=function(_0x1a7f02){while(--_0x1a7f02){_0x55c387['push'](_0x55c387['shift']());}};_0x21683d(++_0x25cf3d);}(_0xabb9,0x83));var _0x9abb=function(_0x261067,_0x494953){_0x261067=_0x261067-0x0;var _0x58fd86=_0xabb9[_0x261067];return _0x58fd86;};'use strict';var path=require(_0x9abb('0x0'));var util=require(_0x9abb('0x1'));var moment=require(_0x9abb('0x2'));var winston=require('winston');var config=require('../config/environment');var debugLevel=config['debugLevel']?config[_0x9abb('0x3')][_0x9abb('0x4')]():'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':'redBG\x20white','error':_0x9abb('0x5'),'warn':_0x9abb('0x6'),'info':'white','print':_0x9abb('0x7'),'success':'bold\x20green','http':_0x9abb('0x8'),'verbose':_0x9abb('0x9'),'debug':_0x9abb('0xa'),'silly':'bold\x20cyan'};winston[_0x9abb('0xb')](XC_LOG_COLORS);function getLogFileName(_0x1efea3,_0x2ee726,_0x57b513){var _0x3a49dd=_0x1efea3||_0x9abb('0xc');return path[_0x9abb('0xd')](_0x3a49dd,util['format']('%s-%s.log',_0x2ee726,_0x57b513));}function formatter(_0x10a83d,_0x37be45){_0x37be45[_0x9abb('0xe')]=_0x37be45[_0x9abb('0xe')][_0x9abb('0xf')](/@@{/g,_0x9abb('0x10'))[_0x9abb('0xf')](/}@@/g,_0x9abb('0x11'))[_0x9abb('0xf')](/@{/g,'{{')[_0x9abb('0xf')](/}@/g,'}}');return util[_0x9abb('0x12')](_0x9abb('0x13'),moment()[_0x9abb('0x12')](_0x9abb('0x14')),_0x37be45[_0x9abb('0x15')][_0x9abb('0x16')](),_0x10a83d,_0x37be45['message']);}function fileFormat(_0x55a0ce,_0x43052b){_0x43052b['message']=_0x43052b[_0x9abb('0xe')]['replace'](/@@{/g,_0x9abb('0x10'))[_0x9abb('0xf')](/}@@/g,'}}}')['replace'](/@{/g,'{{')[_0x9abb('0xf')](/}@/g,'}}');var _0x114e66=_0x43052b[_0x9abb('0x17')]&&Object[_0x9abb('0x18')](_0x43052b[_0x9abb('0x17')])[_0x9abb('0x19')]?'\x0a\x09'+JSON[_0x9abb('0x1a')](_0x43052b[_0x9abb('0x17')]):'';return util[_0x9abb('0x12')](_0x9abb('0x1b'),moment()[_0x9abb('0x12')]('YYYY-MM-DD\x20HH:mm:ss'),_0x43052b[_0x9abb('0x15')][_0x9abb('0x16')](),_0x55a0ce,_0x43052b[_0x9abb('0xe')],_0x114e66);}function consoleLogger(){var _0x69084b=new winston[(_0x9abb('0x1c'))]({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0x9abb('0x1d'))][(_0x9abb('0x1e'))]({'level':'warn','json':![],'formatter':function(_0x26ecf4){return formatter('',_0x26ecf4);}})]});return _0x69084b;}function fileLogger(_0x12164b,_0x251f9e){var _0x388bf2=new winston[(_0x9abb('0x1c'))]({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0x9abb('0x1d'))][(_0x9abb('0x1f'))]({'name':util[_0x9abb('0x12')]('%s-%s',_0x12164b,_0x9abb('0x20')),'filename':getLogFileName(_0x251f9e,_0x12164b,'error'),'level':_0x9abb('0x20'),'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x1c136c){return fileFormat(_0x12164b,_0x1c136c);}}),new winston['transports'][(_0x9abb('0x1f'))]({'name':util['format']('%s-%s',_0x12164b,debugLevel),'filename':getLogFileName(_0x251f9e,_0x12164b,debugLevel),'level':debugLevel,'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x12e4dd){return fileFormat(_0x12164b,_0x12e4dd);}}),new winston[(_0x9abb('0x1d'))][(_0x9abb('0x1e'))]({'level':'warn','json':![],'formatter':function(_0x205cd0){return fileFormat(_0x12164b,_0x205cd0);}})]});return _0x388bf2;}exports[_0x9abb('0x21')]=consoleLogger;exports[_0x9abb('0x22')]=fileLogger;