]> git.mxchange.org Git - friendica.git/commitdiff
Improve Logger calls
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 23 Feb 2019 14:25:21 +0000 (09:25 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 23 Feb 2019 22:32:13 +0000 (17:32 -0500)
- Add context in various calls
- Remove deprecated Logger::log call in Processor

mod/item.php
src/Database/DBA.php
src/Model/Item.php
src/Model/Term.php
src/Protocol/ActivityPub/Processor.php

index 122f62c4e5d8eb8391da53172a83021ef9a6469c..b126c4825b6ef7a8ca83f517a9edc52f08352e9c 100644 (file)
@@ -1127,4 +1127,4 @@ function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $
        }
 
        return $tags;
-}
\ No newline at end of file
+}
index 326fb0771d99e8e5b1a91a8fa164f5569c0724a8..832f0a444f994684354267123a0f9ff6c8c39fed 100644 (file)
@@ -425,7 +425,7 @@ class DBA
 
                if ((substr_count($sql, '?') != count($args)) && (count($args) > 0)) {
                        // Question: Should we continue or stop the query here?
-                       Logger::error('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true));
+                       Logger::warning('Query parameters mismatch.', ['query' => $sql, 'args' => $args, 'callstack' => System::callstack()]);
                }
 
                $sql = self::cleanQuery($sql);
index e4d18c9a740b1ff864ce566d99cb71ba833446e7..16a3b07b53097e98ab3d52dccd693a1b9ce4f888 100644 (file)
@@ -1336,7 +1336,11 @@ class Item extends BaseObject
                        $expire_date = time() - ($expire_interval * 86400);
                        $created_date = strtotime($item['created']);
                        if ($created_date < $expire_date) {
-                               Logger::notice('item-store: item created ('.date('c', $created_date).') before expiration time ('.date('c', $expire_date).'). ignored. ' . print_r($item,true));
+                               Logger::notice('Item created before expiration interval.', [
+                                       'created' => date('c', $created_date),
+                                       'expired' => date('c', $expire_date),
+                                       '$item' => $item
+                               ]);
                                return 0;
                        }
                }
@@ -1354,7 +1358,13 @@ class Item extends BaseObject
                        if (DBA::isResult($existing)) {
                                // We only log the entries with a different user id than 0. Otherwise we would have too many false positives
                                if ($uid != 0) {
-                                       Logger::notice("Item with uri ".$item['uri']." already existed for user ".$uid." with id ".$existing["id"]." target network ".$existing["network"]." - new network: ".$item['network']);
+                                       Logger::notice('Item already existed for user', [
+                                               'uri' => $item['uri'],
+                                               'uid' => $uid,
+                                               'network' => $item['network'],
+                                               'existing_id' => $existing["id"],
+                                               'existing_network' => $existing["network"]
+                                       ]);
                                }
 
                                return $existing["id"];
@@ -1432,7 +1442,7 @@ class Item extends BaseObject
                $item['author-id'] = defaults($item, 'author-id', Contact::getIdForURL($item["author-link"], 0, false, $default));
 
                if (Contact::isBlocked($item["author-id"])) {
-                       Logger::notice('Contact '.$item["author-id"].' is blocked, item '.$item["uri"].' will not be stored');
+                       Logger::notice('Author is blocked node-wide', ['author-link' => $item["author-link"], 'item-uri' => $item["uri"]]);
                        return 0;
                }
 
@@ -1442,21 +1452,27 @@ class Item extends BaseObject
                $item['owner-id'] = defaults($item, 'owner-id', Contact::getIdForURL($item["owner-link"], 0, false, $default));
 
                if (Contact::isBlocked($item["owner-id"])) {
-                       Logger::notice('Contact '.$item["owner-id"].' is blocked, item '.$item["uri"].' will not be stored');
+                       Logger::notice('Owner is blocked node-wide', ['owner-link' => $item["owner-link"], 'item-uri' => $item["uri"]]);
                        return 0;
                }
 
                if ($item['network'] == Protocol::PHANTOM) {
-                       Logger::notice('Missing network. Called by: '.System::callstack(), Logger::DEBUG);
-
                        $item['network'] = Protocol::DFRN;
-                       Logger::notice("Set network to " . $item["network"] . " for " . $item["uri"], Logger::DEBUG);
+                       Logger::notice('Missing network, setting to {network}.', [
+                               'uri' => $item["uri"],
+                               'network' => $item['network'],
+                               'callstack' => System::callstack()
+                       ]);
                }
 
                // Checking if there is already an item with the same guid
                $condition = ['guid' => $item['guid'], 'network' => $item['network'], 'uid' => $item['uid']];
                if (self::exists($condition)) {
-                       Logger::notice('Found already existing item with guid '.$item['guid'].' for user '.$item['uid'].' on network '.$item['network']);
+                       Logger::notice('Found already existing item', [
+                               'guid' => $item['guid'],
+                               'uid' => $item['uid'],
+                               'network' => $item['network']
+                       ]);
                        return 0;
                }
 
index 5266627aca801a41b67ba389e2f80db78dda77ad..36876368dfabb1f468d30b7465fba681dba81ba4 100644 (file)
@@ -204,6 +204,8 @@ class Term
                                $type = self::HASHTAG;
                                $term = $tag;
                                $link = '';
+
+                               Logger::notice('Unknown term type', ['tag' => $tag]);
                        }
 
                        if (DBA::exists('term', ['uid' => $item['uid'], 'otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'term' => $term, 'type' => $type])) {
index b77df1fae86f338c213317df7ef2f4f126f4b8c7..2661444e0c56e34ac94ecd1df2351d5c64a9626d 100644 (file)
@@ -276,7 +276,7 @@ class Processor
                /// @todo What to do with $activity['context']?
 
                if (($item['gravity'] != GRAVITY_PARENT) && !Item::exists(['uri' => $item['thr-parent']])) {
-                       Logger::log('Parent ' . $item['thr-parent'] . ' not found, message will be discarded.', Logger::DEBUG);
+                       Logger::info('Parent not found, message will be discarded.', ['thr-parent' => $item['thr-parent']]);
                        return;
                }