From: Banana Date: Sun, 19 Nov 2023 10:57:41 +0000 (+0100) Subject: better logging X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=a4a44458ac89371fefea3e176379181f6a6440bb;p=insipid.git better logging --- diff --git a/ChangeLog b/ChangeLog index b443a9d..2f61263 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,80 +1,81 @@ version 2.x.x - Griffin Chapel () + + Better logging version 2.8.2 - Dragon Chapel (2023-09-14) - + Added LOGFILE and QUERY_DEBUG const to config.php. See update.txt for more details - + Updated DB table charsets. Needs manual DB updates. See update.txt file. - + Fixed URL handling at creation - + Improved DB queries. - + Add top 5 tag or category relation stats in the tag and category overview - + Updated license to GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - + Updated error logging and try/catch for mysql - + Updated from https://github.com/druidfi/mysqldump-php to https://github.com/ifsnop/mysqldump-php since develop - resumed. Version mysqldump-php v2.11 - + Updated https://github.com/mikehaertl/php-shellcommand to 1.7.0 + + Added LOGFILE and QUERY_DEBUG const to config.php. See update.txt for more details + + Updated DB table charsets. Needs manual DB updates. See update.txt file. + + Fixed URL handling at creation + + Improved DB queries. + + Add top 5 tag or category relation stats in the tag and category overview + + Updated license to GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 + + Updated error logging and try/catch for mysql + + Updated from https://github.com/druidfi/mysqldump-php to https://github.com/ifsnop/mysqldump-php since develop + resumed. Version mysqldump-php v2.11 + + Updated https://github.com/mikehaertl/php-shellcommand to 1.7.0 version 2.8.1 - Deathwind Chapel (2022-12-31) - + Bugfix release - + Moved debug setting into config - + Updated shellcommand class and added the link to the github repo - + Fixed/Updated the creation of the webpage thumbnail using google pagespeed insights api - + Fixed search index update - + Fixed missing lang property - + Fixed xml ex- and import - + Fixed pagination and sort options in all links view - + Mysql dump replaced with https://github.com/druidfi/mysqldump-php - + Updated PHPMailer - + Removed WKHTMLTOPDF_USE and WKHTMLTOPDF_COMMAND from config. No support for a whole page screenshot yet. + + Bugfix release + + Moved debug setting into config + + Updated shellcommand class and added the link to the github repo + + Fixed/Updated the creation of the webpage thumbnail using google pagespeed insights api + + Fixed search index update + + Fixed missing lang property + + Fixed xml ex- and import + + Fixed pagination and sort options in all links view + + Mysql dump replaced with https://github.com/druidfi/mysqldump-php + + Updated PHPMailer + + Removed WKHTMLTOPDF_USE and WKHTMLTOPDF_COMMAND from config. No support for a whole page screenshot yet. version 2.8 - Wastelands (2022-12-10) - + Fixed documentation - + Fixed some PHP 8 defaults - + Fixed #17 + + Fixed documentation + + Fixed some PHP 8 defaults + + Fixed #17 version 2.7 - Sacred Grove (2022-06-12) - + Fixed bug #12. Missing translation key - + Adapted some new PHP code formatting - + Fixed some translations - + Updated bulma css - + Added random link page - + New syntax in config file. See update.txt for more details - + Fixed #13 - + Fixed #15 - + Fixed #14 - + Fixed some small email importer notices and warnings + + Fixed bug #12. Missing translation key + + Adapted some new PHP code formatting + + Fixed some translations + + Updated bulma css + + Added random link page + + New syntax in config file. See update.txt for more details + + Fixed #13 + + Fixed #15 + + Fixed #14 + + Fixed some small email importer notices and warnings version 2.6 - Hypostyle (2021-03-21) - + Fixed sql problems with Maria DB. Any_value is not supported there - + Fixed some query and data loading brain fucks.. - + Fixed #10. URL is now considered when building search information. - Update search index from stats view to update all the exiting information - + Updated third party information in readme - + Fixed xml import xsd - + Added translation support. More information in translation.txt + + Fixed sql problems with Maria DB. Any_value is not supported there + + Fixed some query and data loading brain fucks.. + + Fixed #10. URL is now considered when building search information. + Update search index from stats view to update all the exiting information + + Updated third party information in readme + + Fixed xml import xsd + + Added translation support. More information in translation.txt version 2.5.2 - Darkmere (2020-09-12) - + Fixed bug #8 It is possible to add empty tags and categories. - Special chars check done on server side. JS has problems with unicode. - + Fixed bug #7 Edit categories/tags. Rename and move - + Fixed feature #3 Reduce whitespace in frontend + + Fixed bug #8 It is possible to add empty tags and categories. + Special chars check done on server side. JS has problems with unicode. + + Fixed bug #7 Edit categories/tags. Rename and move + + Fixed feature #3 Reduce whitespace in frontend version 2.5.1 - Caves of Circe (2020-03-22) - + Bugfix release + + Bugfix release version 2.5 - Winnowing Hall (2020-03-21) - + Added a thumbnail by talking to Google page speed API - Planned was a full page snapshot, but only got the thumbnail. - Needs some more work with headless chrome. - + Instead you can now decide to make a full page screenshot - using wkhtmltoimage. See documentation about it. - + Improved documentation + + Added a thumbnail by talking to Google page speed API + Planned was a full page snapshot, but only got the thumbnail. + Needs some more work with headless chrome. + + Instead you can now decide to make a full page screenshot + using wkhtmltoimage. See documentation about it. + + Improved documentation version 2.4 - Seven Portals (2020-02-16) diff --git a/webroot/job/email-import.php b/webroot/job/email-import.php index 9f064e6..cd7afdf 100644 --- a/webroot/job/email-import.php +++ b/webroot/job/email-import.php @@ -122,7 +122,7 @@ try { if(DEBUG === true) $EmailReader->mailboxStatus(); } catch (Exception $e) { - Summoner::sysLog('[ERROR] Email server connection failed: '.var_export($e->getMessage(),true)); + Summoner::sysLog('[ERROR] Email server connection failed: '.$e->getMessage()); exit(); } @@ -132,7 +132,7 @@ try { $emails = $EmailReader->messageWithValidSubject(EMAIL_MARKER); } catch (Exception $e) { - Summoner::sysLog('[ERROR] Can not process email messages: '.var_export($e->getMessage(),true)); + Summoner::sysLog('[ERROR] Can not process email messages: '.$e->getMessage()); exit(); } @@ -143,7 +143,7 @@ if(!empty($emails)) { foreach($emails as $emailId=>$emailData) { $links = EmailImportHelper::extractEmailLinks($emailData['body']); if(!empty($links)) { - if(DEBUG === true) var_dump("Links in email:",$links); + if(DEBUG === true) Summoner::sysLog("Links in email: ".Summoner::cleanForLog($links)); foreach($links as $linkstring) { # defaults @@ -170,8 +170,8 @@ if(!empty($emails)) { $newdata['link'] = Summoner::addSchemeToURL($newdata['link']); if (!filter_var($newdata['link'], FILTER_VALIDATE_URL)) { - error_log("ERROR Invalid URL: ".var_export($newdata['link'],true)); - if(DEBUG === true) var_dump("Invalid URL:", $newdata['link']); + error_log("ERROR Invalid URL: ".Summoner::cleanForLog($newdata['link'])); + if(DEBUG === true) Summoner::sysLog("Invalid URL: ".Summoner::cleanForLog($newdata['link'])); continue; } @@ -190,12 +190,12 @@ if(!empty($emails)) { } else { error_log("WARN No valid title for link found: ".$newdata['link']); - if(DEBUG === true) var_dump("WARN No valid title for link found: ".var_export($newdata,true)); + if(DEBUG === true) Summoner::sysLog("[WARN] No valid title for link found: ".Summoner::cleanForLog($newdata)); array_push($invalidProcessedEmails, $emailData); continue; } - if(DEBUG === true) var_dump("New data", $newdata); + if(DEBUG === true) Summoner::sysLog("New data ".Summoner::cleanForLog($newdata)); $linkObj = new Link($DB); $linkID = false; @@ -207,7 +207,7 @@ if(!empty($emails)) { if(!empty($existing) && isset($existing['id'])) { $linkID = $existing['id']; - Summoner::sysLog('[INFO] Updating existing link with tag or category '.$newdata['link']); + Summoner::sysLog('[INFO] Updating existing link with tag or category '.Summoner::cleanForLog($newdata['link'])); } else { $linkObj = new Link($DB); @@ -223,12 +223,12 @@ if(!empty($emails)) { 'catArr' => $newdata['catArr'] ), true); } catch (Exception $e) { - $_m = "WARN Can not create new link into DB." . $e->getMessage(); + $_m = "[WARN] Can not create new link into DB." . $e->getMessage(); Summoner::sysLog($_m); $emailData['importmessage'] = $_m; array_push($invalidProcessedEmails, $emailData); - if (DEBUG === true) var_dump($_m); - if (DEBUG === true) var_dump($newdata); + if (DEBUG === true) Summoner::sysLog($_m); + if (DEBUG === true) Summoner::sysLog(Summoner::cleanForLog($newdata)); continue; } } diff --git a/webroot/lib/category.class.php b/webroot/lib/category.class.php index f1f74d3..5370547 100644 --- a/webroot/lib/category.class.php +++ b/webroot/lib/category.class.php @@ -226,7 +226,7 @@ class Category { $this->DB->commit(); $ret = true; } catch (Exception $e) { - Summoner::sysLog('ERROR Failed to remove category: '.var_export($e->getMessage(),true)); + Summoner::sysLog('ERROR Failed to remove category: '.$e->getMessage()); $this->DB->rollback(); } } diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index f4bb220..e15e17e 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -219,7 +219,7 @@ class Link { $ret = $this->DB->insert_id; } else { - Summoner::sysLog('ERROR Failed to create link: '.var_export($data,true)); + Summoner::sysLog('ERROR Failed to create link: '.Summoner::cleanForLog($data)); } } catch (Exception $e) { Summoner::sysLog("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage()); @@ -333,7 +333,7 @@ class Link { $snap = new Snapshot(); $do = $snap->doSnapshot($this->_data['link'], $snapshot); if(empty($do)) { - Summoner::sysLog('ERROR Failed to create snapshot: '.var_export($data,true)); + Summoner::sysLog('ERROR Failed to create snapshot: '.Summoner::cleanForLog($data)); } } } elseif ($data['snapshot'] === false) { @@ -352,7 +352,7 @@ class Link { $snap = new Snapshot(); $do = $snap->wholePageSnapshot($this->_data['link'], $pagescreenshot); if(!empty($do)) { - Summoner::sysLog('ERROR Failed to create snapshot: '.var_export($data,true)); + Summoner::sysLog('ERROR Failed to create snapshot: '.Summoner::cleanForLog($data)); } } } elseif ($data['pagescreenshot'] === false) { @@ -365,7 +365,7 @@ class Link { $ret = true; } else { $this->DB->rollback(); - Summoner::sysLog('ERROR Failed to update link: '.var_export($data,true)); + Summoner::sysLog('ERROR Failed to update link: '.Summoner::cleanForLog($data)); } } diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index bdc05a3..315638b 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -918,7 +918,7 @@ class Management { if(!empty($data) && isset($data['link'])) { if(DEBUG) { - Summoner::sysLog("DEBUG Using data: ".var_export($data, true)); + Summoner::sysLog("DEBUG Using data: ".Summoner::cleanForLog($data)); } require_once 'lib/import-export.class.php'; $ImEx = new ImportExport(); diff --git a/webroot/lib/simple-imap.class.php b/webroot/lib/simple-imap.class.php index 8b9a914..9a486ac 100644 --- a/webroot/lib/simple-imap.class.php +++ b/webroot/lib/simple-imap.class.php @@ -160,7 +160,7 @@ class SimpleImap { echo $val->attributes . "
\n"; } } else { - Summoner::sysLog("ERROR imap_getmailboxes failed: ".var_export(imap_last_error())); + Summoner::sysLog("ERROR imap_getmailboxes failed: ".Summoner::cleanForLog(imap_last_error())); } } } diff --git a/webroot/lib/snapshot.class.php b/webroot/lib/snapshot.class.php index 2e720ad..46b5280 100644 --- a/webroot/lib/snapshot.class.php +++ b/webroot/lib/snapshot.class.php @@ -63,10 +63,10 @@ class Snapshot { Summoner::sysLog("[DEBUG] try to save to $filename with $this->_googlePageSpeed for $url"); } $theCall = Summoner::curlCall($this->_googlePageSpeed.urlencode($url).'&screenshot=true'); - if(!empty($theCall)) { - $jsonData = json_decode($theCall,true); + if(!empty($theCall['status'])) { + $jsonData = json_decode($theCall['message'],true); if(DEBUG) { - Summoner::sysLog("[DEBUG] Call result data: ".var_export($jsonData, true)); + Summoner::sysLog("[DEBUG] Call result data: ".Summoner::cleanForLog($jsonData)); } if(!empty($jsonData) && isset($jsonData['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data'])) { $imageData = $jsonData['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data']; @@ -79,10 +79,10 @@ class Snapshot { fclose($source); fclose($destination); } elseif(DEBUG) { - Summoner::sysLog("[DEBUG] invalid json data. Path ['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data'] not found in : ".var_export($jsonData, true)); + Summoner::sysLog("[DEBUG] invalid json data. Path ['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data'] not found in : ".Summoner::cleanForLog($jsonData)); } } elseif(DEBUG) { - Summoner::sysLog("[DEBUG] curl call failed"); + Summoner::sysLog("[DEBUG] curl call failed ".Summoner::cleanForLog($theCall)); } } diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 3b1f2d4..fa9b292 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -134,10 +134,10 @@ class Summoner { * * @param string $url The request url * @param int $port - * @return string + * @return array */ - static function curlCall(string $url, int $port=0): string { - $ret = ''; + static function curlCall(string $url, int $port=0): array { + $ret = array('status' => false, 'message' => 'Unknown'); $ch = curl_init(); @@ -159,10 +159,11 @@ class Summoner { $do = curl_exec($ch); if(is_string($do) === true) { - $ret = $do; + $ret['status'] = true; + $ret['message'] = $do; } else { - self::sysLog('ERROR '.var_export(curl_error($ch),true)); + $ret['message'] = curl_error($ch); } curl_close($ch); @@ -231,8 +232,8 @@ class Summoner { if(self::validate($url,'url')) { $data = self::curlCall($url); - if(!empty($data)) { - $ret = self::socialMetaInfos($data); + if(!empty($data['status'])) { + $ret = self::socialMetaInfos($data['message']); } } @@ -565,10 +566,10 @@ class Summoner { /** * Make the input more safe for logging * - * @param string $input The string to be made more safe + * @param mixed $input The string to be made more safe * @return string */ - static function cleanForLog(string $input): string { + static function cleanForLog(mixed $input): string { $input = var_export($input, true); $input = preg_replace( "/[\t\n\r]/", " ", $input); return addcslashes($input, "\000..\037\177..\377\\"); diff --git a/webroot/lib/tag.class.php b/webroot/lib/tag.class.php index c8b35c9..f0b2a09 100644 --- a/webroot/lib/tag.class.php +++ b/webroot/lib/tag.class.php @@ -231,7 +231,7 @@ class Tag { $this->DB->query($queryStr); $this->DB->commit(); } catch (Exception $e) { - Summoner::sysLog('[ERROR] Failed to remove tag: '.var_export($e->getMessage(),true)); + Summoner::sysLog('[ERROR] Failed to remove tag: '.$e->getMessage()); $this->DB->rollback(); }