企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 日志 使用经过改造后 [Monolog](https://github.com/Seldaek/monolog) 作为日志组件,改造后支持 Swoole 协程,且扩展了控制台打印日志的功能。 ## 组件 使用 [composer]([https://www.phpcomposer.com/](https://www.phpcomposer.com/)) 安装: ~~~ composer require mix/monolog ~~~ ## 依赖注入配置 - [manifest/beans/log.php](https://github.com/mix-php/mix-skeleton/blob/master/manifest/beans/log.php) ## 获取实例 通过依赖配置获取实例: ~~~ /** @var \Mix\Monolog\Logger $log */ $log = context()->get('log'); ~~~ 在 [StartCommand.php#L43](https://github.com/mix-php/mix-skeleton/blob/master/app/Api/Commands/StartCommand.php#L43) 种配置处理器: ~~~ // 设置日志处理器 $this->log->withName('API'); $handler = new RotatingFileHandler(sprintf('%s/runtime/logs/api.log', app()->basePath), 7); $this->log->pushHandler($handler); ~~~ ## PSR 定义方法 | 方法 | | --- | | emergency($message, array $context = []) : bool | | alert($message, array $context = []) : bool | | critical($message, array $context = []) : bool | | error($message, array $context = []) : bool | | warning($message, array $context = []) : bool | | notice($message, array $context = []) : bool | | debug($message, array $context = []) : bool | | log($level, $message, array $context = []) : bool | - Sample: ``` $message = 'UserId: {userId}, Name: {name}'; $context = ['userId' => 1008, 'name' => 'your name']; $log->info($message, $context); ```