优化导出面板;删除部分垃圾文件;引入数据库日志;

This commit is contained in:
2022-06-02 14:34:07 +08:00
parent 8bc73f83de
commit 22587e40bd
4 changed files with 126 additions and 4 deletions

View File

@@ -1 +0,0 @@

1
extend/.gitignore vendored
View File

@@ -1,2 +1 @@
*
!.gitignore !.gitignore

View File

@@ -0,0 +1,125 @@
<?php
namespace think\log\driver;
use think\contract\LogHandlerInterface;
use think\facade\App;
use PDO;
class DebugMysql implements LogHandlerInterface
{
protected $enableLog = true;
protected $config = [];
protected $pdo = null;
protected $tableName = '';
public function __construct(App $app, $config = [])
{
if (is_array($config)) {
$this->config = array_merge($this->config, $config);
}
$dsn = $this->parseDsn($config);
$pdo = $this->createPdo($dsn, $config['username'], $config['password'], $config['params']);
$this->pdo = $pdo;
$this->tableName = $config['prefix'] . 'debug_log';
}
public function save(array $log): bool
{
$app_name = app('http')->getName() ?: '';
$controller_name = request()->controller();
$action_name = request()->action();
if (App::runningInConsole()) {
$app_name = 'cli';
}
$create_time = time();
$create_time_title = date('Y-m-d H:i:s', $create_time);
$log_key = uniqid();
foreach ($log as $log_level => $log_list) {
foreach ($log_list as $key => $log_item) {
if (!is_string($log_item)) {
$log_item = json_encode($log_item, JSON_UNESCAPED_UNICODE);
}
$log_data = [
'level' => $log_level,
'content' => $log_item,
'create_time' => $create_time,
'create_time_title' => $create_time_title,
'uid' => $log_key,
'app_name' => $app_name,
'controller_name' => $controller_name,
'action_name' => $action_name,
];
foreach ($log_data as $key => &$value) {
$value = str_replace('\'', '\\\'', $value);
}
$data_keys = array_keys($log_data);
$data_keys_in_sql = join(',', $data_keys);
$data_values_in_sql = join('\',\'', $log_data);
$sql = "INSERT INTO {$this->tableName} ($data_keys_in_sql) VALUES ('$data_values_in_sql');";
$this->pdo->exec($sql);
}
}
return true;
}
/**
* 解析pdo连接的dsn信息
* @access protected
* @param array $config 连接信息
* @return string
*/
protected function parseDsn(array $config): string
{
if (!empty($config['socket'])) {
$dsn = 'mysql:unix_socket=' . $config['socket'];
} elseif (!empty($config['hostport'])) {
$dsn = 'mysql:host=' . $config['hostname'] . ';port=' . $config['hostport'];
} else {
$dsn = 'mysql:host=' . $config['hostname'];
}
$dsn .= ';dbname=' . $config['database'];
if (!empty($config['charset'])) {
$dsn .= ';charset=' . $config['charset'];
}
return $dsn;
}
protected function createPdo($dsn, $username, $password, $params)
{
return new PDO($dsn, $username, $password, $params);
}
public function __destruct()
{
$this->pdo = null;
}
}

View File

@@ -52,9 +52,8 @@
<div id="post-desc"> <div id="post-desc">
{$post.desc} {$post.desc}
</div> </div>
<article id="post-content" class="ul-content"> <article id="post-content" class="ul-content">
{notempty name='$post.poster'} {notempty name='$post->getData("poster")'}
<div id="post-title-img"> <div id="post-title-img">
<img src="{$post.poster}" alt=""> <img src="{$post.poster}" alt="">
</div> </div>