noobtoob's avatar

Output from cron jobs

Hi all

I'm working with cron jobs in laravel and I'm a bit confused about how to log stuff from within my scripts.

Of course I can save the 'system output' like so

x x x x x php /pathto/artisan schedule:run >> /someath/storage/somelog.log 2>&1

but that doesn't include stuff I want to output from the scripts. I think I know how to output to the general laravel (daily, fx) log. But I don't want to mix it up with errors and stuff.

Any pointers highly appreciated!

Cheers

0 likes
2 replies
willvincent's avatar
Level 54

Pretty easy to spin up a custom log on the fly...

use Monolog\Handler\StreamHandler;
use Monolog\Logger;

class SomeClass {

private $customLog;

function __construct() {
  $this->customLog = new Logger('Log Name');
  $this->customLog->pushHandler(new StreamHandler(storage_path('logs/custom.log'), Logger::INFO));
}

// elsewhere in class...

$this->customLog->error('Some error message');
$this->customLog->warning('a warning');
1 like

Please or to participate in this conversation.