mirror of
https://github.com/friendica/friendica
synced 2024-12-23 03:20:15 +00:00
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\App;
|
||||||
use Friendica\Util\ExAuth;
|
use Friendica\Util\ExAuth;
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
|
|
||||||
if (sizeof($_SERVER["argv"]) == 0) {
|
if (sizeof($_SERVER["argv"]) == 0) {
|
||||||
die();
|
die();
|
||||||
|
@ -52,9 +51,7 @@ chdir($directory);
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$logger = LoggerFactory::create('auth_ejabberd');
|
$a = new App(dirname(__DIR__));
|
||||||
|
|
||||||
$a = new App(dirname(__DIR__), $logger);
|
|
||||||
|
|
||||||
if ($a->getMode()->isNormal()) {
|
if ($a->getMode()->isNormal()) {
|
||||||
$oAuth = new ExAuth();
|
$oAuth = new ExAuth();
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
use Friendica\Util\LoggerFactory;
|
$a = new Friendica\App(dirname(__DIR__));
|
||||||
|
|
||||||
$logger = LoggerFactory::create('console');
|
|
||||||
|
|
||||||
$a = new Friendica\App(dirname(__DIR__), $logger);
|
|
||||||
\Friendica\BaseObject::setApp($a);
|
\Friendica\BaseObject::setApp($a);
|
||||||
|
|
||||||
(new Friendica\Core\Console($argv))->execute();
|
(new Friendica\Core\Console($argv))->execute();
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
$shortopts = 'f';
|
$shortopts = 'f';
|
||||||
|
@ -32,9 +32,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$logger = LoggerFactory::create('daemon');
|
$a = new App(dirname(__DIR__));
|
||||||
|
|
||||||
$a = new App(dirname(__DIR__), $logger);
|
|
||||||
|
|
||||||
if ($a->getMode()->isInstall()) {
|
if ($a->getMode()->isInstall()) {
|
||||||
die("Friendica isn't properly installed yet.\n");
|
die("Friendica isn't properly installed yet.\n");
|
||||||
|
@ -104,7 +102,7 @@ if ($mode == "stop") {
|
||||||
|
|
||||||
unlink($pidfile);
|
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);
|
Config::set('system', 'worker_daemon_mode', false);
|
||||||
die("Worker daemon process $pid was killed.\n");
|
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");
|
die("Daemon process $pid is already running.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger->notice('Starting worker daemon.', ["pid" => $pid]);
|
Logger::log('Starting worker daemon.', Logger::DEBUG);
|
||||||
|
|
||||||
if (!$foreground) {
|
if (!$foreground) {
|
||||||
echo "Starting worker daemon.\n";
|
echo "Starting worker daemon.\n";
|
||||||
|
@ -162,7 +160,7 @@ $last_cron = 0;
|
||||||
// Now running as a daemon.
|
// Now running as a daemon.
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!$do_cron && ($last_cron + $wait_interval) < time()) {
|
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;
|
$do_cron = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +174,7 @@ while (true) {
|
||||||
$last_cron = time();
|
$last_cron = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger->info("Sleeping", ["pid" => $pid]);
|
Logger::log("Sleeping", Logger::DEBUG);
|
||||||
$start = time();
|
$start = time();
|
||||||
do {
|
do {
|
||||||
$seconds = (time() - $start);
|
$seconds = (time() - $start);
|
||||||
|
@ -193,10 +191,10 @@ while (true) {
|
||||||
|
|
||||||
if ($timeout) {
|
if ($timeout) {
|
||||||
$do_cron = true;
|
$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 {
|
} else {
|
||||||
$do_cron = false;
|
$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\Config;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Core\Update;
|
use Friendica\Core\Update;
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
$shortopts = 'sn';
|
$shortopts = 'sn';
|
||||||
|
@ -29,9 +28,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$logger = LoggerFactory::create('worker');
|
$a = new App(dirname(__DIR__));
|
||||||
|
|
||||||
$a = new App(dirname(__DIR__), $logger);
|
|
||||||
|
|
||||||
// Check the database structure and possibly fixes it
|
// Check the database structure and possibly fixes it
|
||||||
Update::check(true);
|
Update::check(true);
|
||||||
|
|
|
@ -42,8 +42,7 @@
|
||||||
"npm-asset/jgrowl": "^1.4",
|
"npm-asset/jgrowl": "^1.4",
|
||||||
"npm-asset/fullcalendar": "^3.0.1",
|
"npm-asset/fullcalendar": "^3.0.1",
|
||||||
"npm-asset/cropperjs": "1.2.2",
|
"npm-asset/cropperjs": "1.2.2",
|
||||||
"npm-asset/imagesloaded": "4.1.4",
|
"npm-asset/imagesloaded": "4.1.4"
|
||||||
"monolog/monolog": "^1.24"
|
|
||||||
},
|
},
|
||||||
"repositories": [
|
"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",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "8cf7268fbcae8a22a518b9e7727eab84",
|
"content-hash": "51f7b3ab622038d7ef62ed03c06b48d0",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "asika/simple-console",
|
"name": "asika/simple-console",
|
||||||
|
@ -809,84 +809,6 @@
|
||||||
],
|
],
|
||||||
"time": "2018-09-01T15:05:15+00:00"
|
"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",
|
"name": "npm-asset/cropperjs",
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
|
@ -1888,53 +1810,6 @@
|
||||||
],
|
],
|
||||||
"time": "2016-08-06T14:39:51+00:00"
|
"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",
|
"name": "seld/cli-prompt",
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
|
@ -2606,6 +2481,7 @@
|
||||||
"testing",
|
"testing",
|
||||||
"xunit"
|
"xunit"
|
||||||
],
|
],
|
||||||
|
"abandoned": true,
|
||||||
"time": "2016-12-02T14:39:14+00:00"
|
"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_POST', 'POST,PUT');
|
||||||
define('API_METHOD_DELETE', 'POST,DELETE');
|
define('API_METHOD_DELETE', 'POST,DELETE');
|
||||||
|
|
||||||
define('API_LOG_PREFIX', 'API {action} - ');
|
|
||||||
|
|
||||||
$API = [];
|
$API = [];
|
||||||
$called_api = [];
|
$called_api = [];
|
||||||
|
|
||||||
|
@ -99,9 +97,9 @@ function api_source()
|
||||||
return "Twidere";
|
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 {
|
} else {
|
||||||
Logger::info(API_LOG_PREFIX . 'Empty user-agent', ['module' => 'api', 'action' => 'source']);
|
Logger::log("Empty user-agent", Logger::DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "api";
|
return "api";
|
||||||
|
@ -183,7 +181,7 @@ function api_login(App $a)
|
||||||
var_dump($consumer, $token);
|
var_dump($consumer, $token);
|
||||||
die();
|
die();
|
||||||
} catch (Exception $e) {
|
} 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
|
// workaround for HTTP-auth in CGI mode
|
||||||
|
@ -197,7 +195,7 @@ function api_login(App $a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($_SERVER['PHP_AUTH_USER'])) {
|
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"');
|
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||||
throw new UnauthorizedException("This API requires login");
|
throw new UnauthorizedException("This API requires login");
|
||||||
}
|
}
|
||||||
|
@ -238,7 +236,7 @@ function api_login(App $a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DBA::isResult($record)) {
|
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('WWW-Authenticate: Basic realm="Friendica"');
|
||||||
//header('HTTP/1.0 401 Unauthorized');
|
//header('HTTP/1.0 401 Unauthorized');
|
||||||
//die('This api requires login');
|
//die('This api requires login');
|
||||||
|
@ -311,35 +309,33 @@ function api_call(App $a)
|
||||||
api_login($a);
|
api_login($a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username']]);
|
Logger::log('API call for ' . $a->user['username'] . ': ' . $a->query_string);
|
||||||
Logger::debug(API_LOG_PREFIX . 'parameters', ['module' => 'api', 'action' => 'call', 'parameters' => $_REQUEST]);
|
Logger::log('API parameters: ' . print_r($_REQUEST, true));
|
||||||
|
|
||||||
$stamp = microtime(true);
|
$stamp = microtime(true);
|
||||||
$return = call_user_func($info['func'], $type);
|
$return = call_user_func($info['func'], $type);
|
||||||
$duration = (float) (microtime(true) - $stamp);
|
$duration = (float) (microtime(true) - $stamp);
|
||||||
|
Logger::log("API call duration: " . round($duration, 2) . "\t" . $a->query_string, Logger::DEBUG);
|
||||||
Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]);
|
|
||||||
|
|
||||||
if (Config::get("system", "profiler")) {
|
if (Config::get("system", "profiler")) {
|
||||||
$duration = microtime(true)-$a->performance["start"];
|
$duration = microtime(true)-$a->performance["start"];
|
||||||
|
|
||||||
/// @TODO round() really everywhere?
|
/// @TODO round() really everywhere?
|
||||||
Logger::debug(
|
Logger::log(
|
||||||
API_LOG_PREFIX . 'performance',
|
parse_url($a->query_string, PHP_URL_PATH) . ": " . sprintf(
|
||||||
[
|
"Database: %s/%s, Cache %s/%s, Network: %s, I/O: %s, Other: %s, Total: %s",
|
||||||
'module' => 'api',
|
round($a->performance["database"] - $a->performance["database_write"], 3),
|
||||||
'action' => 'call',
|
round($a->performance["database_write"], 3),
|
||||||
'database_read' => round($a->performance["database"] - $a->performance["database_write"], 3),
|
round($a->performance["cache"], 3),
|
||||||
'database_write' => round($a->performance["database_write"], 3),
|
round($a->performance["cache_write"], 3),
|
||||||
'cache_read' => round($a->performance["cache"], 3),
|
round($a->performance["network"], 2),
|
||||||
'cache_write' => round($a->performance["cache_write"], 3),
|
round($a->performance["file"], 2),
|
||||||
'network_io' => round($a->performance["network"], 2),
|
round($duration - ($a->performance["database"]
|
||||||
'file_io' => round($a->performance["file"], 2),
|
|
||||||
'other_io' => round($duration - ($a->performance["database"]
|
|
||||||
+ $a->performance["cache"] + $a->performance["cache_write"]
|
+ $a->performance["cache"] + $a->performance["cache_write"]
|
||||||
+ $a->performance["network"] + $a->performance["file"]), 2),
|
+ $a->performance["network"] + $a->performance["file"]), 2),
|
||||||
'total' => round($duration, 2)
|
round($duration, 2)
|
||||||
]
|
),
|
||||||
|
Logger::DEBUG
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Config::get("rendertime", "callstack")) {
|
if (Config::get("rendertime", "callstack")) {
|
||||||
|
@ -380,7 +376,7 @@ function api_call(App $a)
|
||||||
$o .= $func . ": " . $time . "\n";
|
$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();
|
throw new NotImplementedException();
|
||||||
} catch (HTTPException $e) {
|
} catch (HTTPException $e) {
|
||||||
header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}");
|
header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}");
|
||||||
|
@ -526,7 +522,7 @@ function api_get_user(App $a, $contact_id = null)
|
||||||
$extra_query = "";
|
$extra_query = "";
|
||||||
$url = "";
|
$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
|
// Searching for contact URL
|
||||||
if (!is_null($contact_id) && (intval($contact_id) == 0)) {
|
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 (!$user) {
|
||||||
if (api_user() === false) {
|
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
|
// user info
|
||||||
$uinfo = q(
|
$uinfo = q(
|
||||||
|
@ -1941,7 +1937,7 @@ function api_conversation_show($type)
|
||||||
$id = intval(defaults($a->argv, 4, 0));
|
$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
|
// 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]);
|
$item = Item::selectFirst(['parent-uri'], ['id' => $id]);
|
||||||
|
@ -2335,7 +2331,7 @@ function api_favorites($type)
|
||||||
|
|
||||||
// in friendica starred item are private
|
// in friendica starred item are private
|
||||||
// return favorites only for self
|
// 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) {
|
if ($user_info['self'] == 0) {
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
@ -3698,7 +3694,7 @@ function api_friendships_destroy($type)
|
||||||
$contact_id = defaults($_REQUEST, 'user_id');
|
$contact_id = defaults($_REQUEST, 'user_id');
|
||||||
|
|
||||||
if (empty($contact_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");
|
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]);
|
$contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => 0, 'self' => false]);
|
||||||
|
|
||||||
if(!DBA::isResult($contact)) {
|
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");
|
throw new NotFoundException("no contact found to given ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3718,12 +3714,12 @@ function api_friendships_destroy($type)
|
||||||
$contact = DBA::selectFirst('contact', [], $condition);
|
$contact = DBA::selectFirst('contact', [], $condition);
|
||||||
|
|
||||||
if (!DBA::isResult($contact)) {
|
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");
|
throw new NotFoundException("Not following Contact");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
|
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");
|
throw new ExpectationFailedException("Not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3734,7 +3730,7 @@ function api_friendships_destroy($type)
|
||||||
Contact::terminateFriendship($owner, $contact, $dissolve);
|
Contact::terminateFriendship($owner, $contact, $dissolve);
|
||||||
}
|
}
|
||||||
else {
|
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");
|
throw new NotFoundException("Error Processing Request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4841,7 +4837,7 @@ function api_friendica_remoteauth()
|
||||||
'sec' => $sec, 'expire' => time() + 45];
|
'sec' => $sec, 'expire' => time() + 45];
|
||||||
DBA::insert('profile_check', $fields);
|
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 : '');
|
$dest = ($url ? '&destination_url=' . $url : '');
|
||||||
|
|
||||||
System::externalRedirect(
|
System::externalRedirect(
|
||||||
|
@ -5090,7 +5086,7 @@ function api_in_reply_to($item)
|
||||||
// https://github.com/friendica/friendica/issues/1010
|
// https://github.com/friendica/friendica/issues/1010
|
||||||
// This is a bugfix for that.
|
// This is a bugfix for that.
|
||||||
if (intval($in_reply_to['status_id']) == intval($item['id'])) {
|
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['status_id'] = null;
|
||||||
$in_reply_to['user_id'] = null;
|
$in_reply_to['user_id'] = null;
|
||||||
$in_reply_to['status_id_str'] = null;
|
$in_reply_to['status_id_str'] = null;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
|
|
||||||
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
|
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.');
|
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';
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
$logger = LoggerFactory::create('index');
|
|
||||||
|
|
||||||
// We assume that the index.php is called by a frontend process
|
// We assume that the index.php is called by a frontend process
|
||||||
// The value is set to "true" by default in App
|
// The value is set to "true" by default in App
|
||||||
$a = new App(__DIR__, $logger, false);
|
$a = new App(__DIR__, false);
|
||||||
|
|
||||||
$a->runFrontend();
|
$a->runFrontend();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ function acl_content(App $a)
|
||||||
$search = $_REQUEST['query'];
|
$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 != '') {
|
if ($search != '') {
|
||||||
$sql_extra = "AND `name` LIKE '%%" . DBA::escape($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 DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Logger;
|
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -108,11 +106,6 @@ class App
|
||||||
*/
|
*/
|
||||||
public $mobileDetect;
|
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.
|
* Register a stylesheet file path to be included in the <head> tag of every page.
|
||||||
* Inclusion is done in App->initHead().
|
* Inclusion is done in App->initHead().
|
||||||
|
@ -154,15 +147,12 @@ class App
|
||||||
* @brief App constructor.
|
* @brief App constructor.
|
||||||
*
|
*
|
||||||
* @param string $basePath Path to the app base folder
|
* @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)
|
* @param bool $isBackend Whether it is used for backend or frontend (Default true=backend)
|
||||||
*
|
*
|
||||||
* @throws Exception if the Basepath is not usable
|
* @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)) {
|
if (!static::isDirectoryUsable($basePath, false)) {
|
||||||
throw new Exception('Basepath ' . $basePath . ' isn\'t usable.');
|
throw new Exception('Basepath ' . $basePath . ' isn\'t usable.');
|
||||||
}
|
}
|
||||||
|
@ -311,21 +301,6 @@ class App
|
||||||
return $this->mode;
|
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
|
* Reloads the whole app instance
|
||||||
*/
|
*/
|
||||||
|
@ -353,8 +328,6 @@ class App
|
||||||
Core\L10n::init();
|
Core\L10n::init();
|
||||||
|
|
||||||
$this->process_id = Core\System::processID('log');
|
$this->process_id = Core\System::processID('log');
|
||||||
|
|
||||||
Core\Logger::setLogger($this->logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,8 +6,6 @@ namespace Friendica;
|
||||||
|
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
|
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic object
|
* Basic object
|
||||||
*
|
*
|
||||||
|
@ -27,8 +25,7 @@ class BaseObject
|
||||||
public static function getApp()
|
public static function getApp()
|
||||||
{
|
{
|
||||||
if (empty(self::$app)) {
|
if (empty(self::$app)) {
|
||||||
$logger = $logger = LoggerFactory::create('app');
|
self::$app = new App(dirname(__DIR__));
|
||||||
self::$app = new App(dirname(__DIR__), $logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$app;
|
return self::$app;
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
*/
|
*/
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +76,7 @@ class Addon extends BaseObject
|
||||||
*/
|
*/
|
||||||
public static function uninstall($addon)
|
public static function uninstall($addon)
|
||||||
{
|
{
|
||||||
Logger::notice("Addon {addon}: {action}", ['action' => 'uninstall', 'addon' => $addon]);
|
Logger::log("Addons: uninstalling " . $addon);
|
||||||
DBA::delete('addon', ['name' => $addon]);
|
DBA::delete('addon', ['name' => $addon]);
|
||||||
|
|
||||||
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
||||||
|
@ -99,7 +101,7 @@ class Addon extends BaseObject
|
||||||
if (!file_exists('addon/' . $addon . '/' . $addon . '.php')) {
|
if (!file_exists('addon/' . $addon . '/' . $addon . '.php')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Logger::notice("Addon {addon}: {action}", ['action' => 'install', 'addon' => $addon]);
|
Logger::log("Addons: installing " . $addon);
|
||||||
$t = @filemtime('addon/' . $addon . '/' . $addon . '.php');
|
$t = @filemtime('addon/' . $addon . '/' . $addon . '.php');
|
||||||
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
||||||
if (function_exists($addon . '_install')) {
|
if (function_exists($addon . '_install')) {
|
||||||
|
@ -124,7 +126,7 @@ class Addon extends BaseObject
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Logger::error("Addon {addon}: {action} failed", ['action' => 'uninstall', 'addon' => $addon]);
|
Logger::log("Addons: FAILED installing " . $addon);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,8 +156,7 @@ class Addon extends BaseObject
|
||||||
$t = @filemtime($fname);
|
$t = @filemtime($fname);
|
||||||
foreach ($installed as $i) {
|
foreach ($installed as $i) {
|
||||||
if (($i['name'] == $addon) && ($i['timestamp'] != $t)) {
|
if (($i['name'] == $addon) && ($i['timestamp'] != $t)) {
|
||||||
|
Logger::log('Reloading addon: ' . $i['name']);
|
||||||
Logger::notice("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $i['name']]);
|
|
||||||
@include_once($fname);
|
@include_once($fname);
|
||||||
|
|
||||||
if (function_exists($addon . '_uninstall')) {
|
if (function_exists($addon . '_uninstall')) {
|
||||||
|
|
|
@ -5,47 +5,23 @@
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Util\LoggerFactory;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Psr\Log\LoggerInterface;
|
use ReflectionClass;
|
||||||
use Psr\Log\LogLevel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Logger functions
|
* @brief Logger functions
|
||||||
*/
|
*/
|
||||||
class Logger extends BaseObject
|
class Logger extends BaseObject
|
||||||
{
|
{
|
||||||
/**
|
// Log levels:
|
||||||
* @see Logger::error()
|
const WARNING = 0;
|
||||||
*/
|
const INFO = 1;
|
||||||
const WARNING = LogLevel::ERROR;
|
const TRACE = 2;
|
||||||
/**
|
const DEBUG = 3;
|
||||||
* @see Logger::warning()
|
const DATA = 4;
|
||||||
*/
|
const ALL = 5;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 = [
|
public static $levels = [
|
||||||
self::WARNING => 'Warning',
|
self::WARNING => 'Warning',
|
||||||
self::INFO => 'Info',
|
self::INFO => 'Info',
|
||||||
|
@ -55,247 +31,56 @@ class Logger extends BaseObject
|
||||||
self::ALL => 'All',
|
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
|
* @brief Logs the given message at the given log level
|
||||||
*
|
*
|
||||||
* @param string $msg
|
* @param string $msg
|
||||||
* @param int $level
|
* @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;
|
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);
|
$stamp1 = microtime(true);
|
||||||
self::$logger->log($level, $msg);
|
@file_put_contents($logfile, $logline, FILE_APPEND);
|
||||||
self::getApp()->saveTimestamp($stamp1, "file");
|
$a->saveTimestamp($stamp1, "file");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,16 +90,47 @@ class Logger extends BaseObject
|
||||||
* personally without background noise
|
* personally without background noise
|
||||||
*
|
*
|
||||||
* @param string $msg
|
* @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;
|
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);
|
$stamp1 = microtime(true);
|
||||||
self::$devLogger->log($level, $msg);
|
@file_put_contents($logfile, $logline, FILE_APPEND);
|
||||||
self::getApp()->saveTimestamp($stamp1, "file");
|
$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\Protocol;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
use Monolog\Handler\TestHandler;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../../include/api.php';
|
require_once __DIR__ . '/../../include/api.php';
|
||||||
|
|
||||||
|
@ -24,11 +22,6 @@ require_once __DIR__ . '/../../include/api.php';
|
||||||
*/
|
*/
|
||||||
class ApiTest extends DatabaseTest
|
class ApiTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var TestHandler Can handle log-outputs
|
|
||||||
*/
|
|
||||||
protected $logOutput;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create variables used by tests.
|
* Create variables used by tests.
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +30,6 @@ class ApiTest extends DatabaseTest
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->app = BaseObject::getApp();
|
$this->app = BaseObject::getApp();
|
||||||
$this->logOutput = LoggerFactory::enableTest($this->app->getLogger());
|
|
||||||
|
|
||||||
// User data that the test database is populated with
|
// User data that the test database is populated with
|
||||||
$this->selfUser = [
|
$this->selfUser = [
|
||||||
|
|
|
@ -7,7 +7,6 @@ namespace Friendica\Test;
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
use Friendica\Util\LoggerFactory;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,9 +38,7 @@ class BaseObjectTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSetApp()
|
public function testSetApp()
|
||||||
{
|
{
|
||||||
$logger = $logger = LoggerFactory::create('test');
|
$app = new App(__DIR__ . '/../../');
|
||||||
$app = new App(__DIR__ . '/../../', $logger);
|
|
||||||
LoggerFactory::enableTest($logger);
|
|
||||||
$this->assertNull($this->baseObject->setApp($app));
|
$this->assertNull($this->baseObject->setApp($app));
|
||||||
$this->assertEquals($app, $this->baseObject->getApp());
|
$this->assertEquals($app, $this->baseObject->getApp());
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,8 +332,8 @@ function update_1298()
|
||||||
$fail++;
|
$fail++;
|
||||||
} else {
|
} else {
|
||||||
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
|
DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
|
||||||
Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
|
logger::log('Updated contact ' . $data['id'] . " to $translateKey " . $key .
|
||||||
'was' => $data[$translateKey]]);
|
' (was: ' . $data[$translateKey] . ')');
|
||||||
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
|
Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
|
||||||
Contact::updateSelfFromUserID($data['id']);
|
Contact::updateSelfFromUserID($data['id']);
|
||||||
GContact::updateForUser($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;
|
return Update::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue