mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-01 11:17:54 +08:00
Added logger.
This commit is contained in:
parent
9f04628fa1
commit
f29f1a9011
@ -12,10 +12,10 @@ composer require hyperf/model-cache
|
||||
|
||||
模型缓存的配置在 `databases` 中。示例如下
|
||||
|
||||
| 配置 | 类型 | 默认值 | 备注 |
|
||||
| 配置 | 类型 | 默认值 | 备注 |
|
||||
|:-----------:|:------:|:------------------------------------------------------:|:-----------------------------------:|
|
||||
| handler | string | \Hyperf\DbConnection\Cache\Handler\RedisHandler::class | 无 |
|
||||
| cache_key | string | 'mc:%s:m:%s:%s:%s' | mc:缓存前缀:m:表名:主键KEY:主键值 |
|
||||
| cache_key | string | 'mc:%s:m :%s:%s:%s' | mc:缓存前缀:m :表名:主键KEY:主键值 |
|
||||
| prefix | string | db connection name | 缓存前缀 |
|
||||
| ttl | int | 3600 | 超时时间 |
|
||||
| load_script | bool | true | Redis引擎下 是否使用evalSha代替eval |
|
||||
|
66
zh/logger.md
66
zh/logger.md
@ -0,0 +1,66 @@
|
||||
# 日志
|
||||
|
||||
`hyperf/logger` 组件对 [monolog/monolog](https://github.com/Seldaek/monolog) 进行了封装,默认使用 `Monolog\Handler\StreamHandler`, Swoole 已经对 `fopen`, `fwrite` 等方法进行了协程化,所以只要不将 `useLocking` 设置为true,就不会阻塞协程。
|
||||
|
||||
## 安装
|
||||
|
||||
```
|
||||
composer require hyperf/logger
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
模型缓存的配置在 `logger` 中。示例如下
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'handler' => [
|
||||
'class' => \Monolog\Handler\StreamHandler::class,
|
||||
'constructor' => [
|
||||
'stream' => BASE_PATH . '/runtime/logs/hyperf.log',
|
||||
'level' => \Monolog\Logger::DEBUG,
|
||||
],
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => \Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [
|
||||
'format' => null,
|
||||
'dateFormat' => null,
|
||||
'allowInlineLineBreaks' => true,
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
## 使用
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Hyperf\Logger\LoggerFactory;
|
||||
|
||||
class DemoService
|
||||
{
|
||||
protected $logger;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerFactory::class)->get('logname');
|
||||
}
|
||||
|
||||
public function method()
|
||||
{
|
||||
// Do somthing.
|
||||
$this->logger->info("Your log message.");
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user