Php Laravel-将控制台输出写入日志文件

Php Laravel-将控制台输出写入日志文件,php,laravel,Php,Laravel,我有一个命令,输出一些行: /** * Execute the console command. * * @return mixed */ public function handle() { $this->line(''); $this->info('--------------------------------------------------------'); $this->info('----------------- Com

我有一个命令,输出一些行:

/**
  * Execute the console command.
  *
  * @return mixed
  */
public function handle()
{
    $this->line('');
    $this->info('--------------------------------------------------------');
    $this->info('----------------- Compress documents -------------------');
    $this->info('--------------------------------------------------------');
    $this->line('');
    $progressBar = $this->output->createProgressBar(3);
    $this->info('Selecting files...');
    // ...
    $progressBar->advance();
    $this->info('Processing...');
    // ...
    $progressBar->advance();
    $this->info('Moving files...');
    // ...
    $progressBar->advance();
    $this->info('--------------------------------------------------------');
    $this->info('------------------------ Result ------------------------');
    $this->info('--------------------------------------------------------');
    // ...
    $this->info('Output quality: '.$resolution.'%');
    $this->info('Processed files: '.sizeof($files));
    $this->info('Original size: '.number_format($originalPathSize, 3).'MB');
    $this->info('Compressed size:'.number_format($compressedPathSize, 3).'MB');
    $this->info('Improvement: '.number_format($compressedPathSizeDiff, 3).'MB ('.number_format($compressedPathSizeDiffPercent, 3).'%)');
    $this->info('Total time: '.$timeFormatted);
    // ...
    $this->table($headers, $rows);
    $this->info('Ready!');
}
它就像一个符咒

问题是,现在我需要在生产服务器上运行这个命令(通过SSH),处理所有文件必须花费一些小时。显然,我不想在这段时间内一直登录以查看控制台输出


与调度任务一样,有一些方法可以“自动”将控制台命令输出写入日志文件?

要从artisan命令将输出写入日志,只需调用
$this->info()

$this->info('some text')

编辑:

我的错!对不起


Log::info()。

您可以像这样保存输出

#screen
#php artisan command > /etc/commandResults.log


也许不是,我能想到,但是你可以在这里给你的代码添加你自己的
Log::info()
行,我也使用类似
$this->line(“…”)的行正在写入laravel日志文件。试图弄清楚这是怎么回事。@BramVerstraten
storage/logs/laravel.log
?@AlexandreThebaldicorrect@BramVerstraten奇怪!在多次运行命令后,我的laravel.log将保持不变…OP已被激活。这是它们函数中的大多数命令。那个命令只适用于False。我用
$this->info(“…”)
运行了这个命令,但它没有出现在日志文件中是的,这个想法是您需要一个命令,您应该能够在shell上执行它并获得结果。如果您将其更改为始终写入文件,那么它就失去了拥有命令、使用屏幕和重定向的目的,您应该能够在没有连接问题的情况下执行它。我本来打算推荐一份cron工作,但我认为这不是一个重复的需要。