1. Go to this page and download the library: Download mhcg/monolog-wp-cli 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/ */
mhcg / monolog-wp-cli example snippets
use Monolog\Logger;
use MHCG\Monolog\Handler\WPCLIHandler;
// create a log channel
$log = new Logger('name');
$log->pushHandler(new WPCLIHandler(Logger::WARNING));
// output to WP-CLI
$log->warning('This is a warning');
$log->error('An error has occurred');
$log->critical('This will report error and exit out');
$log->debug('Only shown when running wp with --debug');
$log->info('General logging - will not be shown when running wp with --quiet');
/**
* Plugin Name: My Plugin
*/
//my-plugin.php
use Monolog\Logger;
use MHCG\Monolog\Handler\WPCLIHandler;
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
die;
}
// Autoload
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
->debug( 'Some geeky stuff');
// the following won't show when wp is run with --quiet
$log->info( ' Started running' );
$log->warning( 'Something happened of note' );
// always shows even with --quiet
$log->error( 'An error has occurred' );
// all done - no real equivalent in Logger of WP_CLI::success
WP_CLI::success( 'Finished running mycommand' );
}
WP_CLI::add_command( 'mycommand', 'mycommand_command' );
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.