ad28a89e8e29f06e3b38895406744b7fddf7da98
[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 _0x8f27=['bold\x20blue','/var/log/xcally','format','%s-%s.log','message','{{{','}}}','replace','YYYY-MM-DD\x20HH:mm:ss','level','meta','length','[%s]\x20[%s]\x20%s\x20-\x20%s\x20%s','toUpperCase','transports','Console','Logger','%s-%s','error','File','warn','consoleLogger','fileLogger','moment','winston','debugLevel','info','red','bold\x20yellow','white','bold\x20white','bold\x20green','bold\x20magenta'];(function(_0x3d5cd9,_0x16db35){var _0x116080=function(_0x4c80fc){while(--_0x4c80fc){_0x3d5cd9['push'](_0x3d5cd9['shift']());}};_0x116080(++_0x16db35);}(_0x8f27,0x9b));var _0x78f2=function(_0x36b444,_0x505b35){_0x36b444=_0x36b444-0x0;var _0x786323=_0x8f27[_0x36b444];return _0x786323;};'use strict';var path=require('path');var util=require('util');var moment=require(_0x78f2('0x0'));var winston=require(_0x78f2('0x1'));var config=require('../config/environment');var debugLevel=config[_0x78f2('0x2')]?config[_0x78f2('0x2')]['toLowerCase']():_0x78f2('0x3');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':_0x78f2('0x4'),'warn':_0x78f2('0x5'),'info':_0x78f2('0x6'),'print':_0x78f2('0x7'),'success':_0x78f2('0x8'),'http':'gray','verbose':_0x78f2('0x9'),'debug':_0x78f2('0xa'),'silly':'bold\x20cyan'};winston['addColors'](XC_LOG_COLORS);function getLogFileName(_0x25b764,_0x101d83,_0x36a2a9){var _0x2a2c44=_0x25b764||_0x78f2('0xb');return path['join'](_0x2a2c44,util[_0x78f2('0xc')](_0x78f2('0xd'),_0x101d83,_0x36a2a9));}function formatter(_0x4839d9,_0x15e6e7){_0x15e6e7[_0x78f2('0xe')]=_0x15e6e7[_0x78f2('0xe')]['replace'](/@@{/g,_0x78f2('0xf'))['replace'](/}@@/g,_0x78f2('0x10'))[_0x78f2('0x11')](/@{/g,'{{')[_0x78f2('0x11')](/}@/g,'}}');return util['format']('[%s]\x20[%s]\x20%s\x20-\x20%s',moment()[_0x78f2('0xc')](_0x78f2('0x12')),_0x15e6e7[_0x78f2('0x13')]['toUpperCase'](),_0x4839d9,_0x15e6e7['message']);}function fileFormat(_0x56b6bd,_0x109957){_0x109957[_0x78f2('0xe')]=_0x109957[_0x78f2('0xe')][_0x78f2('0x11')](/@@{/g,_0x78f2('0xf'))['replace'](/}@@/g,'}}}')[_0x78f2('0x11')](/@{/g,'{{')[_0x78f2('0x11')](/}@/g,'}}');var _0x4a5be0=_0x109957['meta']&&Object['keys'](_0x109957[_0x78f2('0x14')])[_0x78f2('0x15')]?'\x0a\x09'+JSON['stringify'](_0x109957[_0x78f2('0x14')]):'';return util[_0x78f2('0xc')](_0x78f2('0x16'),moment()['format'](_0x78f2('0x12')),_0x109957[_0x78f2('0x13')][_0x78f2('0x17')](),_0x56b6bd,_0x109957[_0x78f2('0xe')],_0x4a5be0);}function consoleLogger(){var _0x14c76d=new winston['Logger']({'levels':XC_LOG_LEVELS,'transports':[new winston[(_0x78f2('0x18'))][(_0x78f2('0x19'))]({'level':'warn','json':![],'formatter':function(_0x41fa2f){return formatter('',_0x41fa2f);}})]});return _0x14c76d;}function fileLogger(_0x3ba9c9,_0x3cc542){var _0x35e178=new winston[(_0x78f2('0x1a'))]({'levels':XC_LOG_LEVELS,'transports':[new winston['transports']['File']({'name':util['format'](_0x78f2('0x1b'),_0x3ba9c9,'error'),'filename':getLogFileName(_0x3cc542,_0x3ba9c9,_0x78f2('0x1c')),'level':_0x78f2('0x1c'),'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x1bd6e2){return fileFormat(_0x3ba9c9,_0x1bd6e2);}}),new winston[(_0x78f2('0x18'))][(_0x78f2('0x1d'))]({'name':util[_0x78f2('0xc')](_0x78f2('0x1b'),_0x3ba9c9,debugLevel),'filename':getLogFileName(_0x3cc542,_0x3ba9c9,debugLevel),'level':debugLevel,'json':![],'maxsize':0xa00000,'maxFiles':0xa,'tailable':!![],'formatter':function(_0x4702eb){return fileFormat(_0x3ba9c9,_0x4702eb);}}),new winston['transports'][(_0x78f2('0x19'))]({'level':_0x78f2('0x1e'),'json':![],'formatter':function(_0x32b9ec){return fileFormat(_0x3ba9c9,_0x32b9ec);}})]});return _0x35e178;}exports[_0x78f2('0x1f')]=consoleLogger;exports[_0x78f2('0x20')]=fileLogger;