From 77ca236854bc20e81a1fa2658291775978b40352 Mon Sep 17 00:00:00 2001
From: appu <apparao@vtiger.com>
Date: Mon, 13 Nov 2023 17:53:00 +0530
Subject: [PATCH] Feature::Vtiger Logger enabled using MonoLog library

---
 SendSupportNotification.php                   |   2 +-
 composer.json                                 |   3 +-
 composer.lock                                 | 181 ++++++++++++++++--
 config.performance.php                        |   4 +-
 cron/SendReminder.service                     |   2 +-
 .../SalesOrder/RecurringInvoice.service       |   2 +-
 data/Tracker.php                              |   2 +-
 include/database/PearDatabase.php             |   9 +-
 include/logging.php                           |  13 +-
 include/utils/export.php                      |   2 +-
 libraries/log4php/Logger.php                  | 136 -------------
 .../log4php/LoggerPropertyConfigurator.php    |  65 -------
 modules/Accounts/Accounts.php                 |   2 +-
 modules/Calendar/Activity.php                 |   2 +-
 modules/Campaigns/Campaigns.php               |   2 +-
 modules/Contacts/Contacts.php                 |   2 +-
 modules/CustomView/ListViewTop.php            |   2 +-
 modules/Documents/Documents.php               |   2 +-
 modules/Emails/Emails.php                     |   4 +-
 modules/Faq/Faq.php                           |   2 +-
 modules/HelpDesk/HelpDesk.php                 |   2 +-
 modules/Invoice/Invoice.php                   |   2 +-
 modules/Leads/Leads.php                       |   2 +-
 modules/Potentials/Potentials.php             |   2 +-
 modules/PriceBooks/PriceBooks.php             |   2 +-
 modules/Products/Products.php                 |   2 +-
 modules/PurchaseOrder/PurchaseOrder.php       |   2 +-
 modules/Quotes/Quotes.php                     |   2 +-
 modules/Reports/ReportSharing.php             |   2 +-
 modules/Reports/ReportType.php                |   2 +-
 modules/SalesOrder/SalesOrder.php             |   2 +-
 modules/Users/DefaultDataPopulator.php        |   2 +-
 modules/Users/Users.php                       |   2 +-
 modules/Vendors/Vendors.php                   |   2 +-
 modules/Vtiger/helpers/VtigerLogger.php       |  54 ++++++
 modules/Vtiger/layout_utils.php               |   2 +-
 webservice.php                                |   4 +-
 37 files changed, 265 insertions(+), 262 deletions(-)
 delete mode 100644 libraries/log4php/Logger.php
 delete mode 100644 libraries/log4php/LoggerPropertyConfigurator.php
 create mode 100644 modules/Vtiger/helpers/VtigerLogger.php

diff --git a/SendSupportNotification.php b/SendSupportNotification.php
index 17c81cd4b..8a63053e9 100755
--- a/SendSupportNotification.php
+++ b/SendSupportNotification.php
@@ -28,7 +28,7 @@ require("config.php");
 global $adb;
 global $log;
 global $HELPDESK_SUPPORT_EMAIL_ID,$HELPDESK_SUPPORT_NAME;
-$log = Logger::getLogger('SendSupportNotification');
+$log = VtigerLogger::getLogger('SendSupportNotification');
 $log->debug(" invoked SendSupportNotification ");
 
 // retrieve the translated strings.
diff --git a/composer.json b/composer.json
index 0cd484e95..4419cf785 100644
--- a/composer.json
+++ b/composer.json
@@ -21,6 +21,7 @@
         "smarty/smarty": "^4.3",
         "dg/rss-php": "^1.5",
         "ezyang/htmlpurifier": "^4.16",
-        "tecnickcom/tcpdf": "^6.6"
+        "tecnickcom/tcpdf": "^6.6",
+	"monolog/monolog": "*"
     }
 }
diff --git a/composer.lock b/composer.lock
index b410d4ae6..ca4fd136e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "74af97ed9d563a7f2dd29a31b422cbe4",
+    "content-hash": "563a46ac454caaa7dd7892948d7538b7",
     "packages": [
         {
             "name": "dg/rss-php",
@@ -113,18 +113,169 @@
             },
             "time": "2022-09-18T07:06:19+00:00"
         },
+        {
+            "name": "monolog/monolog",
+            "version": "3.5.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/Seldaek/monolog.git",
+                "reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/c915e2634718dbc8a4a15c61b0e62e7a44e14448",
+                "reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=8.1",
+                "psr/log": "^2.0 || ^3.0"
+            },
+            "provide": {
+                "psr/log-implementation": "3.0.0"
+            },
+            "require-dev": {
+                "aws/aws-sdk-php": "^3.0",
+                "doctrine/couchdb": "~1.0@dev",
+                "elasticsearch/elasticsearch": "^7 || ^8",
+                "ext-json": "*",
+                "graylog2/gelf-php": "^1.4.2 || ^2.0",
+                "guzzlehttp/guzzle": "^7.4.5",
+                "guzzlehttp/psr7": "^2.2",
+                "mongodb/mongodb": "^1.8",
+                "php-amqplib/php-amqplib": "~2.4 || ^3",
+                "phpstan/phpstan": "^1.9",
+                "phpstan/phpstan-deprecation-rules": "^1.0",
+                "phpstan/phpstan-strict-rules": "^1.4",
+                "phpunit/phpunit": "^10.1",
+                "predis/predis": "^1.1 || ^2",
+                "ruflin/elastica": "^7",
+                "symfony/mailer": "^5.4 || ^6",
+                "symfony/mime": "^5.4 || ^6"
+            },
+            "suggest": {
+                "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
+                "doctrine/couchdb": "Allow sending log messages to a CouchDB server",
+                "elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client",
+                "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
+                "ext-curl": "Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler",
+                "ext-mbstring": "Allow to work properly with unicode symbols",
+                "ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)",
+                "ext-openssl": "Required to send log messages using SSL",
+                "ext-sockets": "Allow sending log messages to a Syslog server (via UDP driver)",
+                "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
+                "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)",
+                "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
+                "rollbar/rollbar": "Allow sending log messages to Rollbar",
+                "ruflin/elastica": "Allow sending log messages to an Elastic Search server"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-main": "3.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Monolog\\": "src/Monolog"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jordi Boggiano",
+                    "email": "j.boggiano@seld.be",
+                    "homepage": "https://seld.be"
+                }
+            ],
+            "description": "Sends your logs to files, sockets, inboxes, databases and various web services",
+            "homepage": "https://github.com/Seldaek/monolog",
+            "keywords": [
+                "log",
+                "logging",
+                "psr-3"
+            ],
+            "support": {
+                "issues": "https://github.com/Seldaek/monolog/issues",
+                "source": "https://github.com/Seldaek/monolog/tree/3.5.0"
+            },
+            "funding": [
+                {
+                    "url": "https://github.com/Seldaek",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/monolog/monolog",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2023-10-27T15:32:31+00:00"
+        },
+        {
+            "name": "psr/log",
+            "version": "3.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-fig/log.git",
+                "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001",
+                "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=8.0.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Psr\\Log\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "PHP-FIG",
+                    "homepage": "https://www.php-fig.org/"
+                }
+            ],
+            "description": "Common interface for logging libraries",
+            "homepage": "https://github.com/php-fig/log",
+            "keywords": [
+                "log",
+                "psr",
+                "psr-3"
+            ],
+            "support": {
+                "source": "https://github.com/php-fig/log/tree/3.0.0"
+            },
+            "time": "2021-07-14T16:46:02+00:00"
+        },
         {
             "name": "smarty/smarty",
-            "version": "v4.3.2",
+            "version": "v4.3.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/smarty-php/smarty.git",
-                "reference": "1d9cda2be34fd6edb74924684260636fd0b89288"
+                "reference": "3931d8f54b8f7a4ffab538582d34d4397ba8daa5"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/1d9cda2be34fd6edb74924684260636fd0b89288",
-                "reference": "1d9cda2be34fd6edb74924684260636fd0b89288",
+                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/3931d8f54b8f7a4ffab538582d34d4397ba8daa5",
+                "reference": "3931d8f54b8f7a4ffab538582d34d4397ba8daa5",
                 "shasum": ""
             },
             "require": {
@@ -175,22 +326,22 @@
             "support": {
                 "forum": "https://github.com/smarty-php/smarty/discussions",
                 "issues": "https://github.com/smarty-php/smarty/issues",
-                "source": "https://github.com/smarty-php/smarty/tree/v4.3.2"
+                "source": "https://github.com/smarty-php/smarty/tree/v4.3.4"
             },
-            "time": "2023-07-19T10:27:36+00:00"
+            "time": "2023-09-14T10:59:08+00:00"
         },
         {
             "name": "tecnickcom/tcpdf",
-            "version": "6.6.2",
+            "version": "6.6.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/tecnickcom/TCPDF.git",
-                "reference": "e3cffc9bcbc76e89e167e9eb0bbda0cab7518459"
+                "reference": "5fce932fcee4371865314ab7f6c0d85423c5c7ce"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/e3cffc9bcbc76e89e167e9eb0bbda0cab7518459",
-                "reference": "e3cffc9bcbc76e89e167e9eb0bbda0cab7518459",
+                "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/5fce932fcee4371865314ab7f6c0d85423c5c7ce",
+                "reference": "5fce932fcee4371865314ab7f6c0d85423c5c7ce",
                 "shasum": ""
             },
             "require": {
@@ -219,7 +370,7 @@
             },
             "notification-url": "https://packagist.org/downloads/",
             "license": [
-                "LGPL-3.0-only"
+                "LGPL-3.0-or-later"
             ],
             "authors": [
                 {
@@ -241,7 +392,7 @@
             ],
             "support": {
                 "issues": "https://github.com/tecnickcom/TCPDF/issues",
-                "source": "https://github.com/tecnickcom/TCPDF/tree/6.6.2"
+                "source": "https://github.com/tecnickcom/TCPDF/tree/6.6.5"
             },
             "funding": [
                 {
@@ -249,7 +400,7 @@
                     "type": "custom"
                 }
             ],
-            "time": "2022-12-17T10:28:59+00:00"
+            "time": "2023-09-06T15:09:26+00:00"
         }
     ],
     "packages-dev": [],
@@ -265,5 +416,5 @@
         "ext-curl": "*"
     },
     "platform-dev": [],
-    "plugin-api-version": "2.2.0"
+    "plugin-api-version": "2.3.0"
 }
diff --git a/config.performance.php b/config.performance.php
index d40db3411..66fd8a695 100644
--- a/config.performance.php
+++ b/config.performance.php
@@ -9,8 +9,8 @@
  ************************************************************************************/
 /* Performance paramters can be configured to fine tune vtiger CRM runtime */
 $PERFORMANCE_CONFIG = Array(
-	// Enable log4php debugging only if requried 
-	'LOG4PHP_DEBUG' => false,
+	// Enable Vtiger Log Level for debugging only if requried 
+	'LOGLEVEl_DEBUG' => true,
 
 	// Should the caller information be captured in SQL Logging?
 	// It adds little overhead for performance but will be useful to debug
diff --git a/cron/SendReminder.service b/cron/SendReminder.service
index 70d5e538b..48263e29a 100644
--- a/cron/SendReminder.service
+++ b/cron/SendReminder.service
@@ -42,7 +42,7 @@ if(empty($from)) {
 global $adb;
 global $log;
 global $site_URL;
-$log =Logger::getLogger('SendReminder');
+$log =VtigerLogger::getLogger('SendReminder');
 $log->debug(" invoked SendReminder ");
 
 // retrieve the translated strings.
diff --git a/cron/modules/SalesOrder/RecurringInvoice.service b/cron/modules/SalesOrder/RecurringInvoice.service
index c36a70574..17a824a29 100644
--- a/cron/modules/SalesOrder/RecurringInvoice.service
+++ b/cron/modules/SalesOrder/RecurringInvoice.service
@@ -12,7 +12,7 @@ require_once('include/utils/utils.php');
 require_once('include/logging.php');
 
 global $adb, $log;
-$log = Logger::getLogger('RecurringInvoice');
+$log = VtigerLogger::getLogger('RecurringInvoice');
 $log->debug("invoked RecurringInvoice");
 
 $currentDate = date('Y-m-d');
diff --git a/data/Tracker.php b/data/Tracker.php
index 7c59b6e75..fd52d9d4d 100755
--- a/data/Tracker.php
+++ b/data/Tracker.php
@@ -46,7 +46,7 @@ class Tracker {
     );
 	function __construct()
     {
-        $this->log = Logger::getLogger('Tracker');
+        $this->log = VtigerLogger::getLogger('Tracker');
 		// $this->db = PearDatabase::getInstance();
 		global $adb;
         $this->db = $adb;
diff --git a/include/database/PearDatabase.php b/include/database/PearDatabase.php
index 755a14386..1f8275333 100644
--- a/include/database/PearDatabase.php
+++ b/include/database/PearDatabase.php
@@ -16,8 +16,8 @@
 require_once 'include/logging.php';
 require_once 'libraries/adodb_vtigerfix/adodb.inc.php';
 
-$log = Logger::getLogger('VT');
-$logsqltm = Logger::getLogger('SQLTIME');
+$log = VtigerLogger::getLogger('VT');
+$logsqltm = VtigerLogger::getLogger('SQLTIME');
 
 // Callback class useful to convert PreparedStatement Question Marks to SQL value
 // See function convertPS2Sql in PearDatabase below
@@ -113,8 +113,7 @@ class PearDatabase{
 
     function println($msg)
     {
-		require_once('include/logging.php');
-		$log1 = Logger::getLogger('VT');
+		$log1 = VtigerLogger::getLogger('VT');
 		if(is_array($msg)) {
 		    $log1->info("PearDatabse ->".print_r($msg,true));
 		} else {
@@ -858,7 +857,7 @@ class PearDatabase{
 	 */
     function __construct($dbtype='',$host='',$dbname='',$username='',$passwd='') {
 		global $currentModule;
-		$this->log = Logger::getLogger('PearDatabase_'. $currentModule);
+		$this->log = VtigerLogger::getLogger('PearDatabase_'. $currentModule);
 		$this->resetSettings($dbtype,$host,$dbname,$username,$passwd);
 
 		// Initialize performance parameters
diff --git a/include/logging.php b/include/logging.php
index 709b85c32..1e3e3e9d0 100644
--- a/include/logging.php
+++ b/include/logging.php
@@ -21,16 +21,15 @@ require_once('config.php');
 
 // Performance Optimization: Configure the log folder
 @include_once('config.performance.php');
+require_once 'modules/Vtiger/helpers/VtigerLogger.php';
+
 global $PERFORMANCE_CONFIG;
-if(isset($PERFORMANCE_CONFIG) && isset($PERFORMANCE_CONFIG['LOG4PHP_DEBUG']) && $PERFORMANCE_CONFIG['LOG4PHP_DEBUG']) {
-        define('LOG4PHP_DIR', 'libraries/log4php');
+if(isset($PERFORMANCE_CONFIG) && isset($PERFORMANCE_CONFIG['LOGLEVEl_DEBUG']) && $PERFORMANCE_CONFIG['LOGLEVEl_DEBUG']) {
+    VtigerLogger::$filePath = "logs/vtigercrm.log"; // Default log file path.
+    VtigerLogger::$logLevel = 100; // Default debug level defined in Monolog.
 } else {
-        define('LOG4PHP_DIR', 'libraries/log4php');
+    VtigerLogger::$logLevel = 0;
 }
 // END
 
-define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true);
-require_once(LOG4PHP_DIR.'/Logger.php');
-Logger::configure('log4php.properties');
-
 ?>
diff --git a/include/utils/export.php b/include/utils/export.php
index d4c6b7456..66bc892af 100755
--- a/include/utils/export.php
+++ b/include/utils/export.php
@@ -107,7 +107,7 @@ function export($type){
 		// Refer to the logic in setting $currentModule in index.php
 		$focus = CRMEntity::getInstance($type);
     }
-    $log = Logger::getLogger('export_'.$type);
+    $log = VtigerLogger::getLogger('export_'.$type);
     $db = PearDatabase::getInstance();
 
 	$oCustomView = new CustomView("$type");
diff --git a/libraries/log4php/Logger.php b/libraries/log4php/Logger.php
deleted file mode 100644
index c50568a59..000000000
--- a/libraries/log4php/Logger.php
+++ /dev/null
@@ -1,136 +0,0 @@
-<?php
-/*+***********************************************************************************
- * The contents of this file are subject to the vtiger CRM Public License Version 1.0
- * ("License"); You may not use this file except in compliance with the License
- * The Original Code is:  vtiger CRM Open Source
- * The Initial Developer of the Original Code is vtiger.
- * Portions created by vtiger are Copyright (C) vtiger.
- * All Rights Reserved.
- *************************************************************************************/
-
-/** Classes to avoid logging */
-include_once dirname(__FILE__) . '/LoggerPropertyConfigurator.php';
-
-/**
- * Core logging class.
- */
-class Logger {
-	private $name = false;
-	private $appender = false;
-	private $configinfo = false;
-	
-	/**
-	 * Writing log file information could cost in-terms of performance.
-	 * Enable logging based on the levels here explicitly
-	 */
-	private $enableLogLevel =  array(	
-		'ERROR' => false,
-		'FATAL' => false,
-		'INFO'  => false,
-		'WARN'  => false,
-		'DEBUG' => false,
-	);
-	
-	function __construct($name, $configinfo = false) {
-		$this->name = $name;
-		$this->configinfo = $configinfo;
-		
-		/** For migration log-level we need debug turned-on */
-		if(strtoupper($name) == 'MIGRATION') {
-			$this->enableLogLevel['DEBUG'] = true;
-		}
-		
-	}
-	
-	function emit($level, $message) {
-		if(!$this->appender) {
-			$filename = 'logs/vtigercrm.log';			
-			if($this->configinfo && isset($this->configinfo['appender']['File'])) {
-				$filename = $this->configinfo['appender']['File'];
-			}
-			$this->appender = new LoggerAppenderFile($filename, 0777); 
-		}
-		$mypid = @getmypid();
-		
-		$this->appender->emit("$level [$mypid] $this->name - ", $message);
-	}
-	
-	function info($message) {
-		if($this->isLevelEnabled('INFO')) {
-			$this->emit('INFO', $message);
-		}
-	}
-	
-	function debug($message) {
-		if($this->isDebugEnabled()) {
-			$this->emit('DEBUG', $message);
-		}
-	}
-	
-	function warn($message) {
-		if($this->isLevelEnabled('WARN')) {
-			$this->emit('WARN', $message);
-		}
-	}
-	
-	function fatal($message) {
-		if($this->isLevelEnabled('FATAL')) {
-			$this->emit('FATAL', $message);
-		}		
-	}
-	
-	function error($message) {
-		if($this->isLevelEnabled('ERROR')) {
-			$this->emit('ERROR', $message);
-		}
-	}
-	
-	function isLevelEnabled($level) {
-		if($this->enableLogLevel[$level] && $this->configinfo) {
-			return (strtoupper($this->configinfo['level']) == $level);
-		}
-		return false;
-	}
-	
-	function isDebugEnabled() {
-		return $this->isLevelEnabled('DEBUG');
-	}
-        
-        static function getlogger($name = 'ROOT') {
-		$configinfo = LoggerPropertyConfigurator::getInstance()->getConfigInfo($name);
-		return new Logger($name, $configinfo);
-	}
-
-	static function configure($config) {
-		// Do nothing
-	}
-}
-
-/**
- * Log message appender to file.
- */
-class LoggerAppenderFile {
-	
-	private $filename;
-	private $chmod;
-	
-	function __construct($filename, $chmod = 0222) {
-		$this->filename = $filename;
-		$this->chmod    = $chmod;
-	}
-	
-	function emit($prefix, $message) {		
-		if($this->chmod != 0777 && file_exists($this->filename)) {
-			if(is_readable($this->filename)) {
-				@chmod($this->filename, $this->chmod);
-			}
-		}
-		$fh = @fopen($this->filename, 'a');
-		if($fh) {
-			@fwrite($fh, date('m/d/Y H:i:s') . " $prefix $message\n");
-			@fclose($fh);
-		}
-	}	
-	
-}
-?>
diff --git a/libraries/log4php/LoggerPropertyConfigurator.php b/libraries/log4php/LoggerPropertyConfigurator.php
deleted file mode 100644
index 8969499ad..000000000
--- a/libraries/log4php/LoggerPropertyConfigurator.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-/*+***********************************************************************************
- * The contents of this file are subject to the vtiger CRM Public License Version 1.0
- * ("License"); You may not use this file except in compliance with the License
- * The Original Code is:  vtiger CRM Open Source
- * The Initial Developer of the Original Code is vtiger.
- * Portions created by vtiger are Copyright (C) vtiger.
- * All Rights Reserved.
- *************************************************************************************/
-
-/** Classes to avoid logging */
-class LoggerPropertyConfigurator {
-	
-	static $singleton = false;
-	
-	function __construct() {
-	}
-	
-	function configure($configfile) {
-		$configinfo = parse_ini_file($configfile);
-		
-		$types = array();
-		$appenders = array();
-		
-		foreach($configinfo as $k=>$v) {
-			if(preg_match("/log4php.rootLogger/i", $k, $m)) {
-				$name = 'ROOT';
-				list($level, $appender) = explode(',', $v);
-				$types[$name]['level'] = $level;
-				$types[$name]['appender'] = $appender;
-			}
-			if(preg_match("/log4php.logger.(.*)/i", $k, $m)) {
-				$name = $m[1];
-				list($level, $appender) = explode(',', $v);
-				$types[$name]['level'] = $level;
-				$types[$name]['appender'] = $appender;
-			}
-			if(preg_match("/log4php.appender.([^.]+).?(.*)/i", $k, $m)) {
-				$appenders[$m[1]][$m[2]] = $v;
-			}
-			
-		}
-		
-		$this->types = $types;
-		$this->appenders = $appenders;		
-	}
-
-	function getConfigInfo($type) {
-		if(isset($this->types[$type])) {
-			$typeinfo = $this->types[$type];
-			return array (
-				'level'   => $typeinfo['level'],
-				'appender'=> $this->appenders[$typeinfo['appender']]
-		
-			);
-		}
-		return false;
-	}
-	
-	static function getInstance() {
-		if (!self::$singleton) self::$singleton = new static();
-		return self::$singleton;
-	}
-}
-?>
diff --git a/modules/Accounts/Accounts.php b/modules/Accounts/Accounts.php
index 1076fcf2b..cc964237f 100644
--- a/modules/Accounts/Accounts.php
+++ b/modules/Accounts/Accounts.php
@@ -104,7 +104,7 @@ class Accounts extends CRMEntity {
 	);
         function __construct()
         {
-            $this->log =Logger::getLogger('account');
+            $this->log =VtigerLogger::getLogger('account');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Accounts');
         }
diff --git a/modules/Calendar/Activity.php b/modules/Calendar/Activity.php
index 5e6eaf2e9..81d308b82 100644
--- a/modules/Calendar/Activity.php
+++ b/modules/Calendar/Activity.php
@@ -105,7 +105,7 @@ class Activity extends CRMEntity {
 	//var $groupTable = Array('vtiger_activitygrouprelation','activityid');
         function __construct()
         {
-            $this->log = Logger::getLogger('Calendar');
+            $this->log = VtigerLogger::getLogger('Calendar');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Calendar');
         }
diff --git a/modules/Campaigns/Campaigns.php b/modules/Campaigns/Campaigns.php
index 50ad738b0..d9d85c292 100644
--- a/modules/Campaigns/Campaigns.php
+++ b/modules/Campaigns/Campaigns.php
@@ -69,7 +69,7 @@ class Campaigns extends CRMEntity {
 	// For Alphabetical search
 	var $def_basicsearch_col = 'campaignname';
         function __construct() {
-            $this->log =Logger::getLogger('campaign');
+            $this->log =VtigerLogger::getLogger('campaign');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Campaigns');
         }   
diff --git a/modules/Contacts/Contacts.php b/modules/Contacts/Contacts.php
index 422c09245..bd738be33 100644
--- a/modules/Contacts/Contacts.php
+++ b/modules/Contacts/Contacts.php
@@ -145,7 +145,7 @@ class Contacts extends CRMEntity {
         'Vendors' => array('table_name' => 'vtiger_vendorcontactrel', 'table_index' => 'vendorid', 'rel_index' => 'contactid'),
 	);
         function __construct() {
-            $this->log = Logger::getLogger('contact');
+            $this->log = VtigerLogger::getLogger('contact');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Contacts');
         }       
diff --git a/modules/CustomView/ListViewTop.php b/modules/CustomView/ListViewTop.php
index ece5d2369..7b752d51b 100644
--- a/modules/CustomView/ListViewTop.php
+++ b/modules/CustomView/ListViewTop.php
@@ -60,7 +60,7 @@ function getKeyMetrics($maxval,$calCnt)
 	$metricviewnames = "'Hot Leads'";
 
 	$current_module_strings = return_module_language($current_language, "CustomView");
-	$log = Logger::getLogger('metrics');
+	$log = VtigerLogger::getLogger('metrics');
 
 	$metriclists = getMetricList();
 	
diff --git a/modules/Documents/Documents.php b/modules/Documents/Documents.php
index 646781b37..c605f67ca 100644
--- a/modules/Documents/Documents.php
+++ b/modules/Documents/Documents.php
@@ -72,7 +72,7 @@ class Documents extends CRMEntity {
 	var $default_sort_order = 'ASC';
         
         function __construct() {
-            $this->log = Logger::getLogger('notes');
+            $this->log = VtigerLogger::getLogger('notes');
             $this->log->debug("Entering Documents() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Documents');
diff --git a/modules/Emails/Emails.php b/modules/Emails/Emails.php
index b2a924d64..f591a85b6 100644
--- a/modules/Emails/Emails.php
+++ b/modules/Emails/Emails.php
@@ -68,9 +68,9 @@ class Emails extends CRMEntity {
 	/** This function will set the columnfields for Email module
 	 */
         function __construct() {
-            $this->log = Logger::getLogger('email');
+            $this->log = VtigerLogger::getLogger('email');
             $this->log->debug("Entering Emails() method ...");
-            $this->log = Logger::getLogger('email');
+            $this->log = VtigerLogger::getLogger('email');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Emails');
             $this->log->debug("Exiting Email method ...");
diff --git a/modules/Faq/Faq.php b/modules/Faq/Faq.php
index e5867d0a6..06c93d209 100755
--- a/modules/Faq/Faq.php
+++ b/modules/Faq/Faq.php
@@ -80,7 +80,7 @@ class Faq extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('faq');
+            $this->log =VtigerLogger::getLogger('faq');
             $this->log->debug("Entering Faq() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Faq');
diff --git a/modules/HelpDesk/HelpDesk.php b/modules/HelpDesk/HelpDesk.php
index 84d0c4134..bf2f8fd2e 100644
--- a/modules/HelpDesk/HelpDesk.php
+++ b/modules/HelpDesk/HelpDesk.php
@@ -101,7 +101,7 @@ class HelpDesk extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('helpdesk');
+            $this->log =VtigerLogger::getLogger('helpdesk');
             $this->log->debug("Entering HelpDesk() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('HelpDesk');
diff --git a/modules/Invoice/Invoice.php b/modules/Invoice/Invoice.php
index 7850dcc0b..0e39c6353 100755
--- a/modules/Invoice/Invoice.php
+++ b/modules/Invoice/Invoice.php
@@ -105,7 +105,7 @@ class Invoice extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('Invoice');
+            $this->log =VtigerLogger::getLogger('Invoice');
             $this->log->debug("Entering Invoice() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Invoice');
diff --git a/modules/Leads/Leads.php b/modules/Leads/Leads.php
index 0d366b322..f731614de 100755
--- a/modules/Leads/Leads.php
+++ b/modules/Leads/Leads.php
@@ -86,7 +86,7 @@ class Leads extends CRMEntity {
 	//var $groupTable = Array('vtiger_leadgrouprelation','leadid');
 
         function __construct() {
-            $this->log = Logger::getLogger('lead');
+            $this->log = VtigerLogger::getLogger('lead');
             $this->log->debug("Entering Leads() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Leads');
diff --git a/modules/Potentials/Potentials.php b/modules/Potentials/Potentials.php
index 128aeee76..69da8b542 100644
--- a/modules/Potentials/Potentials.php
+++ b/modules/Potentials/Potentials.php
@@ -93,7 +93,7 @@ class Potentials extends CRMEntity {
 	var $LBL_POTENTIAL_MAPPING = 'LBL_OPPORTUNITY_MAPPING';
 	//var $groupTable = Array('vtiger_potentialgrouprelation','potentialid');
 	function __construct() {
-            $this->log = Logger::getLogger('potential');
+            $this->log = VtigerLogger::getLogger('potential');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Potentials');
         }   
diff --git a/modules/PriceBooks/PriceBooks.php b/modules/PriceBooks/PriceBooks.php
index 8bb2fc7ef..5b0511aca 100755
--- a/modules/PriceBooks/PriceBooks.php
+++ b/modules/PriceBooks/PriceBooks.php
@@ -55,7 +55,7 @@ class PriceBooks extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('pricebook');
+            $this->log =VtigerLogger::getLogger('pricebook');
             $this->log->debug("Entering PriceBooks() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('PriceBooks');
diff --git a/modules/Products/Products.php b/modules/Products/Products.php
index d39e6ce4c..9a6be7c0d 100755
--- a/modules/Products/Products.php
+++ b/modules/Products/Products.php
@@ -74,7 +74,7 @@ class Products extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('product');
+            $this->log =VtigerLogger::getLogger('product');
             $this->log->debug("Entering Products() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Products');
diff --git a/modules/PurchaseOrder/PurchaseOrder.php b/modules/PurchaseOrder/PurchaseOrder.php
index 625bcfb62..730fdb4bf 100644
--- a/modules/PurchaseOrder/PurchaseOrder.php
+++ b/modules/PurchaseOrder/PurchaseOrder.php
@@ -98,7 +98,7 @@ class PurchaseOrder extends CRMEntity {
 	 *  creates an instance for PearDatabase class and get values for column_fields array of Order class.
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('PurchaseOrder');
+            $this->log =VtigerLogger::getLogger('PurchaseOrder');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('PurchaseOrder');
         }
diff --git a/modules/Quotes/Quotes.php b/modules/Quotes/Quotes.php
index 21435be09..767e06494 100755
--- a/modules/Quotes/Quotes.php
+++ b/modules/Quotes/Quotes.php
@@ -105,7 +105,7 @@ class Quotes extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('quote');
+            $this->log =VtigerLogger::getLogger('quote');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Quotes');
         }
diff --git a/modules/Reports/ReportSharing.php b/modules/Reports/ReportSharing.php
index b0d4375cc..b8f29131e 100644
--- a/modules/Reports/ReportSharing.php
+++ b/modules/Reports/ReportSharing.php
@@ -21,7 +21,7 @@ $current_module_strings = return_module_language($current_language, 'Reports');
 global $list_max_entries_per_page;
 global $urlPrefix;
 
-$log = Logger::getLogger('report_type');
+$log = VtigerLogger::getLogger('report_type');
 global $currentModule;
 global $image_path;
 global $theme;
diff --git a/modules/Reports/ReportType.php b/modules/Reports/ReportType.php
index 0e14e9fc8..f580678ec 100644
--- a/modules/Reports/ReportType.php
+++ b/modules/Reports/ReportType.php
@@ -21,7 +21,7 @@ $current_module_strings = return_module_language($current_language, 'Reports');
 global $list_max_entries_per_page;
 global $urlPrefix;
 
-$log = Logger::getLogger('report_type');
+$log = VtigerLogger::getLogger('report_type');
 
 global $currentModule;
 global $image_path;
diff --git a/modules/SalesOrder/SalesOrder.php b/modules/SalesOrder/SalesOrder.php
index c7ca1a6d9..b60a23448 100644
--- a/modules/SalesOrder/SalesOrder.php
+++ b/modules/SalesOrder/SalesOrder.php
@@ -107,7 +107,7 @@ class SalesOrder extends CRMEntity {
 	 *  creates an instance for PearDatabase class and get values for column_fields array of SalesOrder class.
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('SalesOrder');
+            $this->log =VtigerLogger::getLogger('SalesOrder');
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('SalesOrder');
         }
diff --git a/modules/Users/DefaultDataPopulator.php b/modules/Users/DefaultDataPopulator.php
index 6b97a414c..3c2d20c7b 100644
--- a/modules/Users/DefaultDataPopulator.php
+++ b/modules/Users/DefaultDataPopulator.php
@@ -18,7 +18,7 @@ require_once('include/utils/utils.php');
 class DefaultDataPopulator extends CRMEntity {
 
         function __construct() {
-            $this->log = Logger::getLogger('DefaultDataPopulator');
+            $this->log = VtigerLogger::getLogger('DefaultDataPopulator');
             $this->db = PearDatabase::getInstance();
         }
 	function DefaultDataPopulator() {
diff --git a/modules/Users/Users.php b/modules/Users/Users.php
index b0ad5bd58..c954519b1 100755
--- a/modules/Users/Users.php
+++ b/modules/Users/Users.php
@@ -133,7 +133,7 @@ class Users extends CRMEntity {
 	 *
 	 */
         function __construct() {
-            $this->log = Logger::getLogger('user');
+            $this->log = VtigerLogger::getLogger('user');
             $this->log->debug("Entering Users() method ...");
             $this->db = PearDatabase::getInstance();
             $this->DEFAULT_PASSWORD_CRYPT_TYPE = (version_compare(PHP_VERSION, '5.3.0') >= 0)? 'PHP5.3MD5': 'MD5';
diff --git a/modules/Vendors/Vendors.php b/modules/Vendors/Vendors.php
index abe9b79d2..fdb4d8899 100755
--- a/modules/Vendors/Vendors.php
+++ b/modules/Vendors/Vendors.php
@@ -65,7 +65,7 @@ class Vendors extends CRMEntity {
 	/**	Constructor which will set the column_fields in this object
 	 */
         function __construct() {
-            $this->log =Logger::getLogger('vendor');
+            $this->log =VtigerLogger::getLogger('vendor');
             $this->log->debug("Entering Vendors() method ...");
             $this->db = PearDatabase::getInstance();
             $this->column_fields = getColumnFields('Vendors');
diff --git a/modules/Vtiger/helpers/VtigerLogger.php b/modules/Vtiger/helpers/VtigerLogger.php
new file mode 100644
index 000000000..c4b14834b
--- /dev/null
+++ b/modules/Vtiger/helpers/VtigerLogger.php
@@ -0,0 +1,54 @@
+<?php
+/*+**********************************************************************************
+ * The contents of this file are subject to the vtiger CRM Public License Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * The Original Code is:  vtiger CRM Open Source
+ * The Initial Developer of the Original Code is vtiger.
+ * Portions created by vtiger are Copyright (C) vtiger.
+ * All Rights Reserved.
+ ************************************************************************************/
+
+require 'vendor/autoload.php';
+
+use Monolog\Logger;
+use Monolog\Handler\StreamHandler;
+
+class VtigerLogger {
+    
+    static $filePath = '';
+    static $logLevel = '';
+    public static function getLogger(string $channel, $customFormatter = true) {
+        $log = new self();
+        if(self::$logLevel) {
+            $log = new Logger($channel);
+            $handler = new StreamHandler(self::$filePath, self::$logLevel);
+            if($customFormatter) {
+                $handler->setFormatter(new VtigerCustomFormatter());
+            }
+            $log->pushHandler($handler);
+        }
+        return $log;
+        
+    }
+    public function info($message) { }
+    public function debug($message) { }
+}
+
+use Monolog\Formatter\FormatterInterface;
+
+class VtigerCustomFormatter implements FormatterInterface {
+
+    public function format(Monolog\LogRecord $record) {
+        $record = $record->toArray();
+        $formatted = '[' . date('Y-m-d H:i:s') . '] - ' .$record['level_name'].' - '.$record['channel'].' - '.$record['message'] . PHP_EOL;
+        return $formatted;
+    }
+
+    public function formatBatch(array $records) {
+        $formatted = '';
+        foreach ($records as $record) {
+            $formatted .= $this->format($record);
+        }
+        return $formatted;
+    }
+}
diff --git a/modules/Vtiger/layout_utils.php b/modules/Vtiger/layout_utils.php
index f65fff9fc..37060baec 100644
--- a/modules/Vtiger/layout_utils.php
+++ b/modules/Vtiger/layout_utils.php
@@ -22,7 +22,7 @@
 require_once('include/logging.php');
 global $app_strings;
 
-$log = Logger::getLogger('layout_utils');	
+$log = VtigerLogger::getLogger('layout_utils');	
 
 /**
  * Create HTML to display formatted form title of a form in the left pane
diff --git a/webservice.php b/webservice.php
index 98edfe4f3..b17c5889b 100644
--- a/webservice.php
+++ b/webservice.php
@@ -36,8 +36,8 @@ require_once("config.php");
 	$API_VERSION = "0.22";
 
 	global $seclog,$log;
-	$seclog = Logger::getLogger('SECURITY');
-	$log = Logger::getLogger('webservice');
+	$seclog = VtigerLogger::getLogger('SECURITY');
+	$log = VtigerLogger::getLogger('webservice');
 
 	function getRequestParamsArrayForOperation($operation){
 		global $operationInput;
-- 
GitLab