mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 07:35:34 +08:00
add logging and debugging docs (#260)
This commit is contained in:
@@ -44,6 +44,7 @@ module.exports = {
|
||||
'configuration',
|
||||
'structure',
|
||||
'get_started',
|
||||
'debugging',
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -86,7 +87,8 @@ module.exports = {
|
||||
sidebarDepth: 2,
|
||||
children: [
|
||||
'common/class-alias',
|
||||
'common/global-defines'
|
||||
'common/global-defines',
|
||||
'common/logging',
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
46
docs/components/common/logging.md
Normal file
46
docs/components/common/logging.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# 日志
|
||||
|
||||
框架支持使用支持 [PSR-3](https://github.com/php-fig/log) 的日志组件。
|
||||
|
||||
框架默认使用 `zhamao/logger` 组件作为日志组件,但是用户可以根据自身的需求选择其他的日志组件。
|
||||
|
||||
## 自定义日志组件
|
||||
|
||||
更换日志组件的方式非常方便,只需要在 `Setup` 事件中调用 `ob_logger_register` 函数即可。
|
||||
|
||||
```php
|
||||
#[\Setup]
|
||||
public function setup()
|
||||
{
|
||||
ob_logger_register(new \Your\Logger());
|
||||
}
|
||||
```
|
||||
|
||||
## 获取日志组件
|
||||
|
||||
框架提供了 `logger` 函数来获取日志组件。
|
||||
|
||||
```php
|
||||
logger()->info('Hello World');
|
||||
```
|
||||
|
||||
或者,你也可以通过依赖注入的方式来获取日志组件。
|
||||
|
||||
```php
|
||||
public function __construct(\Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
$logger->info('Hello World');
|
||||
}
|
||||
```
|
||||
|
||||
## 日志级别
|
||||
|
||||
日志组件支持 PSR-3 规范中定义的 8 个日志级别。
|
||||
|
||||
目前,你可以通过传递 `log-level` 命令行参数来设置日志级别。
|
||||
|
||||
```bash
|
||||
./zhamao server --log-level=debug
|
||||
```
|
||||
|
||||
但请注意这仅适用内置的 `zhamao/logger` 组件,如果你使用了其他的日志组件,你需要自行实现日志级别的设置。
|
||||
25
docs/guide/debugging.md
Normal file
25
docs/guide/debugging.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# 调试
|
||||
|
||||
在日常开发中,调试是一个重要的环节。在这里,我们将介绍如何在框架中调试。
|
||||
|
||||
## 日志记录
|
||||
|
||||
框架提供了一个日志记录组件,可以用来记录应用程序的运行日志。日志记录组件的使用方法请参考 [日志记录](/components/common/logging)。
|
||||
|
||||
## 打印变量
|
||||
|
||||
框架集成了 [VarDumper](https://symfony.com/doc/current/components/var_dumper.html) 组件,可以用来打印变量的值。
|
||||
|
||||
```php
|
||||
dump($var);
|
||||
```
|
||||
|
||||
## 调试工具
|
||||
|
||||
根据运行环境的不同(Swoole、Workerman 等),你可以使用不同的调试工具。
|
||||
|
||||
例如,你可以使用 [Xdebug](https://xdebug.org/) 或 [yasd](https://github.com/swoole/yasd) 等。
|
||||
|
||||
## 热更新
|
||||
|
||||
框架提供了热更新功能,可以在不重启应用程序的情况下更新代码,方便调试。热更新功能的使用方法请参考 [热更新](/components/common/hot-update)。
|
||||
Reference in New Issue
Block a user