Revert "Add monolog"
This commit is contained in:
parent
13e4dd0163
commit
2f49c4a058
18 changed files with 165 additions and 698 deletions
|
@ -34,7 +34,6 @@
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Util\ExAuth;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
|
||||
if (sizeof($_SERVER["argv"]) == 0) {
|
||||
die();
|
||||
|
@ -52,9 +51,7 @@ chdir($directory);
|
|||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$logger = LoggerFactory::create('auth_ejabberd');
|
||||
|
||||
$a = new App(dirname(__DIR__), $logger);
|
||||
$a = new App(dirname(__DIR__));
|
||||
|
||||
if ($a->getMode()->isNormal()) {
|
||||
$oAuth = new ExAuth();
|
||||
|
|
|
@ -3,11 +3,7 @@
|
|||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use Friendica\Util\LoggerFactory;
|
||||
|
||||
$logger = LoggerFactory::create('console');
|
||||
|
||||
$a = new Friendica\App(dirname(__DIR__), $logger);
|
||||
$a = new Friendica\App(dirname(__DIR__));
|
||||
\Friendica\BaseObject::setApp($a);
|
||||
|
||||
(new Friendica\Core\Console($argv))->execute();
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
|
||||
// Get options
|
||||
$shortopts = 'f';
|
||||
|
@ -32,9 +32,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
|||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$logger = LoggerFactory::create('daemon');
|
||||
|
||||
$a = new App(dirname(__DIR__), $logger);
|
||||
$a = new App(dirname(__DIR__));
|
||||
|
||||
if ($a->getMode()->isInstall()) {
|
||||
die("Friendica isn't properly installed yet.\n");
|
||||
|
@ -104,7 +102,7 @@ if ($mode == "stop") {
|
|||
|
||||
unlink($pidfile);
|
||||
|
||||
$logger->notice("Worker daemon process was killed", ["pid" => $pid]);
|
||||
Logger::log("Worker daemon process $pid was killed.", Logger::DEBUG);
|
||||
|
||||
Config::set('system', 'worker_daemon_mode', false);
|
||||
die("Worker daemon process $pid was killed.\n");
|
||||
|
@ -114,7 +112,7 @@ if (!empty($pid) && posix_kill($pid, 0)) {
|
|||
die("Daemon process $pid is already running.\n");
|
||||
}
|
||||
|
||||
$logger->notice('Starting worker daemon.', ["pid" => $pid]);
|
||||
Logger::log('Starting worker daemon.', Logger::DEBUG);
|
||||
|
||||
if (!$foreground) {
|
||||
echo "Starting worker daemon.\n";
|
||||
|
@ -162,7 +160,7 @@ $last_cron = 0;
|
|||
// Now running as a daemon.
|
||||
while (true) {
|
||||
if (!$do_cron && ($last_cron + $wait_interval) < time()) {
|
||||
$logger->info('Forcing cron worker call.', ["pid" => $pid]);
|
||||
Logger::log('Forcing cron worker call.', Logger::DEBUG);
|
||||
$do_cron = true;
|
||||
}
|
||||
|
||||
|
@ -176,7 +174,7 @@ while (true) {
|
|||
$last_cron = time();
|
||||
}
|
||||
|
||||
$logger->info("Sleeping", ["pid" => $pid]);
|
||||
Logger::log("Sleeping", Logger::DEBUG);
|
||||
$start = time();
|
||||
do {
|
||||
$seconds = (time() - $start);
|
||||
|
@ -193,10 +191,10 @@ while (true) {
|
|||
|
||||
if ($timeout) {
|
||||
$do_cron = true;
|
||||
$logger->info("Woke up after $wait_interval seconds.", ["pid" => $pid, 'sleep' => $wait_interval]);
|
||||
Logger::log("Woke up after $wait_interval seconds.", Logger::DEBUG);
|
||||
} else {
|
||||
$do_cron = false;
|
||||
$logger->info("Worker jobs are calling to be forked.", ["pid" => $pid]);
|
||||
Logger::log("Worker jobs are calling to be forked.", Logger::DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ use Friendica\App;
|
|||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Core\Update;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
|
||||
// Get options
|
||||
$shortopts = 'sn';
|
||||
|
@ -29,9 +28,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
|||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$logger = LoggerFactory::create('worker');
|
||||
|
||||
$a = new App(dirname(__DIR__), $logger);
|
||||
$a = new App(dirname(__DIR__));
|
||||
|
||||
// Check the database structure and possibly fixes it
|
||||
Update::check(true);
|
||||
|
|
|
@ -42,8 +42,7 @@
|
|||
"npm-asset/jgrowl": "^1.4",
|
||||
"npm-asset/fullcalendar": "^3.0.1",
|
||||
"npm-asset/cropperjs": "1.2.2",
|
||||
"npm-asset/imagesloaded": "4.1.4",
|
||||
"monolog/monolog": "^1.24"
|
||||
"npm-asset/imagesloaded": "4.1.4"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
|
|
128
composer.lock
generated
128
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "8cf7268fbcae8a22a518b9e7727eab84",
|
||||
"content-hash": "51f7b3ab622038d7ef62ed03c06b48d0",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asika/simple-console",
|
||||
|
@ -809,84 +809,6 @@
|
|||
],
|
||||
"time": "2018-09-01T15:05:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "1.24.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Seldaek/monolog.git",
|
||||
"reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266",
|
||||
"reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/log-implementation": "1.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
||||
"doctrine/couchdb": "~1.0@dev",
|
||||
"graylog2/gelf-php": "~1.0",
|
||||
"jakub-onderka/php-parallel-lint": "0.9",
|
||||
"php-amqplib/php-amqplib": "~2.4",
|
||||
"php-console/php-console": "^3.1.3",
|
||||
"phpunit/phpunit": "~4.5",
|
||||
"phpunit/phpunit-mock-objects": "2.3.0",
|
||||
"ruflin/elastica": ">=0.90 <3.0",
|
||||
"sentry/sentry": "^0.13",
|
||||
"swiftmailer/swiftmailer": "^5.3|^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
|
||||
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
|
||||
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
|
||||
"ext-mongo": "Allow sending log messages to a MongoDB server",
|
||||
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
|
||||
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
|
||||
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
|
||||
"php-console/php-console": "Allow sending log messages to Google Chrome",
|
||||
"rollbar/rollbar": "Allow sending log messages to Rollbar",
|
||||
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
|
||||
"sentry/sentry": "Allow sending log messages to a Sentry server"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Monolog\\": "src/Monolog"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jordi Boggiano",
|
||||
"email": "j.boggiano@seld.be",
|
||||
"homepage": "http://seld.be"
|
||||
}
|
||||
],
|
||||
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
|
||||
"homepage": "http://github.com/Seldaek/monolog",
|
||||
"keywords": [
|
||||
"log",
|
||||
"logging",
|
||||
"psr-3"
|
||||
],
|
||||
"time": "2018-11-05T09:00:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "npm-asset/cropperjs",
|
||||
"version": "1.2.2",
|
||||
|
@ -1888,53 +1810,6 @@
|
|||
],
|
||||
"time": "2016-08-06T14:39:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
"version": "1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/log.git",
|
||||
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
|
||||
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Log\\": "Psr/Log/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for logging libraries",
|
||||
"homepage": "https://github.com/php-fig/log",
|
||||
"keywords": [
|
||||
"log",
|
||||
"psr",
|
||||
"psr-3"
|
||||
],
|
||||
"time": "2018-11-20T15:27:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "seld/cli-prompt",
|
||||
"version": "1.0.3",
|
||||
|
@ -2606,6 +2481,7 @@
|
|||
"testing",
|
||||
"xunit"
|
||||
],
|
||||
"abandoned": true,
|
||||
"time": "2016-12-02T14:39:14+00:00"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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"]
|
||||
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),
|
||||
'total' => round($duration, 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;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
|
||||
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
|
||||
die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.');
|
||||
|
@ -13,10 +12,9 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
|
|||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$logger = LoggerFactory::create('index');
|
||||
|
||||
// We assume that the index.php is called by a frontend process
|
||||
// The value is set to "true" by default in App
|
||||
$a = new App(__DIR__, $logger, false);
|
||||
$a = new App(__DIR__, false);
|
||||
|
||||
$a->runFrontend();
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ function acl_content(App $a)
|
|||
$search = $_REQUEST['query'];
|
||||
}
|
||||
|
||||
Logger::info('ACL {action} - {subaction}', ['module' => 'acl', 'action' => 'content', 'subaction' => 'search', 'search' => $search, 'type' => $type, 'conversation' => $conv_id]);
|
||||
Logger::log("Searching for ".$search." - type ".$type." conversation ".$conv_id, Logger::DEBUG);
|
||||
|
||||
if ($search != '') {
|
||||
$sql_extra = "AND `name` LIKE '%%" . DBA::escape($search) . "%%'";
|
||||
|
|
29
src/App.php
29
src/App.php
|
@ -8,10 +8,8 @@ use Detection\MobileDetect;
|
|||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use Exception;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -108,11 +106,6 @@ class App
|
|||
*/
|
||||
public $mobileDetect;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface The current logger of this App
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* Register a stylesheet file path to be included in the <head> tag of every page.
|
||||
* Inclusion is done in App->initHead().
|
||||
|
@ -154,15 +147,12 @@ class App
|
|||
* @brief App constructor.
|
||||
*
|
||||
* @param string $basePath Path to the app base folder
|
||||
* @param LoggerInterface $logger Logger of this application
|
||||
* @param bool $isBackend Whether it is used for backend or frontend (Default true=backend)
|
||||
*
|
||||
* @throws Exception if the Basepath is not usable
|
||||
*/
|
||||
public function __construct($basePath, LoggerInterface $logger, $isBackend = true)
|
||||
public function __construct($basePath, $isBackend = true)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
if (!static::isDirectoryUsable($basePath, false)) {
|
||||
throw new Exception('Basepath ' . $basePath . ' isn\'t usable.');
|
||||
}
|
||||
|
@ -311,21 +301,6 @@ class App
|
|||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Logger of the Application
|
||||
*
|
||||
* @return LoggerInterface The Logger
|
||||
* @throws InternalServerErrorException when the logger isn't created
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
if (empty($this->logger)) {
|
||||
throw new InternalServerErrorException('Logger of the Application is not defined');
|
||||
}
|
||||
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the whole app instance
|
||||
*/
|
||||
|
@ -353,8 +328,6 @@ class App
|
|||
Core\L10n::init();
|
||||
|
||||
$this->process_id = Core\System::processID('log');
|
||||
|
||||
Core\Logger::setLogger($this->logger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,8 +6,6 @@ namespace Friendica;
|
|||
|
||||
require_once 'boot.php';
|
||||
|
||||
use Friendica\Util\LoggerFactory;
|
||||
|
||||
/**
|
||||
* Basic object
|
||||
*
|
||||
|
@ -27,8 +25,7 @@ class BaseObject
|
|||
public static function getApp()
|
||||
{
|
||||
if (empty(self::$app)) {
|
||||
$logger = $logger = LoggerFactory::create('app');
|
||||
self::$app = new App(dirname(__DIR__), $logger);
|
||||
self::$app = new App(dirname(__DIR__));
|
||||
}
|
||||
|
||||
return self::$app;
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
*/
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
/**
|
||||
|
@ -74,7 +76,7 @@ class Addon extends BaseObject
|
|||
*/
|
||||
public static function uninstall($addon)
|
||||
{
|
||||
Logger::notice("Addon {addon}: {action}", ['action' => 'uninstall', 'addon' => $addon]);
|
||||
Logger::log("Addons: uninstalling " . $addon);
|
||||
DBA::delete('addon', ['name' => $addon]);
|
||||
|
||||
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
||||
|
@ -99,7 +101,7 @@ class Addon extends BaseObject
|
|||
if (!file_exists('addon/' . $addon . '/' . $addon . '.php')) {
|
||||
return false;
|
||||
}
|
||||
Logger::notice("Addon {addon}: {action}", ['action' => 'install', 'addon' => $addon]);
|
||||
Logger::log("Addons: installing " . $addon);
|
||||
$t = @filemtime('addon/' . $addon . '/' . $addon . '.php');
|
||||
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
||||
if (function_exists($addon . '_install')) {
|
||||
|
@ -124,7 +126,7 @@ class Addon extends BaseObject
|
|||
}
|
||||
return true;
|
||||
} else {
|
||||
Logger::error("Addon {addon}: {action} failed", ['action' => 'uninstall', 'addon' => $addon]);
|
||||
Logger::log("Addons: FAILED installing " . $addon);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -154,8 +156,7 @@ class Addon extends BaseObject
|
|||
$t = @filemtime($fname);
|
||||
foreach ($installed as $i) {
|
||||
if (($i['name'] == $addon) && ($i['timestamp'] != $t)) {
|
||||
|
||||
Logger::notice("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $i['name']]);
|
||||
Logger::log('Reloading addon: ' . $i['name']);
|
||||
@include_once($fname);
|
||||
|
||||
if (function_exists($addon . '_uninstall')) {
|
||||
|
|
|
@ -5,47 +5,23 @@
|
|||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @brief Logger functions
|
||||
*/
|
||||
class Logger extends BaseObject
|
||||
{
|
||||
/**
|
||||
* @see Logger::error()
|
||||
*/
|
||||
const WARNING = LogLevel::ERROR;
|
||||
/**
|
||||
* @see Logger::warning()
|
||||
*/
|
||||
const INFO = LogLevel::WARNING;
|
||||
/**
|
||||
* @see Logger::notice()
|
||||
*/
|
||||
const TRACE = LogLevel::NOTICE;
|
||||
/**
|
||||
* @see Logger::info()
|
||||
*/
|
||||
const DEBUG = LogLevel::INFO;
|
||||
/**
|
||||
* @see Logger::debug()
|
||||
*/
|
||||
const DATA = LogLevel::DEBUG;
|
||||
/**
|
||||
* @see Logger::debug()
|
||||
*/
|
||||
const ALL = LogLevel::DEBUG;
|
||||
// Log levels:
|
||||
const WARNING = 0;
|
||||
const INFO = 1;
|
||||
const TRACE = 2;
|
||||
const DEBUG = 3;
|
||||
const DATA = 4;
|
||||
const ALL = 5;
|
||||
|
||||
/**
|
||||
* @var array the legacy loglevels
|
||||
* @deprecated 2019.03 use PSR-3 loglevels
|
||||
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
|
||||
*
|
||||
*/
|
||||
public static $levels = [
|
||||
self::WARNING => 'Warning',
|
||||
self::INFO => 'Info',
|
||||
|
@ -55,247 +31,56 @@ class Logger extends BaseObject
|
|||
self::ALL => 'All',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var LoggerInterface A PSR-3 compliant logger instance
|
||||
*/
|
||||
private static $logger;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface A PSR-3 compliant logger instance for developing only
|
||||
*/
|
||||
private static $devLogger;
|
||||
|
||||
/**
|
||||
* Sets the default logging handler for Friendica.
|
||||
* @todo Can be combined with other handlers too if necessary, could be configurable.
|
||||
*
|
||||
* @param LoggerInterface $logger The Logger instance of this Application
|
||||
*
|
||||
* @throws InternalServerErrorException if the logger factory is incompatible to this logger
|
||||
*/
|
||||
public static function setLogger($logger)
|
||||
{
|
||||
$debugging = Config::get('system', 'debugging');
|
||||
$logfile = Config::get('system', 'logfile');
|
||||
$loglevel = intval(Config::get('system', 'loglevel'));
|
||||
|
||||
if (!$debugging || !$logfile) {
|
||||
return;
|
||||
}
|
||||
|
||||
$level = self::mapPSR3Level($loglevel);
|
||||
LoggerFactory::addStreamHandler($logger, $logfile, $level);
|
||||
|
||||
self::$logger = $logger;
|
||||
|
||||
$logfile = Config::get('system', 'dlogfile');
|
||||
|
||||
if (!$logfile) {
|
||||
return;
|
||||
}
|
||||
|
||||
$developIp = Config::get('system', 'dlogip');
|
||||
|
||||
self::$devLogger = LoggerFactory::createDev('develop', $developIp);
|
||||
LoggerFactory::addStreamHandler(self::$devLogger, $logfile, LogLevel::DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* System is unusable.
|
||||
* @see LoggerInterface::emergency()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function emergency($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->emergency($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Action must be taken immediately.
|
||||
* @see LoggerInterface::alert()
|
||||
*
|
||||
* Example: Entire website down, database unavailable, etc. This should
|
||||
* trigger the SMS alerts and wake you up.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function alert($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->alert($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Critical conditions.
|
||||
* @see LoggerInterface::critical()
|
||||
*
|
||||
* Example: Application component unavailable, unexpected exception.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function critical($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->critical($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime errors that do not require immediate action but should typically
|
||||
* be logged and monitored.
|
||||
* @see LoggerInterface::error()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function error($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
echo "not set!?\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->error($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptional occurrences that are not errors.
|
||||
* @see LoggerInterface::warning()
|
||||
*
|
||||
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
||||
* that are not necessarily wrong.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function warning($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->warning($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal but significant events.
|
||||
* @see LoggerInterface::notice()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function notice($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->notice($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Interesting events.
|
||||
* @see LoggerInterface::info()
|
||||
*
|
||||
* Example: User logs in, SQL logs.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public static function info($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->info($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed debug information.
|
||||
* @see LoggerInterface::debug()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function debug($message, $context = [])
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->debug($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logs the given message at the given log level
|
||||
*
|
||||
* @param string $msg
|
||||
* @param int $level
|
||||
*
|
||||
* @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead
|
||||
*/
|
||||
public static function log($msg, $level = LogLevel::NOTICE)
|
||||
public static function log($msg, $level = self::INFO)
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
$a = self::getApp();
|
||||
|
||||
$debugging = Config::get('system', 'debugging');
|
||||
$logfile = Config::get('system', 'logfile');
|
||||
$loglevel = intval(Config::get('system', 'loglevel'));
|
||||
|
||||
if (
|
||||
!$debugging
|
||||
|| !$logfile
|
||||
|| $level > $loglevel
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$processId = session_id();
|
||||
|
||||
if ($processId == '')
|
||||
{
|
||||
$processId = $a->process_id;
|
||||
}
|
||||
|
||||
$callers = debug_backtrace();
|
||||
|
||||
if (count($callers) > 1) {
|
||||
$function = $callers[1]['function'];
|
||||
} else {
|
||||
$function = '';
|
||||
}
|
||||
|
||||
$logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
|
||||
DateTimeFormat::utcNow(DateTimeFormat::ATOM),
|
||||
$processId,
|
||||
self::$levels[$level],
|
||||
basename($callers[0]['file']),
|
||||
$callers[0]['line'],
|
||||
$function,
|
||||
$msg
|
||||
);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->log($level, $msg);
|
||||
self::getApp()->saveTimestamp($stamp1, "file");
|
||||
@file_put_contents($logfile, $logline, FILE_APPEND);
|
||||
$a->saveTimestamp($stamp1, "file");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,16 +90,47 @@ class Logger extends BaseObject
|
|||
* personally without background noise
|
||||
*
|
||||
* @param string $msg
|
||||
* @param string $level
|
||||
*/
|
||||
public static function devLog($msg, $level = LogLevel::DEBUG)
|
||||
public static function devLog($msg)
|
||||
{
|
||||
if (!isset(self::$logger)) {
|
||||
$a = self::getApp();
|
||||
|
||||
$logfile = Config::get('system', 'dlogfile');
|
||||
|
||||
if (!$logfile) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dlogip = Config::get('system', 'dlogip');
|
||||
|
||||
if (!is_null($dlogip) && $_SERVER['REMOTE_ADDR'] != $dlogip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$processId = session_id();
|
||||
|
||||
if ($processId == '')
|
||||
{
|
||||
$processId = $a->process_id;
|
||||
}
|
||||
|
||||
if (!is_string($msg)) {
|
||||
$msg = var_export($msg, true);
|
||||
}
|
||||
|
||||
$callers = debug_backtrace();
|
||||
$logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
|
||||
DateTimeFormat::utcNow(),
|
||||
$processId,
|
||||
basename($callers[0]['file']),
|
||||
$callers[0]['line'],
|
||||
$callers[1]['function'],
|
||||
$msg
|
||||
);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
self::$devLogger->log($level, $msg);
|
||||
self::getApp()->saveTimestamp($stamp1, "file");
|
||||
@file_put_contents($logfile, $logline, FILE_APPEND);
|
||||
$a->saveTimestamp($stamp1, "file");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Util\Logger;
|
||||
|
||||
use Monolog\Handler;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Simple handler for Friendica developers to use for deeper logging
|
||||
*
|
||||
* If you want to debug only interactions from your IP or the IP of a remote server for federation debug,
|
||||
* you'll use Logger::develop() for the duration of your work, and you clean it up when you're done before submitting your PR.
|
||||
*/
|
||||
class FriendicaDevelopHandler extends Handler\AbstractHandler
|
||||
{
|
||||
/**
|
||||
* @var string The IP of the developer who wants to debug
|
||||
*/
|
||||
private $developerIp;
|
||||
|
||||
/**
|
||||
* @param string $developerIp The IP of the developer who wants to debug
|
||||
* @param int $level The minimum logging level at which this handler will be triggered
|
||||
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
||||
*/
|
||||
public function __construct($developerIp, $level = Logger::DEBUG, $bubble = true)
|
||||
{
|
||||
parent::__construct($level, $bubble);
|
||||
|
||||
$this->developerIp = $developerIp;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(array $record)
|
||||
{
|
||||
if (!$this->isHandling($record)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Just in case the remote IP is the same as the developer IP log the output
|
||||
if (!is_null($this->developerIp) && $_SERVER['REMOTE_ADDR'] != $this->developerIp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false === $this->bubble;
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Util;
|
||||
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Logger\FriendicaDevelopHandler;
|
||||
use Monolog;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
/**
|
||||
* A logger factory
|
||||
*
|
||||
* Currently only Monolog is supported
|
||||
*/
|
||||
class LoggerFactory
|
||||
{
|
||||
/**
|
||||
* Creates a new PSR-3 compliant logger instances
|
||||
*
|
||||
* @param string $channel The channel of the logger instance
|
||||
*
|
||||
* @return LoggerInterface The PSR-3 compliant logger instance
|
||||
*/
|
||||
public static function create($channel)
|
||||
{
|
||||
$logger = new Monolog\Logger($channel);
|
||||
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
|
||||
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
|
||||
|
||||
// Add more information in case of a warning and more
|
||||
$logger->pushProcessor(new Monolog\Processor\IntrospectionProcessor(LogLevel::WARNING, [], 1));
|
||||
|
||||
return $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PSR-3 compliant develop logger
|
||||
*
|
||||
* If you want to debug only interactions from your IP or the IP of a remote server for federation debug,
|
||||
* you'll use this logger instance for the duration of your work.
|
||||
*
|
||||
* It should never get filled during normal usage of Friendica
|
||||
*
|
||||
* @param string $channel The channel of the logger instance
|
||||
* @param string $developerIp The IP of the developer who wants to use the logger
|
||||
*
|
||||
* @return LoggerInterface The PSR-3 compliant logger instance
|
||||
*/
|
||||
public static function createDev($channel, $developerIp)
|
||||
{
|
||||
$logger = new Monolog\Logger($channel);
|
||||
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
|
||||
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
|
||||
|
||||
$logger->pushProcessor(new Monolog\Processor\IntrospectionProcessor(Loglevel::DEBUG, [], 1));
|
||||
|
||||
$logger->pushHandler(new FriendicaDevelopHandler($developerIp));
|
||||
|
||||
return $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding a handler to a given logger instance
|
||||
*
|
||||
* @param LoggerInterface $logger The logger instance
|
||||
* @param mixed $stream The stream which handles the logger output
|
||||
* @param string $level The level, for which this handler at least should handle logging
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InternalServerErrorException if the logger is incompatible to the logger factory
|
||||
* @throws \Exception in case of general failures
|
||||
*/
|
||||
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
|
||||
{
|
||||
if ($logger instanceof Monolog\Logger) {
|
||||
$fileHandler = new Monolog\Handler\StreamHandler($stream, Monolog\Logger::toMonologLevel($level));
|
||||
|
||||
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
||||
$fileHandler->setFormatter($formatter);
|
||||
|
||||
$logger->pushHandler($fileHandler);
|
||||
} else {
|
||||
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method enables the test mode of a given logger
|
||||
*
|
||||
* @param LoggerInterface $logger The logger
|
||||
*
|
||||
* @return Monolog\Handler\TestHandler the Handling for tests
|
||||
*
|
||||
* @throws InternalServerErrorException if the logger is incompatible to the logger factory
|
||||
*/
|
||||
public static function enableTest($logger)
|
||||
{
|
||||
if ($logger instanceof Monolog\Logger) {
|
||||
// disable every handler so far
|
||||
$logger->pushHandler(new Monolog\Handler\NullHandler());
|
||||
|
||||
// enable the test handler
|
||||
$fileHandler = new Monolog\Handler\TestHandler();
|
||||
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
||||
$fileHandler->setFormatter($formatter);
|
||||
|
||||
$logger->pushHandler($fileHandler);
|
||||
|
||||
return $fileHandler;
|
||||
} else {
|
||||
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,8 +11,6 @@ use Friendica\Core\PConfig;
|
|||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
use Monolog\Handler\TestHandler;
|
||||
|
||||
require_once __DIR__ . '/../../include/api.php';
|
||||
|
||||
|
@ -24,11 +22,6 @@ require_once __DIR__ . '/../../include/api.php';
|
|||
*/
|
||||
class ApiTest extends DatabaseTest
|
||||
{
|
||||
/**
|
||||
* @var TestHandler Can handle log-outputs
|
||||
*/
|
||||
protected $logOutput;
|
||||
|
||||
/**
|
||||
* Create variables used by tests.
|
||||
*/
|
||||
|
@ -37,7 +30,6 @@ class ApiTest extends DatabaseTest
|
|||
parent::setUp();
|
||||
|
||||
$this->app = BaseObject::getApp();
|
||||
$this->logOutput = LoggerFactory::enableTest($this->app->getLogger());
|
||||
|
||||
// User data that the test database is populated with
|
||||
$this->selfUser = [
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Friendica\Test;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Util\LoggerFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
|
@ -39,9 +38,7 @@ class BaseObjectTest extends TestCase
|
|||
*/
|
||||
public function testSetApp()
|
||||
{
|
||||
$logger = $logger = LoggerFactory::create('test');
|
||||
$app = new App(__DIR__ . '/../../', $logger);
|
||||
LoggerFactory::enableTest($logger);
|
||||
$app = new App(__DIR__ . '/../../');
|
||||
$this->assertNull($this->baseObject->setApp($app));
|
||||
$this->assertEquals($app, $this->baseObject->getApp());
|
||||
}
|
||||
|
|
|
@ -332,8 +332,8 @@ function update_1298()
|
|||
$fail++;
|
||||
} else {
|
||||
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
|
||||
Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
|
||||
'was' => $data[$translateKey]]);
|
||||
logger::log('Updated contact ' . $data['id'] . " to $translateKey " . $key .
|
||||
' (was: ' . $data[$translateKey] . ')');
|
||||
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
|
||||
Contact::updateSelfFromUserID($data['id']);
|
||||
GContact::updateForUser($data['id']);
|
||||
|
@ -342,7 +342,7 @@ function update_1298()
|
|||
}
|
||||
}
|
||||
|
||||
Logger::notice($translateKey . " fix completed", ['action' => 'update', 'translateKey' => $translateKey, 'Success' => $success, 'Fail' => $fail ]);
|
||||
Logger::log($translateKey . " fix completed. Success: $success. Fail: $fail");
|
||||
}
|
||||
return Update::SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue