b914f8d679dc5bcc1480065eceb6e55555d7d5c2
[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 _0x2433=['Logger','transports','%s-%s','error','warn','fileLogger','path','util','winston','debugLevel','toLowerCase','info','redBG\x20white','bold\x20yellow','bold\x20white','bold\x20green','gray','bold\x20magenta','bold\x20cyan','addColors','join','format','%s-%s.log','message','replace','{{{','}}}','[%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'];(function(_0x2b1a65,_0x54be9a){var _0x2c1475=function(_0x57bc08){while(--_0x57bc08){_0x2b1a65['push'](_0x2b1a65['shift']());}};_0x2c1475(++_0x54be9a);}(_0x2433,0xde));var _0x3243=function(_0x576a47,_0x421ea6){_0x576a47=_0x576a47-0x0;var _0x24a79e=_0x2433[_0x576a47];return _0x24a79e;};'use strict';var path=require(_0x3243('0x0'));var util=require(_0x3243('0x1'));var moment=require('moment');var winston=require(_0x3243('0x2'));var config=require('../config/environment');var debugLevel=config['debugLevel']?config[_0x3243('0x3')][_0x3243('0x4')]():_0x3243('0x5');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':_0x3243('0x6'),'error':'red','warn':_0x3243('0x7'),'info':'white','print':_0x3243('0x8'),'success':_0x3243('0x9'),'http':_0x3243('0xa'),'verbose':_0x3243('0xb'),'debug':'bold\x20blue','silly':_0x3243('0xc')};winston[_0x3243('0xd')](XC_LOG_COLORS);function getLogFileName(_0x550464,_0x40de66,_0x4927a6){var _0x2c0e41=_0x550464||'/var/log/xcally';return path[_0x3243('0xe')](_0x2c0e41,util[_0x3243('0xf')](_0x3243('0x10'),_0x40de66,_0x4927a6));}function formatter(_0x179c37,_0x4a3e14){_0x4a3e14[_0x3243('0x11')]=_0x4a3e14[_0x3243('0x11')][_0x3243('0x12')](/@@{/g,_0x3243('0x13'))['replace'](/}@@/g,_0x3243('0x14'))['replace'](/@{/g,'{{')[_0x3243('0x12')](/}@/g,'}}');return util['format'](_0x3243('0x15'),moment()[_0x3243('0xf')](_0x3243('0x16')),_0x4a3e14[_0x3243('0x17')][_0x3243('0x18')](),_0x179c37,_0x4a3e14[_0x3243('0x11')]);}function fileFormat(_0x1815e5,_0x22d1c3){_0x22d1c3[_0x3243('0x11')]=_0x22d1c3[_0x3243('0x11')][_0x3243('0x12')](/@@{/g,_0x3243('0x13'))[_0x3243('0x12')](/}@@/g,_0x3243('0x14'))['replace'](/@{/g,'{{')[_0x3243('0x12')](/}@/g,'}}');var _0x3b9a66=_0x22d1c3[_0x3243('0x19')]&&Object[_0x3243('0x1a')](_0x22d1c3[_0x3243('0x19')])[_0x3243('0x1b')]?'\x0a\x09'+JSON[_0x3243('0x1c')](_0x22d1c3[_0x3243('0x19')]):'';return util[_0x3243('0xf')](_0x3243('0x1d'),moment()[_0x3243('0xf')](_0x3243('0x16')),_0x22d1c3['level'][_0x3243('0x18')](),_0x1815e5,_0x22d1c3['message'],_0x3b9a66);}function consoleLogger(){var _0x541953=new winston[(_0x3243('0x1e'))]({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0x3243('0x1f'))]['Console']({'level':'warn','json':![],'formatter':function(_0x3aff3c){return formatter('',_0x3aff3c);}})]});return _0x541953;}function fileLogger(_0x28f917,_0x1bdaa2){var _0x364cd7=new winston[(_0x3243('0x1e'))]({'levels':XC_LOG_LEVELS,'transports':[new winston['transports']['File']({'name':util[_0x3243('0xf')](_0x3243('0x20'),_0x28f917,_0x3243('0x21')),'filename':getLogFileName(_0x1bdaa2,_0x28f917,'error'),'level':'error','json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x3d8b19){return fileFormat(_0x28f917,_0x3d8b19);}}),new winston[(_0x3243('0x1f'))]['File']({'name':util[_0x3243('0xf')](_0x3243('0x20'),_0x28f917,debugLevel),'filename':getLogFileName(_0x1bdaa2,_0x28f917,debugLevel),'level':debugLevel,'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x4fc21b){return fileFormat(_0x28f917,_0x4fc21b);}}),new winston[(_0x3243('0x1f'))]['Console']({'level':_0x3243('0x22'),'json':![],'formatter':function(_0x53fb18){return fileFormat(_0x28f917,_0x53fb18);}})]});return _0x364cd7;}exports['consoleLogger']=consoleLogger;exports[_0x3243('0x23')]=fileLogger;