PHP code example of arcostasi / console-log

1. Go to this page and download the library: Download arcostasi/console-log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arcostasi / console-log example snippets


'aliases' => [
  ...
  'Console' => Arcostasi\ConsoleLog\Facades\Console::class,

use Console;

Console::Log("Hello\nConsole!!!");      // Displays as text with break line
Console::Log(2 + (2 * 3));              // Calculates the number and prints the result as text
Console::Log(new \DateTime());          // Displays as an Object
Console::Log(\App\Models\User::all());  // Displays as an Array

Console::Warn('This is an example of WARNING!!');
Console::Info('This is an example of INFO!');
Console::Error('This is an example of ERROR!!! Boom 💣');

use App\Models\User;
use Console;
  ...

Console::Debug(User::all());

use App\Models\User;
use Console;
  ...

Console::Trace(User::all());

use App\Models\User;
use Console;
  ...

Console::Table(User::all(['name', 'email']));


use Console;
  ...

$text = 'hello';

// This is a example with heredoc
$html = <<<HTML
<!DOCTYPE html>
<html lang="en">

<head>
  <!-- ... -->
</head>

<body>
  <h1>$text</h1>

  <script>
    console.dirxml(document.body);
  </script>
</body>

</html>
HTML;

Console::DirXML($html);

Console::Clear();

Console::Assert(2 == '2', '2 not == to "2"'); // this will pass, nothing will be logged
Console::Assert(3 === '3', '3 not === to "3"'); // this fails, '3 not === to "3"' will be logged

for ($i = 1; $i <= 5; $i++) {
    if ($i % 2 === 0) {
        Console::Count('even');
    } else {
        Console::Count('odd');
    }
}

use Console;

Console::Time('fetching data');

$client = new \GuzzleHttp\Client();
$response = $client->get('https://api.github.com/user', ['auth' =>  ['user', 'pwd']]);
Console::Log("Status: {$response->getStatusCode()}"); // Status 200
Console::Log("Content-type: {$response->getHeaderLine('content-type')}"); // Content-type
Console::Log($response->getBody()->getContents());    // Object result

Console::TimeEnd('fetching data');

Console::Group('🖍️ colors');
Console::Log('red');
Console::Log('orange');
Console::Group('HEX');
Console::Log('#FF4C89');
Console::Log('#7186FE');
Console::GroupEnd();
Console::Log('blue');
Console::GroupEnd();

php artisan vendor:publish --provider="Arcostasi\ConsoleLog\ConsoleLogServiceProvider"