Skip to content
Advertisement

Heroku not showing log messages created during scheduled tasks

I’m using Heroku to host a Lumen app. I’ve setup the logging to send messages to stdout:

// bootstrap/app.php
$app->configureMonologUsing(function ($monolog) {
    /** @var MonologLogger $monolog */
    $monolog->pushHandler(new MonologHandlerStreamHandler('php://stdout', MonologLogger::DEBUG));
});

I’ve tested this works by adding a log message to the schedule function

protected function schedule(Schedule $schedule)
{
    Log::info('Running cronjobs.');

    $schedule
        ->command('update:daily')
        ->timezone('America/Los_Angeles')
        ->everyMinute();
}

The Heroku logs show:

Jan 19 09:42:15 service app/scheduler.4140: [2018-01-19 17:42:14] lumen.INFO: Running cronjobs. [] [] 
Jan 19 09:42:15 service app/scheduler.4140: Running scheduled command: '/app/.heroku/php/bin/php' artisan update:daily > '/dev/null' 2>&1

However the update:daily command has a number of log messages inside it and none of them are showing up.

I thought this might be because of the > '/dev/null' so I tried adding ->sendOutputTo('php://stdout') and ->sendOutputTo(base_path('storage/logs/cronjobs.log')) to the scheduled task but neither works.

Here’s my Procfile:

web: vendor/bin/heroku-php-nginx -C heroku-nginx.conf -l storage/logs/cronjobs.log public/

Advertisement

Answer

Laravel uses the > '/dev/null' when you do not call ->sendOutputTo(). I couldn’t figure out an appropriate way to use the ->sendOutputTo() function to send to stdout.

What I did to fix this issue was change the ->command() function to a ->call(function(){}) function and executed the same single line of code the terminal command could have called. When laravel calls a Closure, it does not dump the output to > '/dev/null'.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement