Log function

implement log() function.
This commit is contained in:
Adam Magness 2018-10-29 17:20:46 -04:00
parent d6d593d724
commit 14fde5dc9b
122 changed files with 1280 additions and 1161 deletions

View file

@ -5,6 +5,7 @@
namespace Friendica\Protocol\ActivityPub;
use Friendica\Database\DBA;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Model\Conversation;
use Friendica\Model\Contact;
@ -140,7 +141,7 @@ class Processor
}
if (($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) {
logger('Parent ' . $activity['reply-to-id'] . ' not found. Try to refetch it.');
Logger::log('Parent ' . $activity['reply-to-id'] . ' not found. Try to refetch it.');
self::fetchMissingActivity($activity['reply-to-id'], $activity);
}
@ -158,7 +159,7 @@ class Processor
{
$owner = Contact::getIdForURL($activity['actor']);
logger('Deleting item ' . $activity['object_id'] . ' from ' . $owner, LOGGER_DEBUG);
Logger::log('Deleting item ' . $activity['object_id'] . ' from ' . $owner, LOGGER_DEBUG);
Item::delete(['uri' => $activity['object_id'], 'owner-id' => $owner]);
}
@ -211,7 +212,7 @@ class Processor
}
$event_id = Event::store($event);
logger('Event '.$event_id.' was stored', LOGGER_DEBUG);
Logger::log('Event '.$event_id.' was stored', LOGGER_DEBUG);
}
/**
@ -225,7 +226,7 @@ class Processor
/// @todo What to do with $activity['context']?
if (($item['gravity'] != GRAVITY_PARENT) && !Item::exists(['uri' => $item['parent-uri']])) {
logger('Parent ' . $item['parent-uri'] . ' not found, message will be discarded.', LOGGER_DEBUG);
Logger::log('Parent ' . $item['parent-uri'] . ' not found, message will be discarded.', LOGGER_DEBUG);
return;
}
@ -238,7 +239,7 @@ class Processor
$item['owner-link'] = $activity['actor'];
$item['owner-id'] = Contact::getIdForURL($activity['actor'], 0, true);
} else {
logger('Ignoring actor because of thread completion.', LOGGER_DEBUG);
Logger::log('Ignoring actor because of thread completion.', LOGGER_DEBUG);
$item['owner-link'] = $item['author-link'];
$item['owner-id'] = $item['author-id'];
}
@ -284,7 +285,7 @@ class Processor
}
$item_id = Item::insert($item);
logger('Storing for user ' . $item['uid'] . ': ' . $item_id);
Logger::log('Storing for user ' . $item['uid'] . ': ' . $item_id);
}
}
@ -302,7 +303,7 @@ class Processor
$object = ActivityPub::fetchContent($url);
if (empty($object)) {
logger('Activity ' . $url . ' was not fetchable, aborting.');
Logger::log('Activity ' . $url . ' was not fetchable, aborting.');
return;
}
@ -322,7 +323,7 @@ class Processor
$ldactivity['thread-completion'] = true;
ActivityPub\Receiver::processActivity($ldactivity);
logger('Activity ' . $url . ' had been fetched and processed.');
Logger::log('Activity ' . $url . ' had been fetched and processed.');
}
/**
@ -360,7 +361,7 @@ class Processor
}
DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]);
logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
Logger::log('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
}
/**
@ -374,7 +375,7 @@ class Processor
return;
}
logger('Updating profile for ' . $activity['object_id'], LOGGER_DEBUG);
Logger::log('Updating profile for ' . $activity['object_id'], LOGGER_DEBUG);
APContact::getByURL($activity['object_id'], true);
}
@ -386,12 +387,12 @@ class Processor
public static function deletePerson($activity)
{
if (empty($activity['object_id']) || empty($activity['actor'])) {
logger('Empty object id or actor.', LOGGER_DEBUG);
Logger::log('Empty object id or actor.', LOGGER_DEBUG);
return;
}
if ($activity['object_id'] != $activity['actor']) {
logger('Object id does not match actor.', LOGGER_DEBUG);
Logger::log('Object id does not match actor.', LOGGER_DEBUG);
return;
}
@ -401,7 +402,7 @@ class Processor
}
DBA::close($contacts);
logger('Deleted contact ' . $activity['object_id'], LOGGER_DEBUG);
Logger::log('Deleted contact ' . $activity['object_id'], LOGGER_DEBUG);
}
/**
@ -420,7 +421,7 @@ class Processor
$cid = Contact::getIdForURL($activity['actor'], $uid);
if (empty($cid)) {
logger('No contact found for ' . $activity['actor'], LOGGER_DEBUG);
Logger::log('No contact found for ' . $activity['actor'], LOGGER_DEBUG);
return;
}
@ -435,7 +436,7 @@ class Processor
$condition = ['id' => $cid];
DBA::update('contact', $fields, $condition);
logger('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG);
Logger::log('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG);
}
/**
@ -454,7 +455,7 @@ class Processor
$cid = Contact::getIdForURL($activity['actor'], $uid);
if (empty($cid)) {
logger('No contact found for ' . $activity['actor'], LOGGER_DEBUG);
Logger::log('No contact found for ' . $activity['actor'], LOGGER_DEBUG);
return;
}
@ -462,9 +463,9 @@ class Processor
if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) {
Contact::remove($cid);
logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', LOGGER_DEBUG);
Logger::log('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', LOGGER_DEBUG);
} else {
logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . '.', LOGGER_DEBUG);
Logger::log('Rejected contact request from contact ' . $cid . ' for user ' . $uid . '.', LOGGER_DEBUG);
}
}
@ -507,7 +508,7 @@ class Processor
$cid = Contact::getIdForURL($activity['actor'], $uid);
if (empty($cid)) {
logger('No contact found for ' . $activity['actor'], LOGGER_DEBUG);
Logger::log('No contact found for ' . $activity['actor'], LOGGER_DEBUG);
return;
}
@ -519,7 +520,7 @@ class Processor
}
Contact::removeFollower($owner, $contact);
logger('Undo following request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG);
Logger::log('Undo following request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG);
}
/**
@ -534,7 +535,7 @@ class Processor
return;
}
logger('Change existing contact ' . $cid . ' from ' . $contact['network'] . ' to ActivityPub.');
Logger::log('Change existing contact ' . $cid . ' from ' . $contact['network'] . ' to ActivityPub.');
Contact::updateFromProbe($cid, Protocol::ACTIVITYPUB);
}
}

View file

@ -6,6 +6,7 @@ namespace Friendica\Protocol\ActivityPub;
use Friendica\Database\DBA;
use Friendica\Util\HTTPSignature;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Model\Contact;
use Friendica\Model\APContact;
@ -59,16 +60,16 @@ class Receiver
{
$http_signer = HTTPSignature::getSigner($body, $header);
if (empty($http_signer)) {
logger('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG);
Logger::log('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG);
return;
} else {
logger('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG);
Logger::log('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG);
}
$activity = json_decode($body, true);
if (empty($activity)) {
logger('Invalid body.', LOGGER_DEBUG);
Logger::log('Invalid body.', LOGGER_DEBUG);
return;
}
@ -76,31 +77,31 @@ class Receiver
$actor = JsonLD::fetchElement($ldactivity, 'as:actor');
logger('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG);
Logger::log('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG);
if (LDSignature::isSigned($activity)) {
$ld_signer = LDSignature::getSigner($activity);
if (empty($ld_signer)) {
logger('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG);
Logger::log('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG);
}
if (!empty($ld_signer && ($actor == $http_signer))) {
logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
Logger::log('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
$trust_source = true;
} elseif (!empty($ld_signer)) {
logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
Logger::log('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
$trust_source = true;
} elseif ($actor == $http_signer) {
logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
Logger::log('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
$trust_source = true;
} else {
logger('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
Logger::log('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
$trust_source = false;
}
} elseif ($actor == $http_signer) {
logger('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG);
Logger::log('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG);
$trust_source = true;
} else {
logger('No JSON-LD signature, different actor.', LOGGER_DEBUG);
Logger::log('No JSON-LD signature, different actor.', LOGGER_DEBUG);
$trust_source = false;
}
@ -159,7 +160,7 @@ class Receiver
{
$actor = JsonLD::fetchElement($activity, 'as:actor');
if (empty($actor)) {
logger('Empty actor', LOGGER_DEBUG);
Logger::log('Empty actor', LOGGER_DEBUG);
return [];
}
@ -175,11 +176,11 @@ class Receiver
$receivers = array_merge($receivers, $additional);
}
logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
Logger::log('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
$object_id = JsonLD::fetchElement($activity, 'as:object');
if (empty($object_id)) {
logger('No object found', LOGGER_DEBUG);
Logger::log('No object found', LOGGER_DEBUG);
return [];
}
@ -192,7 +193,7 @@ class Receiver
}
$object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source);
if (empty($object_data)) {
logger("Object data couldn't be processed", LOGGER_DEBUG);
Logger::log("Object data couldn't be processed", LOGGER_DEBUG);
return [];
}
// We had been able to retrieve the object data - so we can trust the source
@ -229,7 +230,7 @@ class Receiver
$object_data['actor'] = $actor;
$object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers);
logger('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG);
Logger::log('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG);
return $object_data;
}
@ -272,17 +273,17 @@ class Receiver
{
$type = JsonLD::fetchElement($activity, '@type');
if (!$type) {
logger('Empty type', LOGGER_DEBUG);
Logger::log('Empty type', LOGGER_DEBUG);
return;
}
if (!JsonLD::fetchElement($activity, 'as:object')) {
logger('Empty object', LOGGER_DEBUG);
Logger::log('Empty object', LOGGER_DEBUG);
return;
}
if (!JsonLD::fetchElement($activity, 'as:actor')) {
logger('Empty actor', LOGGER_DEBUG);
Logger::log('Empty actor', LOGGER_DEBUG);
return;
}
@ -290,12 +291,12 @@ class Receiver
// $trust_source is called by reference and is set to true if the content was retrieved successfully
$object_data = self::prepareObjectData($activity, $uid, $trust_source);
if (empty($object_data)) {
logger('No object data found', LOGGER_DEBUG);
Logger::log('No object data found', LOGGER_DEBUG);
return;
}
if (!$trust_source) {
logger('No trust for activity type "' . $type . '", so we quit now.', LOGGER_DEBUG);
Logger::log('No trust for activity type "' . $type . '", so we quit now.', LOGGER_DEBUG);
return;
}
@ -384,7 +385,7 @@ class Receiver
break;
default:
logger('Unknown activity: ' . $type . ' ' . $object_data['object_type'], LOGGER_DEBUG);
Logger::log('Unknown activity: ' . $type . ' ' . $object_data['object_type'], LOGGER_DEBUG);
break;
}
}
@ -414,9 +415,9 @@ class Receiver
$profile = APContact::getByURL($actor);
$followers = defaults($profile, 'followers', '');
logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG);
Logger::log('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG);
} else {
logger('Empty actor', LOGGER_DEBUG);
Logger::log('Empty actor', LOGGER_DEBUG);
$followers = '';
}
@ -486,7 +487,7 @@ class Receiver
return;
}
logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
Logger::log('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
$photo = defaults($profile, 'photo', null);
unset($profile['photo']);
@ -500,7 +501,7 @@ class Receiver
// Send a new follow request to be sure that the connection still exists
if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
logger('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
Logger::log('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
}
}
@ -570,27 +571,27 @@ class Receiver
$data = ActivityPub::fetchContent($object_id);
if (!empty($data)) {
$object = JsonLD::compact($data);
logger('Fetched content for ' . $object_id, LOGGER_DEBUG);
Logger::log('Fetched content for ' . $object_id, LOGGER_DEBUG);
} else {
logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
$item = Item::selectFirst([], ['uri' => $object_id]);
if (!DBA::isResult($item)) {
logger('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
Logger::log('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
return false;
}
logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
Logger::log('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
$data = ActivityPub\Transmitter::createNote($item);
$object = JsonLD::compact($data);
}
} else {
logger('Using original object for url ' . $object_id, LOGGER_DEBUG);
Logger::log('Using original object for url ' . $object_id, LOGGER_DEBUG);
}
$type = JsonLD::fetchElement($object, '@type');
if (empty($type)) {
logger('Empty type', LOGGER_DEBUG);
Logger::log('Empty type', LOGGER_DEBUG);
return false;
}
@ -606,7 +607,7 @@ class Receiver
return self::fetchObject($object_id);
}
logger('Unhandled object type: ' . $type, LOGGER_DEBUG);
Logger::log('Unhandled object type: ' . $type, LOGGER_DEBUG);
}
/**

View file

@ -6,6 +6,7 @@ namespace Friendica\Protocol\ActivityPub;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Util\HTTPSignature;
use Friendica\Core\Protocol;
@ -1015,7 +1016,7 @@ class Transmitter
$signed = LDSignature::sign($data, $owner);
logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
return HTTPSignature::transmit($signed, $inbox, $uid);
}
@ -1044,7 +1045,7 @@ class Transmitter
$signed = LDSignature::sign($data, $owner);
logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
return HTTPSignature::transmit($signed, $inbox, $uid);
}
@ -1073,7 +1074,7 @@ class Transmitter
$signed = LDSignature::sign($data, $owner);
logger('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
Logger::log('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
return HTTPSignature::transmit($signed, $inbox, $uid);
}
@ -1098,7 +1099,7 @@ class Transmitter
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
'to' => $profile['url']];
logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
Logger::log('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
$signed = LDSignature::sign($data, $owner);
HTTPSignature::transmit($signed, $profile['inbox'], $uid);
@ -1126,7 +1127,7 @@ class Transmitter
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
'to' => $profile['url']];
logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
$signed = LDSignature::sign($data, $owner);
HTTPSignature::transmit($signed, $profile['inbox'], $uid);
@ -1154,7 +1155,7 @@ class Transmitter
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
'to' => $profile['url']];
logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
$signed = LDSignature::sign($data, $owner);
HTTPSignature::transmit($signed, $profile['inbox'], $uid);
@ -1183,7 +1184,7 @@ class Transmitter
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
'to' => $profile['url']];
logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
$signed = LDSignature::sign($data, $owner);
HTTPSignature::transmit($signed, $profile['inbox'], $uid);