Any convenient way to log data into the console and debug Laravel Envoy Blade file

601 views Asked by At

I am trying to debug Laravel Envoy Blade file with @setup configuration block.

@setup
// some PHP config code here...
echo('Deploy started');
@endsetup
@servers(['web' => '-q -A ' . $sshOptions . ' "' . $server . '"', 'localhost' => '127.0.0.1'])
@task('deploy:setup', ['on' => 'web'])
// some deploy commands here...
@endtask

I've got "Whoops, looks like something went wrong" error message in the console. This message is not enough to understand what's wrong. I suppose there is a convenient way to debug Laravel envoy blade files line by line? To log something into the console?

Whoops, looks like something went wrong

As you can see nothing returned into the console despite echo exists in the @setup block of the Blade file

As far i have found a solution, it is dirty but i can check configuration variables throwing an error with some data i want to check :)

enter image description here enter image description here

2

There are 2 answers

1
brombeer On

In your @setup section you could define functions to log different types of messages by setting bash colors. Make sure to return PHP code that can then be executed, not echo the message itself.

@setup
function logSuccess($message) { return "echo '\033[32m" .$message. "\033[0m';\n"; }
function logWarn($message) { return "echo '\033[31m" .$message. "\033[0m';\n"; }
function logInfo($message) { return "echo '\033[36m" .$message. "\033[0m';\n"; }
function logLine($message) { return "echo '" .$message. "';\n"; }
@endsetup

In any Envoy task you could now do something like

{{ logSuccess('Application deployed!') }}

to print out Application deployed in green text.

If you simple want to output a message in your "standard" bash color use

{{ logLine('Application deployed!') }}
0
Alex On

I am pretty sure there are more elegant solutions exist .My solution is to throw exception with the variable you want to dump right from the @setup block.

@setup
$var = 'test';
throw new Exception('Your var '. $var);
@endsetup

So you will get your debuf info, but it will be thrown and code will not be executed further. enter image description here