实现 think/queue 日志分离

当我们使用think/queue包含了比较多的不同队列,日志会写到runtime/log目录下,合并写入的,不好排查问题,我们遇到一个比较严重的就是用了不同用户来执行,权限冲突了,导致部分队列执行不了.

为了解决以上问题,本来希望通过Log::init设置不同日志路径的,但是本地测试没生效,于是用了一下方案:

  1. event中AppInit添加QueueLog
php 复制代码
<?php
// 事件定义文件

use app\common\event\QueueLog;

return [
    'bind'      => [
    ],

    'listen'    => [
        'AppInit'  => [QueueLog::class],
        'HttpRun'  => [],
        'HttpEnd'  => [],
        'LogLevel' => [],
        'LogWrite' => [],
    ],

    'subscribe' => [
    ],
];
  1. 创建QueueLog事件
php 复制代码
<?php
namespace app\common\event;

use think\App;
use think\facade\Request;

class QueueLog
{
    public function handle(App $app): bool
    {
        if (!Request::isCli()) {
            return true;
        }
        $args = (array) $_SERVER['argv'];
        foreach ($args as $arg) {
            if (str_starts_with($arg, '--queue=')) {
                $queueName = substr($arg, 8);
                $app->setRuntimePath($app->getRuntimePath() . '/' . 'queue' . '-' . $queueName . '/');
                break;
            }
        }
        return true;
    }
}

这样的话,不同队列的日志就写到不同的路径下了

相关推荐
2601_9657984715 分钟前
Salient Theme Setup Guide for Fast Creative WordPress Sites
数据库·web3·php·wordpress
xixiaoyunya7 小时前
中小微企业轻量组网方案的技术选型与实践:从传统专线到软定义隧道的成本与效能分析
服务器·php·apache
知行产研8 小时前
中国矿山无人驾驶出海的三重门
数据库·mysql·php
前进的程序员10 小时前
告别Copilot?Codex本地化部署指南
开源·php·copilot·codex
weixin_BYSJ198710 小时前
springboot智慧公共交通系统---附源码51123
java·javascript·spring boot·python·django·flask·php
外滩运维专家1 天前
通配符证书到期,阿里云上几个服务的证书怎么一次换完
运维·开发语言·nginx·https·php·消息推送
郑州光合科技余经理1 天前
海外版多语言团购系统架构:主数据互通与核销边界
java·开发语言·前端·后端·系统架构·php·ai编程
heimeiyingwang1 天前
【架构实战】Kubernetes网络模型深度解析:从Pod通信到Ingress网关实战
开发语言·架构·php
运维行者_1 天前
预测性云监控怎么做?AI驱动的7大核心能力与落地路径
服务器·开发语言·网络·数据库·人工智能·python·php
eggrall1 天前
Socket编程UDP
网络协议·udp·php