【问题标题】:Call to undefined method when trying to log event in laravel 8.0尝试在 laravel 8.0 中记录事件时调用未定义的方法
【发布时间】:2020-11-21 22:01:38
【问题描述】:

所以我正在尝试记录一个事件(如果它不成功),但我总是收到此错误

调用未定义的方法 Monolog\Logger::single() 这是我在 app/console/commands 目录中的控制器代码。

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Illuminate\Support\Facades\Log;

class FPTrainCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'FPTrain:command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        date_default_timezone_set('EST');
        $FPTree_date = date("Y-m-d");
        $my_array = array("$FPTree_date","association", "test");
        $FPJson = json_encode($my_array);
        $process = new Process(["python3", "public/python/FP_Tree.py", "$FPJson"]);
        $process->run();

        // executes after the command finishes
        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
            $date = date('l jS \of F Y h:i:s A');

        }
        Log::single("$FPTree_date Error Executing the daily association script");
        echo $FPJson;
        //dump(json_decode($process->getOutput(), true));
    }
}

我不确定自己做错了什么。

感谢您的帮助

【问题讨论】:

  • 消息很清楚:Monolog Logger 没有single 方法。你从哪里得到这个方法的?
  • 对不起,我的脑袋放屁了,这应该是说:你从哪里得到这个错误?哪一行,什么文件……

标签: php laravel logging laravel-8


【解决方案1】:

laravel 日志中没有单一的方法。

根据https://laravel.com/docs/8.x/logging,这些是你可以使用的功能:

Log::emergency($message);
Log::alert($message);
Log::critical($message);
Log::error($message);
Log::warning($message);
Log::notice($message);
Log::info($message);
Log::debug($message);

【讨论】:

  • 谢谢,现在我必须弄清楚为什么不将数据写入应该存储日志的文件夹中,但这让我很头疼。不知道我在哪里选择了单人线。
  • 检查文件config/logging.php
猜你喜欢
  • 2021-03-07
  • 1970-01-01
  • 2020-11-27
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 2014-04-04
  • 2015-06-24
相关资源
最近更新 更多