PHP code example of devthis / console-logg

1. Go to this page and download the library: Download devthis/console-logg 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/ */

    

devthis / console-logg example snippets


// generally only 
    //...
    \DevThis\ConsoleLogg\Providers\ConsoleLoggServiceProvider::class,
];

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;
    }
}

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;
    }
}