From ff9fd9cfb668c6bb11ec4a6555feb031477844c1 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Thu, 11 Apr 2024 13:54:00 +0200 Subject: [PATCH] 1) Allow to customize the logging and cache directory because on some server there are dedicated directories for this. 2) Allow better exception reporting when an exception occurs during PNG generation. 3) Allow to output the errors to syslog since for production server is the best practice. --- qrconfig.php | 11 +++++++++-- qrencode.php | 2 +- qrtools.php | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/qrconfig.php b/qrconfig.php index e53dff8..492ffd7 100644 --- a/qrconfig.php +++ b/qrconfig.php @@ -5,9 +5,16 @@ * Config file, feel free to modify */ - define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there + + if (!defined('QR_CACHEABLE')) { + define( 'QR_CACHEABLE', true ); // use cache - more disk reads but less CPU power, masks and format templates are stored there + } + if (!defined('QR_CACHE_DIR')) { define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true - define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir + } + if (!defined('QR_LOG_DIR')) { + define( 'QR_LOG_DIR', dirname( __FILE__ ) . DIRECTORY_SEPARATOR ); // default error logs dir + } define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code define('QR_FIND_FROM_RANDOM', false); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly diff --git a/qrencode.php b/qrencode.php index 6c210e8..7c52e1a 100644 --- a/qrencode.php +++ b/qrencode.php @@ -514,7 +514,7 @@ public function encodePNG($intext, $outfile = false,$saveandprint=false) } catch (Exception $e) { - QRtools::log($outfile, $e->getMessage()); + QRtools::log($outfile, $e->getMessage() .' in '. $e->GetFile() . ':' . $e->GetLine()); } } diff --git a/qrtools.php b/qrtools.php index bb29528..864df07 100644 --- a/qrtools.php +++ b/qrtools.php @@ -109,6 +109,9 @@ public static function log($outfile, $err) } } } + if (defined('QR_LOG_SYSLOG') && QR_LOG_SYSLOG) { + syslog(LOG_ERR, '[QRTOOLS] '. $err); + } } //----------------------------------------------------------------------