From 06a914dcfce0cd10edc6e74849ddf90ba6fe9110 Mon Sep 17 00:00:00 2001 From: appu <apparao@vtiger.com> Date: Tue, 14 Nov 2023 09:42:33 +0530 Subject: [PATCH] Feature::Vtiger Logger enabled using MonoLog library --- SendSupportNotification.php | 2 +- config.performance.php | 2 +- cron/SendReminder.service | 2 +- .../SalesOrder/RecurringInvoice.service | 2 +- data/Tracker.php | 2 +- include/database/PearDatabase.php | 8 ++-- include/logging.php | 12 +---- include/utils/export.php | 2 +- 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 +- .../helpers/{VtigerLogger.php => Logger.php} | 45 +++++++++++++------ modules/Vtiger/layout_utils.php | 2 +- webservice.php | 4 +- 33 files changed, 69 insertions(+), 60 deletions(-) rename modules/Vtiger/helpers/{VtigerLogger.php => Logger.php} (51%) diff --git a/SendSupportNotification.php b/SendSupportNotification.php index 8a63053e9..17c81cd4b 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 = VtigerLogger::getLogger('SendSupportNotification'); +$log = Logger::getLogger('SendSupportNotification'); $log->debug(" invoked SendSupportNotification "); // retrieve the translated strings. diff --git a/config.performance.php b/config.performance.php index 66fd8a695..db6125cdc 100644 --- a/config.performance.php +++ b/config.performance.php @@ -10,7 +10,7 @@ /* Performance paramters can be configured to fine tune vtiger CRM runtime */ $PERFORMANCE_CONFIG = Array( // Enable Vtiger Log Level for debugging only if requried - 'LOGLEVEl_DEBUG' => true, + 'LOGLEVEl_DEBUG' => false, // 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 48263e29a..70d5e538b 100644 --- a/cron/SendReminder.service +++ b/cron/SendReminder.service @@ -42,7 +42,7 @@ if(empty($from)) { global $adb; global $log; global $site_URL; -$log =VtigerLogger::getLogger('SendReminder'); +$log =Logger::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 17a824a29..c36a70574 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 = VtigerLogger::getLogger('RecurringInvoice'); +$log = Logger::getLogger('RecurringInvoice'); $log->debug("invoked RecurringInvoice"); $currentDate = date('Y-m-d'); diff --git a/data/Tracker.php b/data/Tracker.php index fd52d9d4d..7c59b6e75 100755 --- a/data/Tracker.php +++ b/data/Tracker.php @@ -46,7 +46,7 @@ class Tracker { ); function __construct() { - $this->log = VtigerLogger::getLogger('Tracker'); + $this->log = Logger::getLogger('Tracker'); // $this->db = PearDatabase::getInstance(); global $adb; $this->db = $adb; diff --git a/include/database/PearDatabase.php b/include/database/PearDatabase.php index 1f8275333..9a6cd7377 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 = VtigerLogger::getLogger('VT'); -$logsqltm = VtigerLogger::getLogger('SQLTIME'); +$log = Logger::getLogger('VT'); +$logsqltm = Logger::getLogger('SQLTIME'); // Callback class useful to convert PreparedStatement Question Marks to SQL value // See function convertPS2Sql in PearDatabase below @@ -113,7 +113,7 @@ class PearDatabase{ function println($msg) { - $log1 = VtigerLogger::getLogger('VT'); + $log1 = Logger::getLogger('VT'); if(is_array($msg)) { $log1->info("PearDatabse ->".print_r($msg,true)); } else { @@ -857,7 +857,7 @@ class PearDatabase{ */ function __construct($dbtype='',$host='',$dbname='',$username='',$passwd='') { global $currentModule; - $this->log = VtigerLogger::getLogger('PearDatabase_'. $currentModule); + $this->log = Logger::getLogger('PearDatabase_'. $currentModule); $this->resetSettings($dbtype,$host,$dbname,$username,$passwd); // Initialize performance parameters diff --git a/include/logging.php b/include/logging.php index 1e3e3e9d0..d86b285b5 100644 --- a/include/logging.php +++ b/include/logging.php @@ -21,15 +21,5 @@ 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['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 { - VtigerLogger::$logLevel = 0; -} -// END - +require_once 'modules/Vtiger/helpers/Logger.php'; ?> diff --git a/include/utils/export.php b/include/utils/export.php index 66bc892af..d4c6b7456 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 = VtigerLogger::getLogger('export_'.$type); + $log = Logger::getLogger('export_'.$type); $db = PearDatabase::getInstance(); $oCustomView = new CustomView("$type"); diff --git a/modules/Accounts/Accounts.php b/modules/Accounts/Accounts.php index cc964237f..1076fcf2b 100644 --- a/modules/Accounts/Accounts.php +++ b/modules/Accounts/Accounts.php @@ -104,7 +104,7 @@ class Accounts extends CRMEntity { ); function __construct() { - $this->log =VtigerLogger::getLogger('account'); + $this->log =Logger::getLogger('account'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('Accounts'); } diff --git a/modules/Calendar/Activity.php b/modules/Calendar/Activity.php index 81d308b82..5e6eaf2e9 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 = VtigerLogger::getLogger('Calendar'); + $this->log = Logger::getLogger('Calendar'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('Calendar'); } diff --git a/modules/Campaigns/Campaigns.php b/modules/Campaigns/Campaigns.php index d9d85c292..50ad738b0 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 =VtigerLogger::getLogger('campaign'); + $this->log =Logger::getLogger('campaign'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('Campaigns'); } diff --git a/modules/Contacts/Contacts.php b/modules/Contacts/Contacts.php index bd738be33..422c09245 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 = VtigerLogger::getLogger('contact'); + $this->log = Logger::getLogger('contact'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('Contacts'); } diff --git a/modules/CustomView/ListViewTop.php b/modules/CustomView/ListViewTop.php index 7b752d51b..ece5d2369 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 = VtigerLogger::getLogger('metrics'); + $log = Logger::getLogger('metrics'); $metriclists = getMetricList(); diff --git a/modules/Documents/Documents.php b/modules/Documents/Documents.php index c605f67ca..646781b37 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 = VtigerLogger::getLogger('notes'); + $this->log = Logger::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 f591a85b6..b2a924d64 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 = VtigerLogger::getLogger('email'); + $this->log = Logger::getLogger('email'); $this->log->debug("Entering Emails() method ..."); - $this->log = VtigerLogger::getLogger('email'); + $this->log = Logger::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 06c93d209..e5867d0a6 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 =VtigerLogger::getLogger('faq'); + $this->log =Logger::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 bf2f8fd2e..84d0c4134 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 =VtigerLogger::getLogger('helpdesk'); + $this->log =Logger::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 0e39c6353..7850dcc0b 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 =VtigerLogger::getLogger('Invoice'); + $this->log =Logger::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 f731614de..0d366b322 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 = VtigerLogger::getLogger('lead'); + $this->log = Logger::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 69da8b542..128aeee76 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 = VtigerLogger::getLogger('potential'); + $this->log = Logger::getLogger('potential'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('Potentials'); } diff --git a/modules/PriceBooks/PriceBooks.php b/modules/PriceBooks/PriceBooks.php index 5b0511aca..8bb2fc7ef 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 =VtigerLogger::getLogger('pricebook'); + $this->log =Logger::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 9a6be7c0d..d39e6ce4c 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 =VtigerLogger::getLogger('product'); + $this->log =Logger::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 730fdb4bf..625bcfb62 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 =VtigerLogger::getLogger('PurchaseOrder'); + $this->log =Logger::getLogger('PurchaseOrder'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('PurchaseOrder'); } diff --git a/modules/Quotes/Quotes.php b/modules/Quotes/Quotes.php index 767e06494..21435be09 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 =VtigerLogger::getLogger('quote'); + $this->log =Logger::getLogger('quote'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('Quotes'); } diff --git a/modules/Reports/ReportSharing.php b/modules/Reports/ReportSharing.php index b8f29131e..b0d4375cc 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 = VtigerLogger::getLogger('report_type'); +$log = Logger::getLogger('report_type'); global $currentModule; global $image_path; global $theme; diff --git a/modules/Reports/ReportType.php b/modules/Reports/ReportType.php index f580678ec..0e14e9fc8 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 = VtigerLogger::getLogger('report_type'); +$log = Logger::getLogger('report_type'); global $currentModule; global $image_path; diff --git a/modules/SalesOrder/SalesOrder.php b/modules/SalesOrder/SalesOrder.php index b60a23448..c7ca1a6d9 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 =VtigerLogger::getLogger('SalesOrder'); + $this->log =Logger::getLogger('SalesOrder'); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('SalesOrder'); } diff --git a/modules/Users/DefaultDataPopulator.php b/modules/Users/DefaultDataPopulator.php index 3c2d20c7b..6b97a414c 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 = VtigerLogger::getLogger('DefaultDataPopulator'); + $this->log = Logger::getLogger('DefaultDataPopulator'); $this->db = PearDatabase::getInstance(); } function DefaultDataPopulator() { diff --git a/modules/Users/Users.php b/modules/Users/Users.php index c954519b1..b0ad5bd58 100755 --- a/modules/Users/Users.php +++ b/modules/Users/Users.php @@ -133,7 +133,7 @@ class Users extends CRMEntity { * */ function __construct() { - $this->log = VtigerLogger::getLogger('user'); + $this->log = Logger::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 fdb4d8899..abe9b79d2 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 =VtigerLogger::getLogger('vendor'); + $this->log =Logger::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/Logger.php similarity index 51% rename from modules/Vtiger/helpers/VtigerLogger.php rename to modules/Vtiger/helpers/Logger.php index c4b14834b..f2fd2b0e5 100644 --- a/modules/Vtiger/helpers/VtigerLogger.php +++ b/modules/Vtiger/helpers/Logger.php @@ -1,37 +1,56 @@ <?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\Logger as MonologLogger; use Monolog\Handler\StreamHandler; -class VtigerLogger { - - static $filePath = ''; - static $logLevel = ''; +class Logger { + + private static $logLevel; + private static $filePath; + private static $initialized = false; + + public function __construct() { + if (!self::$initialized) { + global $PERFORMANCE_CONFIG; + if (isset($PERFORMANCE_CONFIG) && isset($PERFORMANCE_CONFIG['LOGLEVEl_DEBUG']) && $PERFORMANCE_CONFIG['LOGLEVEl_DEBUG']) { + self::$logLevel = 100; // Default log file path.; + self::$filePath = "logs/vtigercrm.log"; + self::$initialized = true; + } + } + } + public static function getLogger(string $channel, $customFormatter = true) { $log = new self(); - if(self::$logLevel) { - $log = new Logger($channel); + if (self::$logLevel) { + $log = new MonologLogger($channel); $handler = new StreamHandler(self::$filePath, self::$logLevel); - if($customFormatter) { + if ($customFormatter) { $handler->setFormatter(new VtigerCustomFormatter()); } $log->pushHandler($handler); } return $log; + } + + public function info($message) { + + } + + public function debug($message) { } - public function info($message) { } - public function debug($message) { } } use Monolog\Formatter\FormatterInterface; @@ -40,7 +59,7 @@ 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; + $formatted = '[' . date('Y-m-d H:i:s') . '] - ' . $record['level_name'] . ' - ' . $record['channel'] . ' - ' . $record['message'] . PHP_EOL; return $formatted; } diff --git a/modules/Vtiger/layout_utils.php b/modules/Vtiger/layout_utils.php index 37060baec..f65fff9fc 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 = VtigerLogger::getLogger('layout_utils'); +$log = Logger::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 b17c5889b..98edfe4f3 100644 --- a/webservice.php +++ b/webservice.php @@ -36,8 +36,8 @@ require_once("config.php"); $API_VERSION = "0.22"; global $seclog,$log; - $seclog = VtigerLogger::getLogger('SECURITY'); - $log = VtigerLogger::getLogger('webservice'); + $seclog = Logger::getLogger('SECURITY'); + $log = Logger::getLogger('webservice'); function getRequestParamsArrayForOperation($operation){ global $operationInput; -- GitLab