mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 21:33:54 -07:00
Imporeved debug 🐛 (#822)
This commit is contained in:
parent
695d46e31e
commit
69f2509910
10 changed files with 77 additions and 60 deletions
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!empty($setmodules)) {
|
if (!empty($setmodules)) {
|
||||||
$module['TorrentPier']['FORUM_CONFIG'] = basename(__FILE__);
|
$module[APP_NAME]['FORUM_CONFIG'] = basename(__FILE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
if (!empty($setmodules)) {
|
if (!empty($setmodules)) {
|
||||||
if (IS_SUPER_ADMIN) {
|
if (IS_SUPER_ADMIN) {
|
||||||
$module['TorrentPier']['CRON'] = basename(__FILE__) . '?mode=list';
|
$module[APP_NAME]['CRON'] = basename(__FILE__) . '?mode=list';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,6 @@ if (file_exists(BB_PATH . '/library/config.local.php')) {
|
||||||
/**
|
/**
|
||||||
* Progressive error reporting
|
* Progressive error reporting
|
||||||
*/
|
*/
|
||||||
define('DBG_USER', isset($_COOKIE[COOKIE_DBG]));
|
|
||||||
\TorrentPier\Dev::initDebug();
|
\TorrentPier\Dev::initDebug();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -345,7 +345,7 @@ $bb_cfg['lang'] = [
|
||||||
// Templates
|
// Templates
|
||||||
$bb_cfg['templates'] = [
|
$bb_cfg['templates'] = [
|
||||||
// Список доступных шаблонов для выбора
|
// Список доступных шаблонов для выбора
|
||||||
'default' => 'TorrentPier',
|
'default' => 'Default',
|
||||||
];
|
];
|
||||||
|
|
||||||
$bb_cfg['tpl_name'] = 'default'; // Активный шаблон по умолчанию
|
$bb_cfg['tpl_name'] = 'default'; // Активный шаблон по умолчанию
|
||||||
|
@ -428,10 +428,6 @@ $bb_cfg['bugsnag'] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
// Special users
|
// Special users
|
||||||
$bb_cfg['dbg_users'] = [
|
|
||||||
# user_id => 'name',
|
|
||||||
2 => 'admin',
|
|
||||||
];
|
|
||||||
$bb_cfg['unlimited_users'] = [
|
$bb_cfg['unlimited_users'] = [
|
||||||
# user_id => 'name',
|
# user_id => 'name',
|
||||||
2 => 'admin',
|
2 => 'admin',
|
||||||
|
|
|
@ -12,6 +12,8 @@ if (!defined('BB_ROOT')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// System
|
// System
|
||||||
|
define('APP_NAME', 'TorrentPier');
|
||||||
|
|
||||||
define('CHECK_REQIREMENTS', [
|
define('CHECK_REQIREMENTS', [
|
||||||
'status' => true,
|
'status' => true,
|
||||||
'php_min_version' => '7.4.0',
|
'php_min_version' => '7.4.0',
|
||||||
|
@ -62,7 +64,7 @@ define('XS_TAG_ENDIF', 8);
|
||||||
define('XS_TAG_BEGINELSE', 11);
|
define('XS_TAG_BEGINELSE', 11);
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
define('COOKIE_DBG', 'bb_dbg'); // debug cookie name
|
define('APP_DEBUG', true); // enable application debug
|
||||||
define('SQL_DEBUG', true); // enable forum sql & cache debug
|
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_ERRORS', true); // all SQL_xxx options enabled only if SQL_DEBUG == TRUE
|
||||||
define('SQL_LOG_NAME', 'sql_error_bb'); // mysql log filename
|
define('SQL_LOG_NAME', 'sql_error_bb'); // mysql log filename
|
||||||
|
@ -79,8 +81,8 @@ define('LOG_MAX_SIZE', 1048576); // bytes
|
||||||
|
|
||||||
// Error reporting
|
// Error reporting
|
||||||
ini_set('error_reporting', E_ALL); // PHP error reporting mode | https://www.php.net/manual/en/errorfunc.constants.php
|
ini_set('error_reporting', E_ALL); // PHP error reporting mode | https://www.php.net/manual/en/errorfunc.constants.php
|
||||||
ini_set('display_errors', 0); // Show general php errors
|
ini_set('display_errors', 1); // Show general php errors
|
||||||
ini_set('display_startup_errors', 0); // Show startup php errors
|
ini_set('display_startup_errors', 1); // Show startup php errors
|
||||||
define('MYSQLI_ERROR_REPORTING', MYSQLI_REPORT_ERROR); // MySQL error reporting mode | https://www.php.net/manual/mysqli-driver.report-mode.php
|
define('MYSQLI_ERROR_REPORTING', MYSQLI_REPORT_ERROR); // MySQL error reporting mode | https://www.php.net/manual/mysqli-driver.report-mode.php
|
||||||
ini_set('log_errors', 1); // php native logging
|
ini_set('log_errors', 1); // php native logging
|
||||||
ini_set('error_log', LOG_DIR . '/php_errors.log'); // path to log file enabled only if log_errors == 1 (native)
|
ini_set('error_log', LOG_DIR . '/php_errors.log'); // path to log file enabled only if log_errors == 1 (native)
|
||||||
|
|
|
@ -96,17 +96,6 @@ function bb_setcookie($name, $val, int $lifetime = COOKIE_PERSIST, bool $httponl
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Debug options
|
|
||||||
*/
|
|
||||||
if (DBG_USER) {
|
|
||||||
ini_set('error_reporting', E_ALL);
|
|
||||||
ini_set('display_errors', 1);
|
|
||||||
ini_set('display_startup_errors', 1);
|
|
||||||
} else {
|
|
||||||
unset($_COOKIE['explain']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// User Levels
|
// User Levels
|
||||||
define('DELETED', -1);
|
define('DELETED', -1);
|
||||||
define('USER', 0);
|
define('USER', 0);
|
||||||
|
|
|
@ -25,7 +25,7 @@ if (!empty($template)) {
|
||||||
$template->pparse('page_footer');
|
$template->pparse('page_footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
$show_dbg_info = (DBG_USER && !(isset($_GET['pane']) && $_GET['pane'] == 'left'));
|
$show_dbg_info = (APP_DEBUG && !(isset($_GET['pane']) && $_GET['pane'] == 'left'));
|
||||||
|
|
||||||
if (!$bb_cfg['gzip_compress']) {
|
if (!$bb_cfg['gzip_compress']) {
|
||||||
flush();
|
flush();
|
||||||
|
|
|
@ -182,7 +182,7 @@ class Ajax
|
||||||
*/
|
*/
|
||||||
public function ob_handler($contents): string
|
public function ob_handler($contents): string
|
||||||
{
|
{
|
||||||
if (DBG_USER) {
|
if (APP_DEBUG) {
|
||||||
if ($contents) {
|
if ($contents) {
|
||||||
$this->response['raw_output'] = $contents;
|
$this->response['raw_output'] = $contents;
|
||||||
}
|
}
|
||||||
|
|
53
src/Dev.php
53
src/Dev.php
|
@ -29,6 +29,13 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class Dev
|
class Dev
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Environment type
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
public static ?string $envType = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base debug functionality init
|
* Base debug functionality init
|
||||||
*
|
*
|
||||||
|
@ -38,13 +45,43 @@ class Dev
|
||||||
{
|
{
|
||||||
global $bb_cfg;
|
global $bb_cfg;
|
||||||
|
|
||||||
if ($bb_cfg['bugsnag']['enabled']) {
|
self::$envType = env('APP_ENV', 'local');
|
||||||
if (env('APP_ENV', 'production') !== 'local') {
|
|
||||||
|
if (self::$envType === 'production') {
|
||||||
|
if (!$bb_cfg['bugsnag']['enabled']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::getBugsnag();
|
||||||
|
} else {
|
||||||
|
if (!APP_DEBUG) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::getWhoops();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bugsnag debug driver
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function getBugsnag(): void
|
||||||
|
{
|
||||||
|
global $bb_cfg;
|
||||||
|
|
||||||
$bugsnag = Client::make($bb_cfg['bugsnag']['api_key']);
|
$bugsnag = Client::make($bb_cfg['bugsnag']['api_key']);
|
||||||
Handler::register($bugsnag);
|
Handler::register($bugsnag);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (DBG_USER) {
|
/**
|
||||||
|
* Whoops debug driver
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function getWhoops(): void
|
||||||
|
{
|
||||||
$whoops = new Run;
|
$whoops = new Run;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +94,7 @@ class Dev
|
||||||
*/
|
*/
|
||||||
$loggingInConsole = new PlainTextHandler();
|
$loggingInConsole = new PlainTextHandler();
|
||||||
$loggingInConsole->loggerOnly(true);
|
$loggingInConsole->loggerOnly(true);
|
||||||
$loggingInConsole->setLogger((new Logger('TorrentPier', [(new BrowserConsoleHandler())->setFormatter((new LineFormatter(null, null, true)))])));
|
$loggingInConsole->setLogger((new Logger(APP_NAME, [(new BrowserConsoleHandler())->setFormatter((new LineFormatter(null, null, true)))])));
|
||||||
$whoops->pushHandler($loggingInConsole);
|
$whoops->pushHandler($loggingInConsole);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,14 +103,12 @@ class Dev
|
||||||
if (ini_get('log_errors') == 1) {
|
if (ini_get('log_errors') == 1) {
|
||||||
$loggingInFile = new PlainTextHandler();
|
$loggingInFile = new PlainTextHandler();
|
||||||
$loggingInFile->loggerOnly(true);
|
$loggingInFile->loggerOnly(true);
|
||||||
$loggingInFile->setLogger((new Logger('TorrentPier', [(new StreamHandler(WHOOPS_LOG_FILE))->setFormatter((new LineFormatter(null, null, true)))])));
|
$loggingInFile->setLogger((new Logger(APP_NAME, [(new StreamHandler(WHOOPS_LOG_FILE))->setFormatter((new LineFormatter(null, null, true)))])));
|
||||||
$whoops->pushHandler($loggingInFile);
|
$whoops->pushHandler($loggingInFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$whoops->register();
|
$whoops->register();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get SQL debug log
|
* Get SQL debug log
|
||||||
|
@ -115,7 +150,7 @@ class Dev
|
||||||
*/
|
*/
|
||||||
public static function sql_dbg_enabled(): bool
|
public static function sql_dbg_enabled(): bool
|
||||||
{
|
{
|
||||||
return (SQL_DEBUG && DBG_USER && !empty($_COOKIE['sql_log']));
|
return (SQL_DEBUG && APP_DEBUG && !empty($_COOKIE['sql_log']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -468,7 +468,6 @@ class User
|
||||||
if ($user_id == GUEST_UID) {
|
if ($user_id == GUEST_UID) {
|
||||||
$delete_cookies = [
|
$delete_cookies = [
|
||||||
COOKIE_DATA,
|
COOKIE_DATA,
|
||||||
COOKIE_DBG,
|
|
||||||
'torhelp',
|
'torhelp',
|
||||||
'explain',
|
'explain',
|
||||||
'sql_log',
|
'sql_log',
|
||||||
|
@ -487,9 +486,6 @@ class User
|
||||||
if ($c_sdata_curr !== $c_sdata_resv) {
|
if ($c_sdata_curr !== $c_sdata_resv) {
|
||||||
bb_setcookie(COOKIE_DATA, $c_sdata_curr, COOKIE_PERSIST, true);
|
bb_setcookie(COOKIE_DATA, $c_sdata_curr, COOKIE_PERSIST, true);
|
||||||
}
|
}
|
||||||
if (isset($bb_cfg['dbg_users'][$this->data['user_id']]) && !DBG_USER) {
|
|
||||||
bb_setcookie(COOKIE_DBG, 1, COOKIE_SESSION);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue