Logging in Iron.io Workers
Previously I wrote about how to use Lumen and Iron.io this adds to that by modifying the logging technique.
As noted the worker is basically a class that sets things up, hands off the payload to the handler and returns the results.
<?php
use App\CompareFuseHandler;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
require_once __DIR__ . '/libs/bootstrap.php';
$payload = getPayload(true);
fire($payload);
function fire($payload)
{
$logs = storage_path('logs/lumen.log');
Log::info(sprintf("Starting Worker at %s", \Carbon\Carbon::now()));
try
{
//Empty Logs
$handler = App::make('App\CompareFuseHandler');
$handler->handle($payload);
echo "Success See Logs Below: \n";
Log::info(sprintf("Ending Worker at %s", \Carbon\Carbon::now()));
echo File::get($logs);
}
catch(\Exception $e)
{
echo "Error See Logs Below: \n";
Log::info(sprintf("Ending Worker at %s", \Carbon\Carbon::now()));
echo File::get($logs);
}
}
The nice thing about above is that all throughout my handler class I can start the do Log::info('foo')
to store up a report for the end of the process on either Success or Error.
Other options of course are BugSnag and PaperTrail
comments powered by Disqus