mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 18:48:21 -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)) {
|
||||
$module['TorrentPier']['FORUM_CONFIG'] = basename(__FILE__);
|
||||
$module[APP_NAME]['FORUM_CONFIG'] = basename(__FILE__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
if (!empty($setmodules)) {
|
||||
if (IS_SUPER_ADMIN) {
|
||||
$module['TorrentPier']['CRON'] = basename(__FILE__) . '?mode=list';
|
||||
$module[APP_NAME]['CRON'] = basename(__FILE__) . '?mode=list';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,6 @@ if (file_exists(BB_PATH . '/library/config.local.php')) {
|
|||
/**
|
||||
* Progressive error reporting
|
||||
*/
|
||||
define('DBG_USER', isset($_COOKIE[COOKIE_DBG]));
|
||||
\TorrentPier\Dev::initDebug();
|
||||
|
||||
/**
|
||||
|
|
|
@ -345,7 +345,7 @@ $bb_cfg['lang'] = [
|
|||
// Templates
|
||||
$bb_cfg['templates'] = [
|
||||
// Список доступных шаблонов для выбора
|
||||
'default' => 'TorrentPier',
|
||||
'default' => 'Default',
|
||||
];
|
||||
|
||||
$bb_cfg['tpl_name'] = 'default'; // Активный шаблон по умолчанию
|
||||
|
@ -428,10 +428,6 @@ $bb_cfg['bugsnag'] = [
|
|||
];
|
||||
|
||||
// Special users
|
||||
$bb_cfg['dbg_users'] = [
|
||||
# user_id => 'name',
|
||||
2 => 'admin',
|
||||
];
|
||||
$bb_cfg['unlimited_users'] = [
|
||||
# user_id => 'name',
|
||||
2 => 'admin',
|
||||
|
|
|
@ -12,6 +12,8 @@ if (!defined('BB_ROOT')) {
|
|||
}
|
||||
|
||||
// System
|
||||
define('APP_NAME', 'TorrentPier');
|
||||
|
||||
define('CHECK_REQIREMENTS', [
|
||||
'status' => true,
|
||||
'php_min_version' => '7.4.0',
|
||||
|
@ -62,7 +64,7 @@ define('XS_TAG_ENDIF', 8);
|
|||
define('XS_TAG_BEGINELSE', 11);
|
||||
|
||||
// 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_LOG_ERRORS', true); // all SQL_xxx options enabled only if SQL_DEBUG == TRUE
|
||||
define('SQL_LOG_NAME', 'sql_error_bb'); // mysql log filename
|
||||
|
@ -79,8 +81,8 @@ define('LOG_MAX_SIZE', 1048576); // bytes
|
|||
|
||||
// Error reporting
|
||||
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_startup_errors', 0); // Show startup php errors
|
||||
ini_set('display_errors', 1); // Show general 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
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
define('DELETED', -1);
|
||||
define('USER', 0);
|
||||
|
|
|
@ -25,7 +25,7 @@ if (!empty($template)) {
|
|||
$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']) {
|
||||
flush();
|
||||
|
|
|
@ -182,7 +182,7 @@ class Ajax
|
|||
*/
|
||||
public function ob_handler($contents): string
|
||||
{
|
||||
if (DBG_USER) {
|
||||
if (APP_DEBUG) {
|
||||
if ($contents) {
|
||||
$this->response['raw_output'] = $contents;
|
||||
}
|
||||
|
|
99
src/Dev.php
99
src/Dev.php
|
@ -29,6 +29,13 @@ use Exception;
|
|||
*/
|
||||
class Dev
|
||||
{
|
||||
/**
|
||||
* Environment type
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public static ?string $envType = null;
|
||||
|
||||
/**
|
||||
* Base debug functionality init
|
||||
*
|
||||
|
@ -38,43 +45,71 @@ class Dev
|
|||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if ($bb_cfg['bugsnag']['enabled']) {
|
||||
if (env('APP_ENV', 'production') !== 'local') {
|
||||
$bugsnag = Client::make($bb_cfg['bugsnag']['api_key']);
|
||||
Handler::register($bugsnag);
|
||||
self::$envType = env('APP_ENV', 'local');
|
||||
|
||||
if (self::$envType === 'production') {
|
||||
if (!$bb_cfg['bugsnag']['enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::getBugsnag();
|
||||
} else {
|
||||
if (DBG_USER) {
|
||||
$whoops = new Run;
|
||||
|
||||
/**
|
||||
* Show errors on page
|
||||
*/
|
||||
$whoops->pushHandler(new PrettyPageHandler);
|
||||
|
||||
/**
|
||||
* Show log in browser console
|
||||
*/
|
||||
$loggingInConsole = new PlainTextHandler();
|
||||
$loggingInConsole->loggerOnly(true);
|
||||
$loggingInConsole->setLogger((new Logger('TorrentPier', [(new BrowserConsoleHandler())->setFormatter((new LineFormatter(null, null, true)))])));
|
||||
$whoops->pushHandler($loggingInConsole);
|
||||
|
||||
/**
|
||||
* Log errors in file
|
||||
*/
|
||||
if (ini_get('log_errors') == 1) {
|
||||
$loggingInFile = new PlainTextHandler();
|
||||
$loggingInFile->loggerOnly(true);
|
||||
$loggingInFile->setLogger((new Logger('TorrentPier', [(new StreamHandler(WHOOPS_LOG_FILE))->setFormatter((new LineFormatter(null, null, true)))])));
|
||||
$whoops->pushHandler($loggingInFile);
|
||||
}
|
||||
|
||||
$whoops->register();
|
||||
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']);
|
||||
Handler::register($bugsnag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whoops debug driver
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function getWhoops(): void
|
||||
{
|
||||
$whoops = new Run;
|
||||
|
||||
/**
|
||||
* Show errors on page
|
||||
*/
|
||||
$whoops->pushHandler(new PrettyPageHandler);
|
||||
|
||||
/**
|
||||
* Show log in browser console
|
||||
*/
|
||||
$loggingInConsole = new PlainTextHandler();
|
||||
$loggingInConsole->loggerOnly(true);
|
||||
$loggingInConsole->setLogger((new Logger(APP_NAME, [(new BrowserConsoleHandler())->setFormatter((new LineFormatter(null, null, true)))])));
|
||||
$whoops->pushHandler($loggingInConsole);
|
||||
|
||||
/**
|
||||
* Log errors in file
|
||||
*/
|
||||
if (ini_get('log_errors') == 1) {
|
||||
$loggingInFile = new PlainTextHandler();
|
||||
$loggingInFile->loggerOnly(true);
|
||||
$loggingInFile->setLogger((new Logger(APP_NAME, [(new StreamHandler(WHOOPS_LOG_FILE))->setFormatter((new LineFormatter(null, null, true)))])));
|
||||
$whoops->pushHandler($loggingInFile);
|
||||
}
|
||||
|
||||
$whoops->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL debug log
|
||||
*
|
||||
|
@ -115,7 +150,7 @@ class Dev
|
|||
*/
|
||||
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) {
|
||||
$delete_cookies = [
|
||||
COOKIE_DATA,
|
||||
COOKIE_DBG,
|
||||
'torhelp',
|
||||
'explain',
|
||||
'sql_log',
|
||||
|
@ -487,9 +486,6 @@ class User
|
|||
if ($c_sdata_curr !== $c_sdata_resv) {
|
||||
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