diff --git a/common.php b/common.php index 8c4b6d479..2e2cd676b 100644 --- a/common.php +++ b/common.php @@ -145,7 +145,30 @@ if ($bb_cfg['bugsnag']['enabled']) { if (DBG_USER) { /** @var Whoops\Run $whoops */ $whoops = new \Whoops\Run; + + /** + * Show errors on page + */ $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); + + /** + * Show log in browser console + */ + $loggingInConsole = new \Whoops\Handler\PlainTextHandler(); + $loggingInConsole->loggerOnly(true); + $loggingInConsole->setLogger((new \Monolog\Logger(getenv('APP_NAME', 'TorrentPier'), [(new \Monolog\Handler\BrowserConsoleHandler())->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))]))); + $whoops->pushHandler($loggingInConsole); + + /** + * Log errors in file + */ + if (ini_get('log_errors') == 1) { + $loggingInFile = new \Whoops\Handler\PlainTextHandler(); + $loggingInFile->loggerOnly(true); + $loggingInFile->setLogger((new \Monolog\Logger(getenv('APP_NAME', 'TorrentPier'), [(new \Monolog\Handler\StreamHandler(bb_log('', WHOOPS_LOG_FILE, true)))->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))]))); + $whoops->pushHandler($loggingInFile); + } + $whoops->register(); } } @@ -228,13 +251,19 @@ function utime() return array_sum(explode(' ', microtime())); } -function bb_log($msg, $file_name) +function bb_log($msg, $file_name, $return_path = false) { if (is_array($msg)) { $msg = implode(LOG_LF, $msg); } $file_name .= (LOG_EXT) ? '.' . LOG_EXT : ''; - return file_write($msg, LOG_DIR . '/' . $file_name); + + $path = (LOG_DIR . '/' . $file_name); + if ($return_path) { + return $path; + } + + return file_write($msg, $path); } function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replace_content = false) diff --git a/composer.json b/composer.json index f20bac1f0..c38385dbf 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "guzzlehttp/guzzle": "6.*", "guzzlehttp/psr7": "1.*", "longman/ip-tools": "1.2.1", + "monolog/monolog": "1.*", "rych/bencode": "v1.0.0", "samdark/sitemap": "2.4.0", "swiftmailer/swiftmailer": "v6.3.0", diff --git a/composer.lock b/composer.lock index a7ec7e232..eeaba4318 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "530818326ea7baa3a459b76781f0157a", + "content-hash": "5cbe568826fbd0fe40fe76d58d1e1a9c", "packages": [ { "name": "bugsnag/bugsnag", @@ -836,6 +836,92 @@ }, "time": "2016-10-23T20:08:46+00:00" }, + { + "name": "monolog/monolog", + "version": "1.27.1", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "904713c5929655dc9b97288b69cfeedad610c9a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/904713c5929655dc9b97288b69cfeedad610c9a1", + "reference": "904713c5929655dc9b97288b69cfeedad610c9a1", + "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", + "php-amqplib/php-amqplib": "~2.4", + "php-console/php-console": "^3.1.3", + "phpstan/phpstan": "^0.12.59", + "phpunit/phpunit": "~4.5", + "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", + "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" + ], + "support": { + "issues": "https://github.com/Seldaek/monolog/issues", + "source": "https://github.com/Seldaek/monolog/tree/1.27.1" + }, + "funding": [ + { + "url": "https://github.com/Seldaek", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/monolog/monolog", + "type": "tidelift" + } + ], + "time": "2022-06-09T08:53:42+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -1460,5 +1546,5 @@ "php": "^7.1.3" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/library/defines.php b/library/defines.php index 5f81f66d6..ae12adccc 100644 --- a/library/defines.php +++ b/library/defines.php @@ -50,12 +50,13 @@ define('XS_TAG_BEGINELSE', 11); // Debug define('COOKIE_DBG', 'bb_dbg'); // debug cookie name -define('SQL_DEBUG', true); // enable forum sql & cache debug -define('SQL_LOG_ERRORS', true); // all SQL_xxx options enabled only if SQL_DEBUG == TRUE -define('SQL_CALC_QUERY_TIME', true); // for stats -define('SQL_LOG_SLOW_QUERIES', true); // log sql slow queries -define('SQL_SLOW_QUERY_TIME', 10); // slow query in seconds -define('SQL_PREPEND_SRC_COMM', false); // prepend source file comment to sql query +define('SQL_DEBUG', true); // enable forum sql & cache debug +define('SQL_LOG_ERRORS', true); // all SQL_xxx options enabled only if SQL_DEBUG == TRUE +define('SQL_LOG_NAME', 'sql_error_bb'); // mysql log filename +define('SQL_CALC_QUERY_TIME', true); // for stats +define('SQL_LOG_SLOW_QUERIES', true); // log sql slow queries +define('SQL_SLOW_QUERY_TIME', 10); // slow query in seconds +define('SQL_PREPEND_SRC_COMM', false); // prepend source file comment to sql query // Log options define('LOG_EXT', 'log'); @@ -67,7 +68,8 @@ define('LOG_MAX_SIZE', 1048576); // bytes ini_set('error_reporting', E_ALL); ini_set('display_errors', 0); ini_set('log_errors', 1); -ini_set('error_log', LOG_DIR . '/php_err.log'); +ini_set('error_log', LOG_DIR . '/php_errors.log'); // path to log file enabled only if log_errors == 1 (native) +define('WHOOPS_LOG_FILE', 'php_whoops'); // log file enabled only if log_errors == 1 (whoops) // Triggers define('BB_ENABLED', TRIGGERS_DIR . '/$on'); diff --git a/src/Legacy/SqlDb.php b/src/Legacy/SqlDb.php index 066018afd..024927b08 100644 --- a/src/Legacy/SqlDb.php +++ b/src/Legacy/SqlDb.php @@ -941,7 +941,7 @@ class SqlDb $msg[] = 'PID : ' . sprintf('%05d', getmypid()); $msg[] = 'Request : ' . trim(print_r($_REQUEST, true)) . str_repeat('_', 78) . LOG_LF; $msg[] = ''; - bb_log($msg, 'sql_error_bb'); + bb_log($msg, SQL_LOG_NAME); } /**