Laravel 5.6 将 QueuedCommand 消息更改为更具可读性的内容



所以,

a 我第一次尝试使用 Commands 类,我想让队列消息更具可读性,然后[2018-09-01 17:57:47][276] Processing: IlluminateFoundationConsoleQueuedCommand

因此,我所做的是以下几点;

我用protected $signature = 'recording:convert {recording_id}';protected $description = 'Convert a recording from mkv to mp4 using an recording id and making use of ffmpeg';注册了命令ConvertRecording。这有一个空的构造函数,因为我不需要将对象传递给它......句柄方法只有一些工作代码和一些$this->log()命令......

现在,当我调用工匠命令时,我使用以下代码:

$exitCode = Artisan::queue('recording:convert', [
'recording_id' => $recording_id
]);

它附加到队列中,但我只收到如下消息:

[2018-09-01 17:57:47][276] Processing: IlluminateFoundationConsoleQueuedCommand
[2018-09-01 17:58:16][276] Processed:  IlluminateFoundationConsoleQueuedCommand

我怎么能把它改成类似[2018-09-01 17:58:16] Procesing: Video with ID [video ID here]

可能是您希望对排队命令执行某些操作,而这些命令并不是真正要做的。您在日志中看到的内容正是作业要执行的操作 - 即报告何时启动以及何时完成(或失败(。它是完成有用工作的命令,因此所有输出和日志记录都应在那里完成。

命令当然有一些控制台日志记录工具,例如错误、信息和注释,可以帮助您进行调试:

$this->error('This is an error and will appear highlighted in the console');
$this->info('This is information');
$this->comment('This is a comment');

但是,在生产环境中使用这些可能不起作用,因为您的队列工作线程不会登录到控制台(我可能弄错了,因为我从未尝试过查看(。

我建议使用服务提供商为您的命令设置一个专用的日志文件。

最新更新