Effortless artisan console output with your usual Laravel logger
devthis/console-logg is a Laravel package for effortless artisan console output with your usual laravel logger.
It currently has 11 GitHub stars and 15.197 downloads on Packagist (latest version v1.3.0).
Install it with composer require devthis/console-logg.
Discover more Laravel packages by devthis
or browse all Laravel packages to compare alternatives.
Last updated
Powered by Symfony's Console Logger
Logger channel for sharing messages between application and console commands
Typically, this requires a hacky solution, such as coupling your shared services with a console logger, or configuring multiple driver channels.
With ConsoleLogg you can have logs for your artisan commands, and behave as usual with http/controllers.
No code changes are required with logger usage
Supported:
LoggerInterface $logger & $logger->debug("yeet")logger()->critical("Send help")Log::alert("She find pictures in my email")Log::info("Found <X> to be processed")php artisan my:command -vvv
[debug] yeet
[critical] Send help
[alert] She find pictures in my email
[info] Found <X> to be processed
Install the package via Composer:
composer require devthis/console-logg
Enable logging channel console-logg
config/logging.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'channels' => ['console-logg', 'single'],
'ignore_exceptions' => false,
],
| Compatible | Laravel | |--------------------|---------| | :heavy_check_mark: | 10.* | | :heavy_check_mark: | 9.* | | :heavy_check_mark: | 8.* | | :heavy_check_mark: | 7.* | | :heavy_check_mark: | 6.* |
Logger output will be shown in your local development server console.
Your application will not be coupled with ConsoleLogg.
There are no traits, classes, interfaces that you need to use. ConsoleLogg does not require any custom code, it just works.
The ConsoleLog Service Provider should be automatically added to your app, but if it hasn't, you can add it yourself to config/app.php
// generally only required when you have composer installed with --no-scripts
'providers' => [
//...
\DevThis\ConsoleLogg\Providers\ConsoleLoggServiceProvider::class,
];
ConsoleLogg has (not yet) been tested for compatibility using artisan commands in a command with nested command calls
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MyConsoleApp extends Command
{
protected $description = '';
protected $signature = 'my:app';
public function handle(): int
{
//other:command may invoke services that use the Laravel Logger
//these logs will still output to this current console
$this->call('other:command');
//...
return 0;
}
}
Verbosity is optionally controlled by either using -v arguments when running artisan.
This is not behaviour set by ConsoleLogg, it is defined in combination of Laravel & Symfony
ConsoleLogg may provide configuration for this in the future, if demand is apparent
| Verbosity | Level |
| ---------------|----------------|
| default | emergency, alert, critical, error, warning|
| -v | notice + all of above |
| -vv |info + all of above |
| -vvv | debug + all of above |
There are several guides/answers on the internet that enable you to send all SQL queries to your configured Logger.
With ConsoleLogg installed this means
Links (in no order):
:warning: REMINDER: n-o-t-h-i-n-g is special about this following code example
There are no traits, interfaces, or classes/dependencies that are involved to use ConsoleLogg once it's installed.
namespace App\Service;
use Illuminate\Support\Facades\Log;
use Psr\Log\LoggerInterface;
class MyExampleService {
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function doSomethingCool(): void
{
// using Laravel's logger with DI/autowiring
$this->logger->debug("A message that should have value when output to your application in general");
// Facade
Log::info("or just the facade if you love magic");
// Helper function
logger()->notice("or this weird helper function I guess");
// ... <imaginary useful code here>
}
}
namespace App\Console\Commands;
use App\Service\ExampleService;
use Illuminate\Console\Command;
class ExampleConsole extends Command
{
/**
* The console command description.
*/
protected $description = '';
/**
* The name and signature of the console command.
*/
protected $signature = 'something';
public function handle(ExampleService $exampleService): int
{
$exampleService->doSomethingCool();
return 0;
}
}
not-root@linux:~/MyProject$ php artisan something -vv
[debug] A message that should have value when output to your application in general
[info] or just the facade if you love magic
[notice] or this weird helper function I guess
Laravel ConsoleLogg is open-sourced software licensed under the MIT license.