PHPackages                             illuminated/console-logger - 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. illuminated/console-logger

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

illuminated/console-logger
==========================

Logging and Notifications for Laravel Console Commands.

12.0.0(1y ago)8674.9k—10%12[1 PRs](https://github.com/dmitry-ivanov/laravel-console-logger/pulls)MITPHPPHP ^8.2CI passing

Since Jun 14Pushed 1y ago5 watchersCompare

[ Source](https://github.com/dmitry-ivanov/laravel-console-logger)[ Packagist](https://packagist.org/packages/illuminated/console-logger)[ RSS](/packages/illuminated-console-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (135)Used By (0)

[![Logging and Notifications for Laravel Console Commands](art/1380x575-optimized.jpg)](art/1380x575-optimized.jpg)

Laravel Console Logger
======================

[](#laravel-console-logger)

[![Buy me a coffee](https://user-images.githubusercontent.com/1286821/181085373-12eee197-187a-4438-90fe-571ac6d68900.png)](https://buymeacoffee.com/dmitry.ivanov)

[![StyleCI](https://camo.githubusercontent.com/e2892284a9a1988ed131fc9866286a078029b611ecc60781cf03f7d673f447e8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f36313131373736382f736869656c643f6272616e63683d6d6173746572267374796c653d666c6174)](https://github.styleci.io/repos/61117768?branch=master)[![Build Status](https://camo.githubusercontent.com/f0b3ec7cd54a2e35c6fe37a7924d2e6629f2ad871567ff93964721d25bfd515c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646d697472792d6976616e6f762f6c61726176656c2d636f6e736f6c652d6c6f676765722f74657374732e796d6c3f6272616e63683d6d6173746572)](https://github.com/dmitry-ivanov/laravel-console-logger/actions?query=workflow%3Atests+branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/aa7f8202ab292614882ef7b314a6fff9b0fe82c24aab8d61897628da64e9f2e1/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f646d697472792d6976616e6f762f6c61726176656c2d636f6e736f6c652d6c6f676765722f6d6173746572)](https://app.codecov.io/gh/dmitry-ivanov/laravel-console-logger/tree/master)

[![Packagist Version](https://camo.githubusercontent.com/13745f0ccc4ac64c4171dba3275a85b20d0178ed7e8801113ce1e7ff43eaac2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)](https://camo.githubusercontent.com/13745f0ccc4ac64c4171dba3275a85b20d0178ed7e8801113ce1e7ff43eaac2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)[![Packagist Stars](https://camo.githubusercontent.com/7202f92b758a56c58cedba4cb979eabc518f978caf4f169da70bdd9561d31da1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)](https://camo.githubusercontent.com/7202f92b758a56c58cedba4cb979eabc518f978caf4f169da70bdd9561d31da1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)[![Packagist Downloads](https://camo.githubusercontent.com/e07919f4d728d330013fbb61b953135270f402f781147c49e8f8704087c66810/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)](https://camo.githubusercontent.com/e07919f4d728d330013fbb61b953135270f402f781147c49e8f8704087c66810/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)[![Packagist License](https://camo.githubusercontent.com/cc22ae9e0928632caf93769403ab067ac24ea48e9b42de1c94084d8e8f061042/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)](https://camo.githubusercontent.com/cc22ae9e0928632caf93769403ab067ac24ea48e9b42de1c94084d8e8f061042/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696c6c756d696e617465642f636f6e736f6c652d6c6f67676572)

Logging and Notifications for Laravel Console Commands.

LaravelConsole Logger12.x[12.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/12.x)11.x[11.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/11.x)10.x[10.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/10.x)9.x[9.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/9.x)8.x[8.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/8.x)7.x[7.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/7.x)6.x[6.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/6.x)5.8.\*[5.8.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.8)5.7.\*[5.7.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.7)5.6.\*[5.6.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.6)5.5.\*[5.5.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.5)5.4.\*[5.4.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.4)5.3.\*[5.3.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.3)5.2.\*[5.2.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.2)5.1.\*[5.1.\*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.1)[![Laravel Console Logger - Demo](doc/img/demo.gif)](doc/img/demo.gif)

Table of contents
-----------------

[](#table-of-contents)

- [Usage](#usage)
- [Available methods](#available-methods)
- [Channels](#channels)
    - [File channel](#file-channel)
    - [Notification channels](#notification-channels)
        - [Email channel](#email-channel)
        - [Database channel](#database-channel)
- [Error handling](#error-handling)
    - [Exceptions with context](#exceptions-with-context)
- [Guzzle 6+ integration](#guzzle-6-integration)
- [Powered by Monolog](#powered-by-monolog)
- [Troubleshooting](#troubleshooting)
    - [Trait included, but nothing happens?](#trait-included-but-nothing-happens)
    - [Several traits conflict?](#several-traits-conflict)
- [Sponsors](#sponsors)
- [License](#license)

Usage
-----

[](#usage)

1. Install the package via Composer:

    ```
    composer require illuminated/console-logger
    ```
2. Use `Illuminated\Console\Loggable` trait:

    ```
    use Illuminated\Console\Loggable;

    class ExampleCommand extends Command
    {
        use Loggable;

        public function handle()
        {
            $this->logInfo('Hello World!');
        }

        // ...
    }
    ```
3. Run the command and check your logs:

    ```
    [2020-05-11 17:19:21]: [INFO]: Command `App\Console\Commands\ExampleCommand` initialized.
    [2020-05-11 17:19:21]: [INFO]: Host: `MyHost.local` (`10.0.1.1`).
    [2020-05-11 17:19:21]: [INFO]: Database host: `MyHost.local`, port: `3306`, ip: ``.
    [2020-05-11 17:19:21]: [INFO]: Database date: `2020-05-11 17:19:21`.
    [2020-05-11 17:19:21]: [INFO]: Hello World!
    [2020-05-11 17:19:21]: [INFO]: Execution time: 0.009 sec.
    [2020-05-11 17:19:21]: [INFO]: Memory peak usage: 8 MB.

    ```

Available methods
-----------------

[](#available-methods)

The `Loggable` trait provides these [PSR-3](http://www.php-fig.org/psr/psr-3/) methods:

- `logDebug()`
- `logInfo()`
- `logNotice()`
- `logWarning()`
- `logError()`
- `logCritical()`
- `logAlert()`
- `logEmergency()`

Use them in your console commands to log required information.

Channels
--------

[](#channels)

Log messages could be handled in multiple different ways.

It might be writing data into the log file, storing it in the database, sending an email, etc.

### File channel

[](#file-channel)

File channel simply writes log messages into the log file.

Each of the commands would have a separate folder within the `storage/logs` dir.

For example, `foo-bar` command logs would be stored in the `storage/logs/foo-bar` folder.

You can customize the storage folder, and the max number of stored log files by overriding proper methods:

```
class ExampleCommand extends Command
{
    use Loggable;

    protected function getLogPath()
    {
        return storage_path('logs/custom-folder/date.log');
    }

    protected function getLogMaxFiles()
    {
        return 45;
    }

    // ...
}
```

Notification channels
---------------------

[](#notification-channels)

If you want to be notified about errors in your console commands - use notification channels.

Notification channels are optional and disabled by default. Each of them could be enabled and configured as needed.

By default, you'll get notifications with a level higher than NOTICE (see [PSR-3 log levels](https://www.php-fig.org/psr/psr-3/#5-psrlogloglevel)). It means that you'll get NOTICE, WARNING, ERROR, CRITICAL, ALERT, and EMERGENCY notifications, by default.

Of course, you can customize that, as well as other channel-specific details.

### Email channel

[](#email-channel)

The email channel provides notifications via email.

Set the recipients, and email notifications are ready to go!

```
class ExampleCommand extends Command
{
    use Loggable;

    protected function getEmailNotificationsRecipients()
    {
        return [
            ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
            ['address' => 'jane.smith@example.com', 'name' => 'Jane Smith'],
        ];
    }

    // ...
}
```

There's a bunch of methods related to the email channel.

By overriding those methods, you can change the subject, `from` address, notification level, etc.

Deduplication is another useful feature worth mentioning. Sometimes the same error might occur many times in a row. For example, you're using an external web service that is down. Or imagine that the database server goes down. You'll get a lot of similar emails in those cases. Deduplication is the right solution for that.

You can enable it and adjust the time in seconds, for which deduplication works:

```
class ExampleCommand extends Command
{
    use Loggable;

    protected function useEmailNotificationsDeduplication()
    {
        return true;
    }

    protected function getEmailNotificationsDeduplicationTime()
    {
        return 90;
    }

    // ...
}
```

### Database channel

[](#database-channel)

The database channel provides a way to save notifications in the database.

The easiest way to start using it:

```
class ExampleCommand extends Command
{
    use Loggable;

    protected function useDatabaseNotifications()
    {
        return true;
    }

    // ...
}
```

Notifications would be stored in the `iclogger_notifications` table, which would be automatically created if it doesn't exist yet.

Of course, you can customize the table name, and even the saving logic, by overriding proper methods:

```
class ExampleCommand extends Command
{
    use Loggable;

    protected function useDatabaseNotifications()
    {
        return true;
    }

    protected function getDatabaseNotificationsTable()
    {
        return 'custom_notifications';
    }

    protected function getDatabaseNotificationsCallback()
    {
        return function (array $record) {
            CustomNotification::create([
                'level' => $record['level'],
                'level_name' => $record['level_name'],
                'message' => $record['message'],
                'context' => get_dump($record['context']),
                'custom_field' => 'Foo Bar Baz!',
            ]);
        };
    }

    // ...
}
```

Error handling
--------------

[](#error-handling)

Another cool feature that is enabled by default - is error handling.

The package automatically logs everything for you: severe problems - exceptions and fatal errors, and even small things, such as PHP notices and warnings.

Add notifications to that, and you'll immediately know when something goes wrong in your console commands!

### Exceptions with context

[](#exceptions-with-context)

Sometimes it's useful to pass an additional context of the thrown exception.

Use the `Illuminated\Console\Exceptions\RuntimeException` for that:

```
use Illuminated\Console\Exceptions\RuntimeException;

class ExampleCommand extends Command
{
    use Loggable;

    public function handle()
    {
        throw new RuntimeException('Whoops! We have a problem!', [
            'some' => 123,
            'extra' => true,
            'context' => null,
        ]);
    }

    // ...
}
```

```
[2020-05-11 17:19:21]: [ERROR]: Whoops! We have a problem!
array:5 [
    "code" => 0
    "message" => "Whoops! We have a problem!"
    "file" => "/Applications/MAMP/htdocs/icl-test/app/Console/Commands/ExampleCommand.php"
    "line" => 22
    "context" => array:3 [
        "some" => 123
        "extra" => true
        "context" => null
    ]
]

```

Guzzle 6+ integration
---------------------

[](#guzzle-6-integration)

If you're using [Guzzle](https://github.com/guzzle/guzzle), you might want to have a full log of your HTTP interactions.

The `iclogger_guzzle_middleware()` function provides a pre-configured [Guzzle Middleware](https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html) for that:

```
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

// Create a log middleware
$logMiddleware = iclogger_guzzle_middleware($logger);

// Add it to the HandlerStack
$handler = HandlerStack::create();
$handler->push($logMiddleware);

// Use the created handler in your Guzzle Client
$client = new Client([
    'handler' => $handler,
    'base_uri' => 'https://example.com',
]);

// Now, all your HTTP requests and responses would be logged automatically!
// $client->get('/foo');
```

If you're using JSON, you might want to get auto decoding for your request params and response bodies:

```
$logMiddleware = iclogger_guzzle_middleware($logger, 'json');
```

Also, you can disable logging of specific request params and/or response bodies, based on your custom logic:

```
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

// Disable logging of request params for the `/foo` endpoint
$shouldLogRequestParams = function (RequestInterface $request) {
    return ! str_ends_with($request->getUri(), '/foo');
};

// Disable logging of response bodies greater than 100 KB
$shouldLogResponseBody = function (RequestInterface $request, ResponseInterface $response) {
    return $response->getHeaderLine('Content-Length') < 102400;
};

$logMiddleware = iclogger_guzzle_middleware($logger, 'json', $shouldLogRequestParams, $shouldLogResponseBody);
```

Powered by Monolog
------------------

[](#powered-by-monolog)

This package uses the powerful [Monolog Logger](https://github.com/Seldaek/monolog).

You can access the underlying instance of Monolog by:

- Using the command's `icLogger()` method:

    ```
    class ExampleCommand extends Command
    {
        use Loggable;

        public function handle()
        {
            $logger = $this->icLogger();
        }

        // ...
    }
    ```
- Or via the Laravel's Service Container:

    ```
    $logger = app('log.iclogger');
    ```

Troubleshooting
---------------

[](#troubleshooting)

### Trait included, but nothing happens?

[](#trait-included-but-nothing-happens)

`Loggable` trait overrides the `initialize()` method:

```
trait Loggable
{
    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        $this->initializeLogging();

        parent::initialize($input, $output);
    }

    // ...
}
```

If your command overrides the `initialize()` method too, you have to call the `initializeLogging()` method by yourself:

```
class ExampleCommand extends Command
{
    use Loggable;

    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        // You have to call it first
        $this->initializeLogging();

        // Then goes your custom code
        $this->foo = $this->argument('foo');
        $this->bar = $this->argument('bar');
        $this->baz = $this->argument('baz');
    }

    // ...
}
```

### Several traits conflict?

[](#several-traits-conflict)

If you're using another `illuminated/console-%` package, you'll get the "traits conflict" error.

For example, if you're building a loggable command, which [doesn't allow overlapping](https://github.com/dmitry-ivanov/laravel-console-mutex):

```
class ExampleCommand extends Command
{
    use Loggable;
    use WithoutOverlapping;

    // ...
}
```

You'll get the traits conflict, because both of those traits are overriding the `initialize()` method:

> If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.

To fix that - override the `initialize()` method and resolve the conflict:

```
class ExampleCommand extends Command
{
    use Loggable;
    use WithoutOverlapping;

    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        // Initialize conflicting traits
        $this->initializeMutex();
        $this->initializeLogging();
    }

    // ...
}
```

Sponsors
--------

[](#sponsors)

[![Laravel Idea](art/sponsor-laravel-idea.png)](https://laravel-idea.com)
[![Material Theme UI Plugin](art/sponsor-material-theme.png)](https://material-theme.com)

License
-------

[](#license)

Laravel Console Logger is open-sourced software licensed under the [MIT license](LICENSE.md).

[![Buy me a coffee](https://user-images.githubusercontent.com/1286821/181085373-12eee197-187a-4438-90fe-571ac6d68900.png)](https://buymeacoffee.com/dmitry.ivanov)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance44

Moderate activity, may be stable

Popularity44

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~91 days

Total

134

Last Release

438d ago

Major Versions

7.x-dev → 8.3.02021-10-14

8.x-dev → 9.0.02022-05-29

9.x-dev → 10.0.02024-03-06

10.x-dev → 11.x-dev2025-03-05

11.0.0 → 12.x-dev2025-03-06

PHP version history (13 changes)0.1.1PHP &gt;=5.4.0

0.1.14PHP &gt;=5.5.9

1.1.5PHP &gt;=5.6.4

5.5.0PHP &gt;=7.0

5.6.0PHP ^7.1.3

6.0.0PHP ^7.2

7.0.0PHP ^7.2.5

8.0.0PHP ^7.3

6.3.0PHP ^7.2.5|^8.0

8.2.0PHP ^7.3|^8.0

9.0.0PHP ^8.0.2

10.0.0PHP ^8.1

11.x-devPHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b6a68d578b4021fbe05838e8e71ccd44b07879ffda6b7ec05c1deb65d0c88f8?d=identicon)[dmitry-ivanov](/maintainers/dmitry-ivanov)

---

Top Contributors

[![dmitry-ivanov](https://avatars.githubusercontent.com/u/1286821?v=4)](https://github.com/dmitry-ivanov "dmitry-ivanov (717 commits)")

---

Tags

commandconsoleemail-notificationserror-handlingguzzle-middlewarelaravellaravel-packageloggernotificationsconsolelaravelnotificationsloggercommanderror handlingguzzle middlewareemail-notifications

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/illuminated-console-logger/health.svg)

```
[![Health](https://phpackages.com/badges/illuminated-console-logger/health.svg)](https://phpackages.com/packages/illuminated-console-logger)
```

###  Alternatives

[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[ytake/laravel-aspect

Aspect Oriented Programming library for laravel framework, and lumen

138132.2k1](/packages/ytake-laravel-aspect)[devthis/console-logg

Effortless artisan console output with your usual Laravel logger

1112.7k](/packages/devthis-console-logg)[tylercd100/laravel-notify

12152.1k1](/packages/tylercd100-laravel-notify)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
