PHPackages                             arcostasi/console-log - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. arcostasi/console-log

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

arcostasi/console-log
=====================

Console Log Facade for Laravel

v1.1.5(6y ago)2431MITPHPPHP &gt;=7.0.0

Since May 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/arcostasi/console-log)[ Packagist](https://packagist.org/packages/arcostasi/console-log)[ Docs](https://github.com/arcostasi/console-log)[ RSS](/packages/arcostasi-console-log/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

Console Log Facade for Laravel 5.x
==================================

[](#console-log-facade-for-laravel-5x)

The JavaScript console is an invaluable tool to help develop and debug our apps. With the console object and its logging methods, long are the days of calling alert() to debug and get a variable’s value. On top of that, thanks to a work in progress standard, modern browsers are finally supporting the same set of methods.

### Requirements

[](#requirements)

- PHP 7.0 or higher
- Laravel 5.0 or higher

### Installation

[](#installation)

```
composer require arcostasi/console-log

```

And now you can publish your config:

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

```

Add to `config/app.php`

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

Usage
-----

[](#usage)

Add in your blade view template:

```

@if(Session::has('console.log'))

    @foreach(Session::get('console.log') as $console)
    {!! $console !!}
    @endforeach

{{ Session::forget('console.log') }}
@endif
```

and add Console facade in your PHP files (controllers or models):

```
use Console;
```

### Logging

[](#logging)

Console::Log is the usual method we use to log values out to the 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
```

But we also have access to more logging methods like warn, info and error:

```
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 💣');
```

As you can see from the resulting console output, using the warn or error methods also gives us a stack trace:

[![](https://github.com/arcostasi/console-log/raw/master/img/logging-methods.png?raw=true)](https://github.com/arcostasi/console-log/blob/master/img/logging-methods.png?raw=true)

You can also prints out objects with Debug method:

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

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

or you can also trigger a stack trace with Trace method:

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

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

Result from console output:

[![](https://github.com/arcostasi/console-log/raw/master/img/trace.png?raw=true)](https://github.com/arcostasi/console-log/blob/master/img/trace.png?raw=true)

### Table

[](#table)

If you feel so inclined, you can even display data in the console more neatly in a table format using Table method:

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

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

As you can see from the resulting console output, using the Table method:

[![](https://github.com/arcostasi/console-log/raw/master/img/table.png?raw=true)](https://github.com/arcostasi/console-log/blob/master/img/table.png?raw=true)

### Dir &amp; DirXML

[](#dir--dirxml)

Console Dir and DirXML prints out objects in a nice formatted way:

```
