From ff162dfef23684c34d1166c9bda76d7d361ac1f5 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Tue, 1 Jan 2019 19:35:08 +0100 Subject: [PATCH] Replacing log usage --- include/api.php | 46 +++++++++++++++++++++++----------------------- mod/acl.php | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/api.php b/include/api.php index 2085c801b8..2586def0a7 100644 --- a/include/api.php +++ b/include/api.php @@ -181,7 +181,7 @@ function api_login(App $a) var_dump($consumer, $token); die(); } catch (Exception $e) { - $a->getLogger()->warning('API login: error', ['module' => 'api', 'action' => 'login', 'exception' => $e->getMessage()]); + Logger::warning('API {action}: error', ['module' => 'api', 'action' => 'login', 'exception' => $e->getMessage()]); } // workaround for HTTP-auth in CGI mode @@ -195,7 +195,7 @@ function api_login(App $a) } if (empty($_SERVER['PHP_AUTH_USER'])) { - $a->getLogger()->debug('API login: failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]); + Logger::debug('API {action}: failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]); header('WWW-Authenticate: Basic realm="Friendica"'); throw new UnauthorizedException("This API requires login"); } @@ -236,7 +236,7 @@ function api_login(App $a) } if (!DBA::isResult($record)) { - $a->getLogger()->debug('API login: failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]); + Logger::debug('API {action}: failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]); header('WWW-Authenticate: Basic realm="Friendica"'); //header('HTTP/1.0 401 Unauthorized'); //die('This api requires login'); @@ -309,24 +309,24 @@ function api_call(App $a) api_login($a); } - $a->getLogger()->info('API call', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username']]); - $a->getLogger()->debug('API parameters', ['module' => 'api', 'action' => 'call', 'parameters' => $_REQUEST]); + Logger::info('API {action}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username']]); + Logger::debug('API {action} parameters', ['module' => 'api', 'action' => 'call', 'parameters' => $_REQUEST]); $stamp = microtime(true); $return = call_user_func($info['func'], $type); $duration = (float) (microtime(true) - $stamp); - $a->getLogger()->info('API call', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); + Logger::info('API {action} for {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); if (Config::get("system", "profiler")) { $duration = microtime(true)-$a->performance["start"]; /// @TODO round() really everywhere? - $a->getLogger()->debug( - 'API call performance', + Logger::debug( + 'API {action} performance', [ 'module' => 'api', - 'action' => 'performance', + '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), @@ -378,7 +378,7 @@ function api_call(App $a) $o .= $func . ": " . $time . "\n"; } } - $a->getLogger()->debug($o, ['module' => 'api', 'action' => 'performance']); + Logger::debug($o, ['module' => 'api', 'action' => 'call']); } } @@ -415,7 +415,7 @@ function api_call(App $a) } } - $a->getLogger()->warning('API call not implemented'); + Logger::warning('API {action} not implemented', ['module' => 'api', 'action' => 'call']); throw new NotImplementedException(); } catch (HTTPException $e) { header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}"); @@ -524,7 +524,7 @@ function api_get_user(App $a, $contact_id = null) $extra_query = ""; $url = ""; - $a->getLogger()->info('api_get_user: Fetching user data', ['module' => 'api', 'action' => 'get_user', 'user' => $contact_id]); + Logger::info('API {action}: Fetching data for user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $contact_id]); // Searching for contact URL if (!is_null($contact_id) && (intval($contact_id) == 0)) { @@ -608,7 +608,7 @@ function api_get_user(App $a, $contact_id = null) } } - $a->getLogger()->info('api_get_user: getting user', ['module' => 'api', 'action' => 'get_user', 'user' => $user]); + Logger::info('API {action}: getting user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $user]); if (!$user) { if (api_user() === false) { @@ -620,7 +620,7 @@ function api_get_user(App $a, $contact_id = null) } } - $a->getLogger()->info('api_get_user: found user', ['module' => 'api', 'action' => 'get_user', 'user' => $user, 'extra_query' => $extra_query]); + Logger::info('API {action}: found user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $user, 'extra_query' => $extra_query]); // user info $uinfo = q( @@ -1939,7 +1939,7 @@ function api_conversation_show($type) $id = intval(defaults($a->argv, 4, 0)); } - $a->getLogger()->info('API: api_conversation_show', ['module' => 'api', 'action' => 'conversation', 'id' => $id]); + Logger::info('API: {action} - {subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $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]); @@ -2333,7 +2333,7 @@ function api_favorites($type) // in friendica starred item are private // return favorites only for self - $a->getLogger()->info('API: api_favorites', ['module' => 'api', 'action' => 'favorites', 'self' => $user_info['self']]); + Logger::info('API: {action}', ['module' => 'api', 'action' => 'favorites', 'self' => $user_info['self']]); if ($user_info['self'] == 0) { $ret = []; @@ -3697,7 +3697,7 @@ function api_friendships_destroy($type) $contact_id = defaults($_REQUEST, 'user_id'); if (empty($contact_id)) { - $a->getLogger()->notice('No user_id specified', ['module' => 'api', 'action' => 'friendships_destroy']); + Logger::notice('API {action} - No user_id specified', ['module' => 'api', 'action' => 'friendships_destroy']); throw new BadRequestException("no user_id specified"); } @@ -3705,7 +3705,7 @@ function api_friendships_destroy($type) $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => 0, 'self' => false]); if(!DBA::isResult($contact)) { - $a->getLogger()->notice('No contact found for ID', ['module' => 'api', 'action' => 'friendships_destroy', 'contact' => $contact_id]); + Logger::notice('API {action} - No contact found for ID {contact}', ['module' => 'api', 'action' => 'friendships_destroy', 'contact' => $contact_id]); throw new NotFoundException("no contact found to given ID"); } @@ -3717,12 +3717,12 @@ function api_friendships_destroy($type) $contact = DBA::selectFirst('contact', [], $condition); if (!DBA::isResult($contact)) { - $a->getLogger()->notice('Not following contact', ['module' => 'api', 'action' => 'friendships_destroy']); + Logger::notice('API {action} - Not following contact', ['module' => 'api', 'action' => 'friendships_destroy']); throw new NotFoundException("Not following Contact"); } if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { - $a->getLogger()->notice('Not supported', ['module' => 'api', 'action' => 'friendships_destroy', 'network' => $contact['network']]); + Logger::notice('API {action} - Not supported for {network}', ['module' => 'api', 'action' => 'friendships_destroy', 'network' => $contact['network']]); throw new ExpectationFailedException("Not supported"); } @@ -3733,7 +3733,7 @@ function api_friendships_destroy($type) Contact::terminateFriendship($owner, $contact, $dissolve); } else { - $a->getLogger()->notice('No owner found', ['module' => 'api', 'action' => 'friendships_destroy', 'uid' => $uid]); + Logger::notice('API {action} - No owner {uid} found', ['module' => 'api', 'action' => 'friendships_destroy', 'uid' => $uid]); throw new NotFoundException("Error Processing Request"); } @@ -4841,7 +4841,7 @@ function api_friendica_remoteauth() DBA::insert('profile_check', $fields); $a = get_app(); - $a->getLogger()->info('API: friendica_remoteauth', ['module' => 'api', 'action' => 'remoteauth', 'contact' => $contact['name'], 'hey' => $sec]); + Logger::info('API: {action}', ['module' => 'api', 'action' => 'friendica_remoteauth', 'contact' => $contact['name'], 'hey' => $sec]); $dest = ($url ? '&destination_url=' . $url : ''); System::externalRedirect( @@ -5091,7 +5091,7 @@ function api_in_reply_to($item) // This is a bugfix for that. if (intval($in_reply_to['status_id']) == intval($item['id'])) { $a = get_app(); - $a->getLogger()->warning('ID is similar to reply-to', ['module' => 'api', 'action' => 'in_reply_to', 'id' => $item['id'], 'reply-to' => $in_reply_to['status_id']]); + Logger::warning('API {action}: 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']]); $in_reply_to['status_id'] = null; $in_reply_to['user_id'] = null; $in_reply_to['status_id_str'] = null; diff --git a/mod/acl.php b/mod/acl.php index e7445a995b..03cb1ad63e 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -34,7 +34,7 @@ function acl_content(App $a) $search = $_REQUEST['query']; } - $a->getLogger()->info("Searching for " . $search . " - type " . $type . " conversation " . $conv_id); + Logger::info('ACL {action} - {subaction}', ['module' => 'acl', 'action' => 'content', 'subaction' => 'search', 'search' => $search, 'type' => $type, 'conversation' => $conv_id]); if ($search != '') { $sql_extra = "AND `name` LIKE '%%" . DBA::escape($search) . "%%'"; -- 2.39.5