Replace Logger with DI::logger() in Core classes

This commit is contained in:
Art4 2025-01-13 09:39:19 +00:00
parent 8c89c37775
commit e3cf6b9c54
6 changed files with 43 additions and 43 deletions

View file

@ -117,7 +117,7 @@ class Addon
{ {
$addon = Strings::sanitizeFilePathItem($addon); $addon = Strings::sanitizeFilePathItem($addon);
Logger::debug("Addon {addon}: {action}", ['action' => 'uninstall', 'addon' => $addon]); DI::logger()->debug("Addon {addon}: {action}", ['action' => 'uninstall', 'addon' => $addon]);
DI::config()->delete('addons', $addon); DI::config()->delete('addons', $addon);
@include_once('addon/' . $addon . '/' . $addon . '.php'); @include_once('addon/' . $addon . '/' . $addon . '.php');
@ -150,7 +150,7 @@ class Addon
return false; return false;
} }
Logger::debug("Addon {addon}: {action}", ['action' => 'install', 'addon' => $addon]); DI::logger()->debug("Addon {addon}: {action}", ['action' => 'install', 'addon' => $addon]);
$t = @filemtime($addon_file_path); $t = @filemtime($addon_file_path);
@include_once($addon_file_path); @include_once($addon_file_path);
if (function_exists($addon . '_install')) { if (function_exists($addon . '_install')) {
@ -189,7 +189,7 @@ class Addon
continue; continue;
} }
Logger::debug("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $name]); DI::logger()->debug("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $name]);
self::uninstall($name); self::uninstall($name);
self::install($name); self::install($name);

View file

@ -8,6 +8,7 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
@ -123,7 +124,7 @@ class Protocol
if ($protocol == self::DIASPORA) { if ($protocol == self::DIASPORA) {
$contact = Diaspora::sendShare($owner, $contact); $contact = Diaspora::sendShare($owner, $contact);
Logger::notice('share returns: ' . $contact); DI::logger()->notice('share returns: ' . $contact);
} elseif (in_array($protocol, [self::ACTIVITYPUB, self::DFRN])) { } elseif (in_array($protocol, [self::ACTIVITYPUB, self::DFRN])) {
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact['id']); $activity_id = ActivityPub\Transmitter::activityIDFromContact($contact['id']);
if (empty($activity_id)) { if (empty($activity_id)) {
@ -132,7 +133,7 @@ class Protocol
} }
$success = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $owner['uid'], $activity_id); $success = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $owner['uid'], $activity_id);
Logger::notice('Follow returns: ' . $success); DI::logger()->notice('Follow returns: ' . $success);
} }
return true; return true;
@ -150,7 +151,7 @@ class Protocol
public static function unfollow(array $contact, array $owner): ?bool public static function unfollow(array $contact, array $owner): ?bool
{ {
if (empty($contact['network'])) { if (empty($contact['network'])) {
Logger::notice('Contact has got no network, we quit here', ['id' => $contact['id']]); DI::logger()->notice('Contact has got no network, we quit here', ['id' => $contact['id']]);
return null; return null;
} }

View file

@ -16,7 +16,6 @@ use Friendica\Network\HTTPException;
use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ContactResult;
use Friendica\Object\Search\ResultList; use Friendica\Object\Search\ResultList;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\Uri;
/** /**
@ -160,7 +159,7 @@ class Search
*/ */
public static function getContactsFromLocalDirectory(string $search, int $type = self::TYPE_ALL, int $start = 0, int $itemPage = 80): ResultList public static function getContactsFromLocalDirectory(string $search, int $type = self::TYPE_ALL, int $start = 0, int $itemPage = 80): ResultList
{ {
Logger::info('Searching', ['search' => $search, 'type' => $type, 'start' => $start, 'itempage' => $itemPage]); DI::logger()->info('Searching', ['search' => $search, 'type' => $type, 'start' => $start, 'itempage' => $itemPage]);
$contacts = Contact::searchByName($search, $type == self::TYPE_GROUP ? 'community' : '', true); $contacts = Contact::searchByName($search, $type == self::TYPE_GROUP ? 'community' : '', true);
@ -200,7 +199,7 @@ class Search
*/ */
public static function searchContact(string $search, string $mode, int $page = 1): array public static function searchContact(string $search, string $mode, int $page = 1): array
{ {
Logger::info('Searching', ['search' => $search, 'mode' => $mode, 'page' => $page]); DI::logger()->info('Searching', ['search' => $search, 'mode' => $mode, 'page' => $page]);
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) { if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
return []; return [];
@ -223,7 +222,7 @@ class Search
try { try {
$curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]); $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]);
} catch (\Throwable $th) { } catch (\Throwable $th) {
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
return []; return [];
} }
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {

View file

@ -322,7 +322,7 @@ class System
} }
if ($status) { if ($status) {
Logger::notice('xml_status returning non_zero: ' . $status . " message=" . $message); DI::logger()->notice('xml_status returning non_zero: ' . $status . " message=" . $message);
} }
self::httpExit(XML::fromArray(['result' => $result]), Response::TYPE_XML); self::httpExit(XML::fromArray(['result' => $result]), Response::TYPE_XML);
@ -340,7 +340,7 @@ class System
public static function httpError($httpCode, $message = '', $content = '') public static function httpError($httpCode, $message = '', $content = '')
{ {
if ($httpCode >= 400) { if ($httpCode >= 400) {
Logger::debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); DI::logger()->debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
} }
DI::apiResponse()->setStatus($httpCode, $message); DI::apiResponse()->setStatus($httpCode, $message);
@ -373,7 +373,7 @@ class System
public static function jsonError($httpCode, $content, $content_type = 'application/json') public static function jsonError($httpCode, $content, $content_type = 'application/json')
{ {
if ($httpCode >= 400) { if ($httpCode >= 400) {
Logger::debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); DI::logger()->debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
} }
DI::apiResponse()->setStatus($httpCode); DI::apiResponse()->setStatus($httpCode);
self::jsonExit($content, $content_type); self::jsonExit($content, $content_type);
@ -520,7 +520,7 @@ class System
public static function externalRedirect($url, $code = 302) public static function externalRedirect($url, $code = 302)
{ {
if (empty(parse_url($url, PHP_URL_SCHEME))) { if (empty(parse_url($url, PHP_URL_SCHEME))) {
Logger::warning('No fully qualified URL provided', ['url' => $url]); DI::logger()->warning('No fully qualified URL provided', ['url' => $url]);
DI::baseUrl()->redirect($url); DI::baseUrl()->redirect($url);
} }
@ -564,27 +564,27 @@ class System
private static function isDirectoryUsable(string $directory): bool private static function isDirectoryUsable(string $directory): bool
{ {
if (empty($directory)) { if (empty($directory)) {
Logger::warning('Directory is empty. This shouldn\'t happen.'); DI::logger()->warning('Directory is empty. This shouldn\'t happen.');
return false; return false;
} }
if (!file_exists($directory)) { if (!file_exists($directory)) {
Logger::info('Path does not exist', ['directory' => $directory, 'user' => static::getUser()]); DI::logger()->info('Path does not exist', ['directory' => $directory, 'user' => static::getUser()]);
return false; return false;
} }
if (is_file($directory)) { if (is_file($directory)) {
Logger::warning('Path is a file', ['directory' => $directory, 'user' => static::getUser()]); DI::logger()->warning('Path is a file', ['directory' => $directory, 'user' => static::getUser()]);
return false; return false;
} }
if (!is_dir($directory)) { if (!is_dir($directory)) {
Logger::warning('Path is not a directory', ['directory' => $directory, 'user' => static::getUser()]); DI::logger()->warning('Path is not a directory', ['directory' => $directory, 'user' => static::getUser()]);
return false; return false;
} }
if (!is_writable($directory)) { if (!is_writable($directory)) {
Logger::warning('Path is not writable', ['directory' => $directory, 'user' => static::getUser()]); DI::logger()->warning('Path is not writable', ['directory' => $directory, 'user' => static::getUser()]);
return false; return false;
} }

View file

@ -191,7 +191,7 @@ class Theme
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Logger::error('Theme installation failed', ['theme' => $theme, 'error' => $e->getMessage()]); DI::logger()->error('Theme installation failed', ['theme' => $theme, 'error' => $e->getMessage()]);
return false; return false;
} }
} }

View file

@ -178,7 +178,7 @@ class Update
// If the Lock is acquired, never release it automatically to avoid double updates // If the Lock is acquired, never release it automatically to avoid double updates
if (DI::lock()->acquire('dbupdate', 0, Cache\Enum\Duration::INFINITE)) { if (DI::lock()->acquire('dbupdate', 0, Cache\Enum\Duration::INFINITE)) {
Logger::notice('Update starting.', ['from' => $stored, 'to' => $current]); DI::logger()->notice('Update starting.', ['from' => $stored, 'to' => $current]);
// Checks if the build changed during Lock acquiring (so no double update occurs) // Checks if the build changed during Lock acquiring (so no double update occurs)
$retryBuild = DI::config()->get('system', 'build'); $retryBuild = DI::config()->get('system', 'build');
@ -192,7 +192,7 @@ class Update
} }
if ($retryBuild != $build) { if ($retryBuild != $build) {
Logger::notice('Update already done.', ['from' => $build, 'retry' => $retryBuild, 'to' => $current]); DI::logger()->notice('Update already done.', ['from' => $build, 'retry' => $retryBuild, 'to' => $current]);
DI::lock()->release('dbupdate'); DI::lock()->release('dbupdate');
return ''; return '';
} }
@ -202,12 +202,12 @@ class Update
// run the pre_update_nnnn functions in update.php // run the pre_update_nnnn functions in update.php
for ($version = $stored + 1; $version <= $current; $version++) { for ($version = $stored + 1; $version <= $current; $version++) {
Logger::notice('Execute pre update.', ['version' => $version]); DI::logger()->notice('Execute pre update.', ['version' => $version]);
DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: executing pre update %d', DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: executing pre update %d',
DateTimeFormat::utcNow() . ' ' . date('e'), $version)); DateTimeFormat::utcNow() . ' ' . date('e'), $version));
$r = self::runUpdateFunction($version, 'pre_update', $sendMail); $r = self::runUpdateFunction($version, 'pre_update', $sendMail);
if (!$r) { if (!$r) {
Logger::warning('Pre update failed', ['version' => $version]); DI::logger()->warning('Pre update failed', ['version' => $version]);
DI::config()->set('system', 'update', Update::FAILED); DI::config()->set('system', 'update', Update::FAILED);
DI::lock()->release('dbupdate'); DI::lock()->release('dbupdate');
DI::config()->beginTransaction() DI::config()->beginTransaction()
@ -216,12 +216,12 @@ class Update
->commit(); ->commit();
return $r; return $r;
} else { } else {
Logger::notice('Pre update executed.', ['version' => $version]); DI::logger()->notice('Pre update executed.', ['version' => $version]);
} }
} }
// update the structure in one call // update the structure in one call
Logger::notice('Execute structure update'); DI::logger()->notice('Execute structure update');
$retval = DBStructure::performUpdate(false, $verbose); $retval = DBStructure::performUpdate(false, $verbose);
if (!empty($retval)) { if (!empty($retval)) {
if ($sendMail) { if ($sendMail) {
@ -230,7 +230,7 @@ class Update
$retval $retval
); );
} }
Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]); DI::logger()->error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
DI::config()->set('system', 'update', Update::FAILED); DI::config()->set('system', 'update', Update::FAILED);
DI::lock()->release('dbupdate'); DI::lock()->release('dbupdate');
DI::config()->beginTransaction() DI::config()->beginTransaction()
@ -239,17 +239,17 @@ class Update
->commit(); ->commit();
return $retval; return $retval;
} else { } else {
Logger::notice('Database structure update finished.', ['from' => $stored, 'to' => $current]); DI::logger()->notice('Database structure update finished.', ['from' => $stored, 'to' => $current]);
} }
// run the update_nnnn functions in update.php // run the update_nnnn functions in update.php
for ($version = $stored + 1; $version <= $current; $version++) { for ($version = $stored + 1; $version <= $current; $version++) {
Logger::notice('Execute post update.', ['version' => $version]); DI::logger()->notice('Execute post update.', ['version' => $version]);
DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: executing post update %d', DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: executing post update %d',
DateTimeFormat::utcNow() . ' ' . date('e'), $version)); DateTimeFormat::utcNow() . ' ' . date('e'), $version));
$r = self::runUpdateFunction($version, 'update', $sendMail); $r = self::runUpdateFunction($version, 'update', $sendMail);
if (!$r) { if (!$r) {
Logger::warning('Post update failed', ['version' => $version]); DI::logger()->warning('Post update failed', ['version' => $version]);
DI::config()->set('system', 'update', Update::FAILED); DI::config()->set('system', 'update', Update::FAILED);
DI::lock()->release('dbupdate'); DI::lock()->release('dbupdate');
DI::config()->beginTransaction() DI::config()->beginTransaction()
@ -259,7 +259,7 @@ class Update
return $r; return $r;
} else { } else {
DI::config()->set('system', 'build', $version); DI::config()->set('system', 'build', $version);
Logger::notice('Post update executed.', ['version' => $version]); DI::logger()->notice('Post update executed.', ['version' => $version]);
} }
} }
@ -271,12 +271,12 @@ class Update
->delete('system', 'maintenance_reason') ->delete('system', 'maintenance_reason')
->commit(); ->commit();
Logger::notice('Update success.', ['from' => $stored, 'to' => $current]); DI::logger()->notice('Update success.', ['from' => $stored, 'to' => $current]);
if ($sendMail) { if ($sendMail) {
self::updateSuccessful($stored, $current); self::updateSuccessful($stored, $current);
} }
} else { } else {
Logger::warning('Update lock could not be acquired'); DI::logger()->warning('Update lock could not be acquired');
} }
} }
} }
@ -297,7 +297,7 @@ class Update
{ {
$funcname = $prefix . '_' . $version; $funcname = $prefix . '_' . $version;
Logger::notice('Update function start.', ['function' => $funcname]); DI::logger()->notice('Update function start.', ['function' => $funcname]);
if (function_exists($funcname)) { if (function_exists($funcname)) {
// There could be a lot of processes running or about to run. // There could be a lot of processes running or about to run.
@ -310,9 +310,9 @@ class Update
if (DI::lock()->acquire('dbupdate_function', 120, Cache\Enum\Duration::INFINITE)) { if (DI::lock()->acquire('dbupdate_function', 120, Cache\Enum\Duration::INFINITE)) {
// call the specific update // call the specific update
Logger::notice('Pre update function start.', ['function' => $funcname]); DI::logger()->notice('Pre update function start.', ['function' => $funcname]);
$retval = $funcname(); $retval = $funcname();
Logger::notice('Update function done.', ['function' => $funcname]); DI::logger()->notice('Update function done.', ['function' => $funcname]);
if ($retval) { if ($retval) {
if ($sendMail) { if ($sendMail) {
@ -322,20 +322,20 @@ class Update
DI::l10n()->t('Update %s failed. See error logs.', $version) DI::l10n()->t('Update %s failed. See error logs.', $version)
); );
} }
Logger::error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]); DI::logger()->error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]);
DI::lock()->release('dbupdate_function'); DI::lock()->release('dbupdate_function');
return false; return false;
} else { } else {
DI::lock()->release('dbupdate_function'); DI::lock()->release('dbupdate_function');
Logger::notice('Update function finished.', ['function' => $funcname]); DI::logger()->notice('Update function finished.', ['function' => $funcname]);
return true; return true;
} }
} else { } else {
Logger::error('Locking failed.', ['function' => $funcname]); DI::logger()->error('Locking failed.', ['function' => $funcname]);
return false; return false;
} }
} else { } else {
Logger::notice('Update function skipped.', ['function' => $funcname]); DI::logger()->notice('Update function skipped.', ['function' => $funcname]);
return true; return true;
} }
} }
@ -352,7 +352,7 @@ class Update
{ {
$adminEmails = User::getAdminListForEmailing(['uid', 'language', 'email']); $adminEmails = User::getAdminListForEmailing(['uid', 'language', 'email']);
if (!$adminEmails) { if (!$adminEmails) {
Logger::warning('Cannot notify administrators .', ['update' => $update_id, 'message' => $error_message]); DI::logger()->warning('Cannot notify administrators .', ['update' => $update_id, 'message' => $error_message]);
return; return;
} }
@ -376,7 +376,7 @@ class Update
DI::emailer()->send($email); DI::emailer()->send($email);
} }
Logger::alert('Database structure update failed.', ['error' => $error_message]); DI::logger()->alert('Database structure update failed.', ['error' => $error_message]);
} }
/** /**
@ -404,6 +404,6 @@ class Update
DI::emailer()->send($email); DI::emailer()->send($email);
} }
Logger::debug('Database structure update successful.'); DI::logger()->debug('Database structure update successful.');
} }
} }