367303ad716f2eafe66c5c2b10daafea14e38a0a
[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 _0xa9fd=['bold\x20cyan','addColors','/var/log/xcally','format','%s-%s.log','message','replace','{{{','}}}','[%s]\x20[%s]\x20%s\x20-\x20%s','YYYY-MM-DD\x20HH:mm:ss','meta','keys','[%s]\x20[%s]\x20%s\x20-\x20%s\x20%s','toUpperCase','Logger','transports','File','%s-%s','error','warn','fileLogger','path','util','../config/environment','debugLevel','toLowerCase','red','white','bold\x20green','gray','bold\x20blue'];(function(_0x3f1f6a,_0x6ceb8e){var _0x71afae=function(_0x48f54f){while(--_0x48f54f){_0x3f1f6a['push'](_0x3f1f6a['shift']());}};_0x71afae(++_0x6ceb8e);}(_0xa9fd,0x1d6));var _0xda9f=function(_0x15c909,_0x3fde7e){_0x15c909=_0x15c909-0x0;var _0x44523c=_0xa9fd[_0x15c909];return _0x44523c;};'use strict';var path=require(_0xda9f('0x0'));var util=require(_0xda9f('0x1'));var moment=require('moment');var winston=require('winston');var config=require(_0xda9f('0x2'));var debugLevel=config[_0xda9f('0x3')]?config[_0xda9f('0x3')][_0xda9f('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':_0xda9f('0x5'),'warn':'bold\x20yellow','info':_0xda9f('0x6'),'print':'bold\x20white','success':_0xda9f('0x7'),'http':_0xda9f('0x8'),'verbose':'bold\x20magenta','debug':_0xda9f('0x9'),'silly':_0xda9f('0xa')};winston[_0xda9f('0xb')](XC_LOG_COLORS);function getLogFileName(_0x3d8dc3,_0xb19a3a,_0x53d5b2){var _0x3e08dc=_0x3d8dc3||_0xda9f('0xc');return path['join'](_0x3e08dc,util[_0xda9f('0xd')](_0xda9f('0xe'),_0xb19a3a,_0x53d5b2));}function formatter(_0x54f63f,_0x13c3c8){_0x13c3c8[_0xda9f('0xf')]=_0x13c3c8[_0xda9f('0xf')][_0xda9f('0x10')](/@@{/g,_0xda9f('0x11'))[_0xda9f('0x10')](/}@@/g,_0xda9f('0x12'))[_0xda9f('0x10')](/@{/g,'{{')[_0xda9f('0x10')](/}@/g,'}}');return util[_0xda9f('0xd')](_0xda9f('0x13'),moment()[_0xda9f('0xd')](_0xda9f('0x14')),_0x13c3c8['level']['toUpperCase'](),_0x54f63f,_0x13c3c8['message']);}function fileFormat(_0x460bc6,_0x1167d4){_0x1167d4[_0xda9f('0xf')]=_0x1167d4[_0xda9f('0xf')][_0xda9f('0x10')](/@@{/g,'{{{')['replace'](/}@@/g,_0xda9f('0x12'))[_0xda9f('0x10')](/@{/g,'{{')['replace'](/}@/g,'}}');var _0xb172ac=_0x1167d4[_0xda9f('0x15')]&&Object[_0xda9f('0x16')](_0x1167d4[_0xda9f('0x15')])['length']?'\x0a\x09'+JSON['stringify'](_0x1167d4[_0xda9f('0x15')]):'';return util[_0xda9f('0xd')](_0xda9f('0x17'),moment()[_0xda9f('0xd')](_0xda9f('0x14')),_0x1167d4['level'][_0xda9f('0x18')](),_0x460bc6,_0x1167d4['message'],_0xb172ac);}function consoleLogger(){var _0x4ab501=new winston['Logger']({'levels':XC_LOG_LEVELS,'transports':[new winston['transports']['Console']({'level':'warn','json':![],'formatter':function(_0x40a94e){return formatter('',_0x40a94e);}})]});return _0x4ab501;}function fileLogger(_0x35cd07,_0x1b8804){var _0x335785=new winston[(_0xda9f('0x19'))]({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0xda9f('0x1a'))][(_0xda9f('0x1b'))]({'name':util['format'](_0xda9f('0x1c'),_0x35cd07,_0xda9f('0x1d')),'filename':getLogFileName(_0x1b8804,_0x35cd07,_0xda9f('0x1d')),'level':_0xda9f('0x1d'),'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x69c669){return fileFormat(_0x35cd07,_0x69c669);}}),new winston[(_0xda9f('0x1a'))]['File']({'name':util['format']('%s-%s',_0x35cd07,debugLevel),'filename':getLogFileName(_0x1b8804,_0x35cd07,debugLevel),'level':debugLevel,'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x82866e){return fileFormat(_0x35cd07,_0x82866e);}}),new winston[(_0xda9f('0x1a'))]['Console']({'level':_0xda9f('0x1e'),'json':![],'formatter':function(_0x521126){return fileFormat(_0x35cd07,_0x521126);}})]});return _0x335785;}exports['consoleLogger']=consoleLogger;exports[_0xda9f('0x1f')]=fileLogger;