PHP code example of underpin / logger-loader

1. Go to this page and download the library: Download underpin/logger-loader 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/ */

    

underpin / logger-loader example snippets


plugin_name_replace_me()->logger()->log(
'error',
'error_code',
'error_message',
['arbitrary' => 'data', 'that' => 'is relevant', 'ref' => 1]
);

$error = new \WP_Error('code','Message',['data' => 'to use']);
plugin_name_replace_me()->logger()->log_wp_error('error',$error);

try{
  echo 'hi';
}catch(Exception $e ){
  plugin_name_replace_me()->logger()->log_exception('error', $e);
}

$wp_error_object = plugin_name_replace_me()->logger()->log_as_error(
  'error',
  'error_code',
  'error message',
  ['arbitrary' => 'data', 'that' => 'is relevant']
);

var_dump($wp_error_object); // WP_Error...

$wp_error_object = plugin_name_replace_me()->logger()->log_as_error(
  'error',
  'invalid_product',
  'The product ID ' . $id . ' is invalid'
);

$wp_error_object = plugin_name_replace_me()->logger()->log_as_error(
  'error',
  'invalid_product',
  'An invalid product was referenced',
  ['product_id' => $id]
);

$item_1 = function_that_returns_errors();
$item_2 = another_function_that_returns_errors();

$errors = underpin()->logger()->gather_errors($item_1,$item_2);

if($errors->has_errors()){
  // Do do something if either of the items were a WP Error.
} else{
 // All clear, proceed.
}


namespace Plugin_Name_Replace_Me\Event_Types;
/**
 * Class Background_Process
 * Error event type.
 *
 * @since 1.0.0
 *
 * @since
 * @package
 */
class Background_Process extends Event_Type {

	/**
	 * Event type
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	public $type = 'background_process';

	/**
	 * Writes this to the log.
	 * Set this to true to cause this event to get written to the log.
	 *
	 * @since 1.0.0
	 *
	 * @var bool
	 */
	protected $write_to_log = true;

	/**
	 * @var inheritDoc
	 */
	public $description = 'Logs when background processes run.';

	/**
	 * @var inheritDoc
	 */
	public $name = "Background Processes";
}

	/**
	 * Set up active loader classes.
	 *
	 * This is where you can add anything that needs "registered" to WordPress,
	 * such as shortcodes, rest endpoints, blocks, and cron jobs.
	 *
	 * All supported loaders come pre-packaged with this plugin, they just need un-commented here
	 * to begin using.
	 *
	 * @since 1.0.0
	 */
	protected function _setup() {
      plugin_name_replace_me()->logger()->add('background_process', '\Plugin_Name_Replace_Me\Event_Types\Background_Process');
	}


namespace Plugin_Name_Replace_Me\Event_Types;
/**
 * Class Background_Process
 * Error event type.
 *
 * @since 1.0.0
 *
 * @since
 * @package
 */
class Background_Process extends Event_Type {

	/**
	 * Event type
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	public $type = 'background_process';

	/**
	 * Writes this to the log.
	 * Set this to true to cause this event to get written to the log.
	 *
	 * @since 1.0.0
	 *
	 * @var bool
	 */
	protected $write_to_log = true;

	/**
	 * @var inheritDoc
	 */
	public $description = 'Logs when background processes run.';

	/**
	 * @var inheritDoc
	 */
	public $name = "Background Processes";


	/**
	 * The class to instantiate when writing to the error log.
	 *
	 * @since 1.0.0
	 *
	 * @var string Namespaced instance of writer class.
	 */
	public $writer_class = 'Plugin_Name_Replace_Me\Factories\Email_Logger';
}

underpin()->scripts()->add( 'test', [
	'handle'      => 'test',
	'src'         => 'path/to/script/src',
	'name'        => 'test',
	'description' => 'The description',
] );

underpin()->logger()->add('key','Namespace\To\Class');