简体   繁体   中英

How do I log properly a Laravel Job?

Reading the official documentation I understand that it's necessary to use Illuminate\Support\Facades\Log , but the configuration in logging.php is a bit confusing to me. I basically don't understand how the channel drivers work, it seems to me a bit overcomplicated.

Logging commands, however, is pretty easy in my opinion: you just add ->appendOutputTo('command.log') in the schedule method and the job is pretty much done. Is there a similar method to log jobs? Or is the way in the documentation the only one? If so, could anyone be kind enough to simplify it to me?

It is simple to use the Log facade,

Go to loggin.php and add a new channel, here is a signle log file example (without rotation)

'job' =>  [
            'driver' => 'single',
            'path' => storage_path('logs/job.log'),
            'level' => 'info',
        ],

Then use it anywhere with

Log::channel('job')->info($content);
//or
Log::channel('job')->error($content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM