Download the PHP package illuminated/console-logger without Composer
On this page you can find all versions of the php package illuminated/console-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download illuminated/console-logger
More information about illuminated/console-logger
Files in illuminated/console-logger
Package console-logger
Short Description Logging and Notifications for Laravel Console Commands.
License MIT
Informations about the package console-logger
Laravel Console Logger
Logging and Notifications for Laravel Console Commands.
Laravel | Console Logger |
---|---|
12.x | 12.x |
11.x | 11.x |
10.x | 10.x |
9.x | 9.x |
8.x | 8.x |
7.x | 7.x |
6.x | 6.x |
5.8.* | 5.8.* |
5.7.* | 5.7.* |
5.6.* | 5.6.* |
5.5.* | 5.5.* |
5.4.* | 5.4.* |
5.3.* | 5.3.* |
5.2.* | 5.2.* |
5.1.* | 5.1.* |
Table of contents
- Usage
- Available methods
- Channels
- File channel
- Notification channels
- Email channel
- Database channel
- Error handling
- Exceptions with context
- Guzzle 6+ integration
- Powered by Monolog
- Troubleshooting
- Trait included, but nothing happens?
- Several traits conflict?
- Sponsors
- License
Usage
-
Install the package via Composer:
-
Use
Illuminated\Console\Loggable
trait: - Run the command and check your logs:
Available methods
The Loggable
trait provides these PSR-3 methods:
logDebug()
logInfo()
logNotice()
logWarning()
logError()
logCritical()
logAlert()
logEmergency()
Use them in your console commands to log required information.
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 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:
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). 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
The email channel provides notifications via email.
Set the recipients, and email notifications are ready to go!
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:
Database channel
The database channel provides a way to save notifications in the database.
The easiest way to start using it:
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:
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
Sometimes it's useful to pass an additional context of the thrown exception.
Use the Illuminated\Console\Exceptions\RuntimeException
for that:
Guzzle 6+ integration
If you're using Guzzle, you might want to have a full log of your HTTP interactions.
The iclogger_guzzle_middleware()
function provides a pre-configured Guzzle Middleware for that:
If you're using JSON, you might want to get auto decoding for your request params and response bodies:
Also, you can disable logging of specific request params and/or response bodies, based on your custom logic:
Powered by Monolog
This package uses the powerful Monolog Logger.
You can access the underlying instance of Monolog by:
-
Using the command's
icLogger()
method: - Or via the Laravel's Service Container:
Troubleshooting
Trait included, but nothing happens?
Loggable
trait overrides the initialize()
method:
If your command overrides the initialize()
method too, you have to call the initializeLogging()
method by yourself:
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:
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:
Sponsors
License
Laravel Console Logger is open-sourced software licensed under the MIT license.
All versions of console-logger with dependencies
illuminate/console Version ^12.0
illuminate/support Version ^12.0
illuminated/helper-functions Version ^12.0
monolog/monolog Version ^3.0
psr/http-message Version ^1.0
psr/log Version ^1.0|^2.0|^3.0
symfony/finder Version ^7.2