diff --git a/composer.json b/composer.json index 0cd484e9576a28f75823ff7b2d7cac36e38a0e66..c8b1e390c1488dc61f73a3571395c84978995b18 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": "^3.5" } } diff --git a/composer.lock b/composer.lock index b410d4ae62823099b066fb256fae91a2246b682c..ca4fd136ed283c4f6e463f60419662fb3035cee9 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 d40db3411886764f9ace4563d09680884e6006cc..db6125cdc0ff2af6a0bc7943f02cdda4fcfa92ab 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' => 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/include/database/PearDatabase.php b/include/database/PearDatabase.php index 755a14386fb781c8ea67c91cc65b91a1169eb719..9a6cd7377f70439dfdaf36d63a497c6de45b9614 100644 --- a/include/database/PearDatabase.php +++ b/include/database/PearDatabase.php @@ -113,7 +113,6 @@ class PearDatabase{ function println($msg) { - require_once('include/logging.php'); $log1 = Logger::getLogger('VT'); if(is_array($msg)) { $log1->info("PearDatabse ->".print_r($msg,true)); diff --git a/include/logging.php b/include/logging.php index 709b85c325e3a799c957619a35f04af4aedcfa4c..d86b285b5b29a0c15c87ab6629510b3697a7193f 100644 --- a/include/logging.php +++ b/include/logging.php @@ -21,16 +21,5 @@ require_once('config.php'); // Performance Optimization: Configure the log folder @include_once('config.performance.php'); -global $PERFORMANCE_CONFIG; -if(isset($PERFORMANCE_CONFIG) && isset($PERFORMANCE_CONFIG['LOG4PHP_DEBUG']) && $PERFORMANCE_CONFIG['LOG4PHP_DEBUG']) { - define('LOG4PHP_DIR', 'libraries/log4php'); -} else { - define('LOG4PHP_DIR', 'libraries/log4php'); -} -// END - -define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true); -require_once(LOG4PHP_DIR.'/Logger.php'); -Logger::configure('log4php.properties'); - +require_once 'modules/Vtiger/helpers/Logger.php'; ?> diff --git a/libraries/log4php/Logger.php b/libraries/log4php/Logger.php deleted file mode 100644 index c50568a591656a596db56d543e3af42b386f53d8..0000000000000000000000000000000000000000 --- 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 8969499ad1e7887c451f05fe6573213a6c829041..0000000000000000000000000000000000000000 --- 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/Vtiger/helpers/Logger.php b/modules/Vtiger/helpers/Logger.php new file mode 100644 index 0000000000000000000000000000000000000000..1d545f488f837ab18910cfcd91ff8a0fcdab9533 --- /dev/null +++ b/modules/Vtiger/helpers/Logger.php @@ -0,0 +1,104 @@ +<?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. + * ********************************************************************************** */ + +// Include the Monolog library for logging functionality +require 'vendor/autoload.php'; + +// Import necessary classes from Monolog +use Monolog\Logger as MonologLogger; +use Monolog\Handler\StreamHandler; + +// Define a custom Logger class +class Logger { + + private static $logLevel; + private static $filePath; + private static $initialized = false; + + /** + * Constructor to initialize the logger + * @global type $PERFORMANCE_CONFIG [Enable LOGLEVEL_DEBUG falg in config.performance.php] + */ + public function __construct() { + // Check if the logger is not already initialized + if (!self::$initialized) { + global $PERFORMANCE_CONFIG; + // Check if the performance config is set and debug logging is enabled + if (isset($PERFORMANCE_CONFIG) && isset($PERFORMANCE_CONFIG['LOGLEVEl_DEBUG']) && $PERFORMANCE_CONFIG['LOGLEVEl_DEBUG']) { + // Set the default log level to 100 and the log file path + self::$logLevel = 100; + self::$filePath = "logs/vtigercrm.log"; + self::$initialized = true; + } + } + } + + /** + * Static method to get a logger instance + */ + public static function getLogger(string $channel, $customFormatter = true) { + // Create a new logger instance + $log = new self(); + + // Check if log level is set (logger is initialized) + if (self::$logLevel) { + $log = new MonologLogger($channel); + $handler = new StreamHandler(self::$filePath, self::$logLevel); + + // Set a custom formatter if customFormatter is true + if ($customFormatter) { + $handler->setFormatter(new VtigerCustomFormatter()); + } + $log->pushHandler($handler); + } + return $log; + } + + // Placeholder method for logging information + public function info($message) { + // Logging info not implemented + } + + // Placeholder method for logging debug messages + public function debug($message) { + // Logging debug not implemented + } +} + +// Define a custom log formatter +use Monolog\Formatter\FormatterInterface; + +class VtigerCustomFormatter implements FormatterInterface { + + /** + * Format a log record + * @param Monolog\LogRecord $record + * @return string + */ + 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; + } + + /** + * Format a batch of log records + * @param array $records + * @return type string + */ + public function formatBatch(array $records) { + $formatted = ''; + foreach ($records as $record) { + $formatted .= $this->format($record); + } + return $formatted; + } +}