mirror of
https://github.com/friendica/friendica
synced 2025-04-23 23:50:12 +00:00
Revert "Add monolog"
This commit is contained in:
parent
13e4dd0163
commit
2f49c4a058
18 changed files with 165 additions and 698 deletions
|
@ -55,8 +55,6 @@ define('API_METHOD_GET', 'GET');
|
|||
define('API_METHOD_POST', 'POST,PUT');
|
||||
define('API_METHOD_DELETE', 'POST,DELETE');
|
||||
|
||||
define('API_LOG_PREFIX', 'API {action} - ');
|
||||
|
||||
$API = [];
|
||||
$called_api = [];
|
||||
|
||||
|
@ -99,9 +97,9 @@ function api_source()
|
|||
return "Twidere";
|
||||
}
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'Unrecognized user-agent', ['module' => 'api', 'action' => 'source', 'http_user_agent' => $_SERVER['HTTP_USER_AGENT']]);
|
||||
Logger::log("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], Logger::DEBUG);
|
||||
} else {
|
||||
Logger::info(API_LOG_PREFIX . 'Empty user-agent', ['module' => 'api', 'action' => 'source']);
|
||||
Logger::log("Empty user-agent", Logger::DEBUG);
|
||||
}
|
||||
|
||||
return "api";
|
||||
|
@ -183,7 +181,7 @@ function api_login(App $a)
|
|||
var_dump($consumer, $token);
|
||||
die();
|
||||
} catch (Exception $e) {
|
||||
Logger::warning(API_LOG_PREFIX . 'error', ['module' => 'api', 'action' => 'login', 'exception' => $e->getMessage()]);
|
||||
Logger::log($e);
|
||||
}
|
||||
|
||||
// workaround for HTTP-auth in CGI mode
|
||||
|
@ -197,7 +195,7 @@ function api_login(App $a)
|
|||
}
|
||||
|
||||
if (empty($_SERVER['PHP_AUTH_USER'])) {
|
||||
Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]);
|
||||
Logger::log('API_login: ' . print_r($_SERVER, true), Logger::DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||
throw new UnauthorizedException("This API requires login");
|
||||
}
|
||||
|
@ -238,7 +236,7 @@ function api_login(App $a)
|
|||
}
|
||||
|
||||
if (!DBA::isResult($record)) {
|
||||
Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]);
|
||||
Logger::log('API_login failure: ' . print_r($_SERVER, true), Logger::DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||
//header('HTTP/1.0 401 Unauthorized');
|
||||
//die('This api requires login');
|
||||
|
@ -311,35 +309,33 @@ function api_call(App $a)
|
|||
api_login($a);
|
||||
}
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username']]);
|
||||
Logger::debug(API_LOG_PREFIX . 'parameters', ['module' => 'api', 'action' => 'call', 'parameters' => $_REQUEST]);
|
||||
Logger::log('API call for ' . $a->user['username'] . ': ' . $a->query_string);
|
||||
Logger::log('API parameters: ' . print_r($_REQUEST, true));
|
||||
|
||||
$stamp = microtime(true);
|
||||
$return = call_user_func($info['func'], $type);
|
||||
$duration = (float) (microtime(true) - $stamp);
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]);
|
||||
Logger::log("API call duration: " . round($duration, 2) . "\t" . $a->query_string, Logger::DEBUG);
|
||||
|
||||
if (Config::get("system", "profiler")) {
|
||||
$duration = microtime(true)-$a->performance["start"];
|
||||
|
||||
/// @TODO round() really everywhere?
|
||||
Logger::debug(
|
||||
API_LOG_PREFIX . 'performance',
|
||||
[
|
||||
'module' => 'api',
|
||||
'action' => 'call',
|
||||
'database_read' => round($a->performance["database"] - $a->performance["database_write"], 3),
|
||||
'database_write' => round($a->performance["database_write"], 3),
|
||||
'cache_read' => round($a->performance["cache"], 3),
|
||||
'cache_write' => round($a->performance["cache_write"], 3),
|
||||
'network_io' => round($a->performance["network"], 2),
|
||||
'file_io' => round($a->performance["file"], 2),
|
||||
'other_io' => round($duration - ($a->performance["database"]
|
||||
+ $a->performance["cache"] + $a->performance["cache_write"]
|
||||
+ $a->performance["network"] + $a->performance["file"]), 2),
|
||||
'total' => round($duration, 2)
|
||||
]
|
||||
Logger::log(
|
||||
parse_url($a->query_string, PHP_URL_PATH) . ": " . sprintf(
|
||||
"Database: %s/%s, Cache %s/%s, Network: %s, I/O: %s, Other: %s, Total: %s",
|
||||
round($a->performance["database"] - $a->performance["database_write"], 3),
|
||||
round($a->performance["database_write"], 3),
|
||||
round($a->performance["cache"], 3),
|
||||
round($a->performance["cache_write"], 3),
|
||||
round($a->performance["network"], 2),
|
||||
round($a->performance["file"], 2),
|
||||
round($duration - ($a->performance["database"]
|
||||
+ $a->performance["cache"] + $a->performance["cache_write"]
|
||||
+ $a->performance["network"] + $a->performance["file"]), 2),
|
||||
round($duration, 2)
|
||||
),
|
||||
Logger::DEBUG
|
||||
);
|
||||
|
||||
if (Config::get("rendertime", "callstack")) {
|
||||
|
@ -380,7 +376,7 @@ function api_call(App $a)
|
|||
$o .= $func . ": " . $time . "\n";
|
||||
}
|
||||
}
|
||||
Logger::debug(API_LOG_PREFIX . $o, ['module' => 'api', 'action' => 'call']);
|
||||
Logger::log($o, Logger::DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,7 +413,7 @@ function api_call(App $a)
|
|||
}
|
||||
}
|
||||
|
||||
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call']);
|
||||
Logger::log('API call not implemented: ' . $a->query_string);
|
||||
throw new NotImplementedException();
|
||||
} catch (HTTPException $e) {
|
||||
header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}");
|
||||
|
@ -526,7 +522,7 @@ function api_get_user(App $a, $contact_id = null)
|
|||
$extra_query = "";
|
||||
$url = "";
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'Fetching data for user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $contact_id]);
|
||||
Logger::log("api_get_user: Fetching user data for user ".$contact_id, Logger::DEBUG);
|
||||
|
||||
// Searching for contact URL
|
||||
if (!is_null($contact_id) && (intval($contact_id) == 0)) {
|
||||
|
@ -610,7 +606,7 @@ function api_get_user(App $a, $contact_id = null)
|
|||
}
|
||||
}
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'getting user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $user]);
|
||||
Logger::log("api_get_user: user ".$user, Logger::DEBUG);
|
||||
|
||||
if (!$user) {
|
||||
if (api_user() === false) {
|
||||
|
@ -622,7 +618,7 @@ function api_get_user(App $a, $contact_id = null)
|
|||
}
|
||||
}
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'found user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $user, 'extra_query' => $extra_query]);
|
||||
Logger::log('api_user: ' . $extra_query . ', user: ' . $user);
|
||||
|
||||
// user info
|
||||
$uinfo = q(
|
||||
|
@ -1941,7 +1937,7 @@ function api_conversation_show($type)
|
|||
$id = intval(defaults($a->argv, 4, 0));
|
||||
}
|
||||
|
||||
Logger::info(API_LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]);
|
||||
Logger::log('API: api_conversation_show: '.$id);
|
||||
|
||||
// try to fetch the item for the local user - or the public item, if there is no local one
|
||||
$item = Item::selectFirst(['parent-uri'], ['id' => $id]);
|
||||
|
@ -2335,7 +2331,7 @@ function api_favorites($type)
|
|||
|
||||
// in friendica starred item are private
|
||||
// return favorites only for self
|
||||
Logger::info(API_LOG_PREFIX . 'for {self}', ['module' => 'api', 'action' => 'favorites', 'self' => $user_info['self']]);
|
||||
Logger::log('api_favorites: self:' . $user_info['self']);
|
||||
|
||||
if ($user_info['self'] == 0) {
|
||||
$ret = [];
|
||||
|
@ -3698,7 +3694,7 @@ function api_friendships_destroy($type)
|
|||
$contact_id = defaults($_REQUEST, 'user_id');
|
||||
|
||||
if (empty($contact_id)) {
|
||||
Logger::notice(API_LOG_PREFIX . 'No user_id specified', ['module' => 'api', 'action' => 'friendships_destroy']);
|
||||
Logger::log("No user_id specified", Logger::DEBUG);
|
||||
throw new BadRequestException("no user_id specified");
|
||||
}
|
||||
|
||||
|
@ -3706,7 +3702,7 @@ function api_friendships_destroy($type)
|
|||
$contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => 0, 'self' => false]);
|
||||
|
||||
if(!DBA::isResult($contact)) {
|
||||
Logger::notice(API_LOG_PREFIX . 'No contact found for ID {contact}', ['module' => 'api', 'action' => 'friendships_destroy', 'contact' => $contact_id]);
|
||||
Logger::log("No contact found for ID" . $contact_id, Logger::DEBUG);
|
||||
throw new NotFoundException("no contact found to given ID");
|
||||
}
|
||||
|
||||
|
@ -3718,12 +3714,12 @@ function api_friendships_destroy($type)
|
|||
$contact = DBA::selectFirst('contact', [], $condition);
|
||||
|
||||
if (!DBA::isResult($contact)) {
|
||||
Logger::notice(API_LOG_PREFIX . 'Not following contact', ['module' => 'api', 'action' => 'friendships_destroy']);
|
||||
Logger::log("Not following Contact", Logger::DEBUG);
|
||||
throw new NotFoundException("Not following Contact");
|
||||
}
|
||||
|
||||
if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
|
||||
Logger::notice(API_LOG_PREFIX . 'Not supported for {network}', ['module' => 'api', 'action' => 'friendships_destroy', 'network' => $contact['network']]);
|
||||
Logger::log("Not supported", Logger::DEBUG);
|
||||
throw new ExpectationFailedException("Not supported");
|
||||
}
|
||||
|
||||
|
@ -3734,7 +3730,7 @@ function api_friendships_destroy($type)
|
|||
Contact::terminateFriendship($owner, $contact, $dissolve);
|
||||
}
|
||||
else {
|
||||
Logger::notice(API_LOG_PREFIX . 'No owner {uid} found', ['module' => 'api', 'action' => 'friendships_destroy', 'uid' => $uid]);
|
||||
Logger::log("No owner found", Logger::DEBUG);
|
||||
throw new NotFoundException("Error Processing Request");
|
||||
}
|
||||
|
||||
|
@ -4841,7 +4837,7 @@ function api_friendica_remoteauth()
|
|||
'sec' => $sec, 'expire' => time() + 45];
|
||||
DBA::insert('profile_check', $fields);
|
||||
|
||||
Logger::info(API_LOG_PREFIX . 'for contact {contact}', ['module' => 'api', 'action' => 'friendica_remoteauth', 'contact' => $contact['name'], 'hey' => $sec]);
|
||||
Logger::log($contact['name'] . ' ' . $sec, Logger::DEBUG);
|
||||
$dest = ($url ? '&destination_url=' . $url : '');
|
||||
|
||||
System::externalRedirect(
|
||||
|
@ -5090,7 +5086,7 @@ function api_in_reply_to($item)
|
|||
// https://github.com/friendica/friendica/issues/1010
|
||||
// This is a bugfix for that.
|
||||
if (intval($in_reply_to['status_id']) == intval($item['id'])) {
|
||||
Logger::warning(API_LOG_PREFIX . 'ID {id} is similar to reply-to {reply-to}', ['module' => 'api', 'action' => 'in_reply_to', 'id' => $item['id'], 'reply-to' => $in_reply_to['status_id']]);
|
||||
Logger::log('this message should never appear: id: '.$item['id'].' similar to reply-to: '.$in_reply_to['status_id'], Logger::DEBUG);
|
||||
$in_reply_to['status_id'] = null;
|
||||
$in_reply_to['user_id'] = null;
|
||||
$in_reply_to['status_id_str'] = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue