Commit 29c1e093 authored by Michael Iseard's avatar Michael Iseard
Browse files

Use LoggerService factory method

parent 5c81d6de
...@@ -70,7 +70,7 @@ class Admin { ...@@ -70,7 +70,7 @@ class Admin {
add_action( 'kudos_transactions_update', add_action( 'kudos_transactions_update',
function ( $column, $value ) { function ( $column, $value ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
$logger->debug( 'kudos_transactions_update', [ $column, $value ] ); $logger->debug( 'kudos_transactions_update', [ $column, $value ] );
}, },
10, 10,
...@@ -78,7 +78,7 @@ class Admin { ...@@ -78,7 +78,7 @@ class Admin {
add_action( 'kudos_donors_add', add_action( 'kudos_donors_add',
function ( $column, $value ) { function ( $column, $value ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
$logger->debug( 'kudos_donors_add', [ $column, $value ] ); $logger->debug( 'kudos_donors_add', [ $column, $value ] );
}, },
10, 10,
...@@ -500,7 +500,7 @@ class Admin { ...@@ -500,7 +500,7 @@ class Admin {
// Check if action is a kudos action then log if true // Check if action is a kudos action then log if true
if(substr($action, 0, 6) === "kudos_" ) { if(substr($action, 0, 6) === "kudos_" ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
$logger->warning( 'Nonce verification failed', [ 'nonce' => $nonce, 'action' => $action ] ); $logger->warning( 'Nonce verification failed', [ 'nonce' => $nonce, 'action' => $action ] );
} }
......
...@@ -100,7 +100,7 @@ $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $default_tab; ...@@ -100,7 +100,7 @@ $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $default_tab;
return; return;
} }
$kudos_logger = new LoggerService(); $kudos_logger = LoggerService::factory();
$logArray = $kudos_logger->get_as_array(); $logArray = $kudos_logger->get_as_array();
?> ?>
......
...@@ -68,7 +68,7 @@ abstract class AbstractEntity implements EntityInterface { ...@@ -68,7 +68,7 @@ abstract class AbstractEntity implements EntityInterface {
throw new EntityException( 'Property does not exist!', 0, $property, static::class ); throw new EntityException( 'Property does not exist!', 0, $property, static::class );
} }
} catch ( EntityException $e ) { } catch ( EntityException $e ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
$logger->warning( 'Error setting property.', [ "message" => $e->getMessage() ] ); $logger->warning( 'Error setting property.', [ "message" => $e->getMessage() ] );
} }
...@@ -102,7 +102,7 @@ abstract class AbstractEntity implements EntityInterface { ...@@ -102,7 +102,7 @@ abstract class AbstractEntity implements EntityInterface {
*/ */
public function create_secret( $timeout = '+10 minutes' ) { public function create_secret( $timeout = '+10 minutes' ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
$table = static::get_table_name( false ); $table = static::get_table_name( false );
try { try {
......
...@@ -69,7 +69,7 @@ class Front { ...@@ -69,7 +69,7 @@ class Front {
*/ */
public static function process_transaction( string $order_id ) { public static function process_transaction( string $order_id ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
$logger->debug( 'Processing transaction', [ $order_id ] ); $logger->debug( 'Processing transaction', [ $order_id ] );
// Bail if no order ID // Bail if no order ID
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Kudos\Front; namespace Kudos\Front;
use Kudos\Service\LoggerService;
use Kudos\Service\TwigService; use Kudos\Service\TwigService;
class KudosButton { class KudosButton {
...@@ -23,10 +22,6 @@ class KudosButton { ...@@ -23,10 +22,6 @@ class KudosButton {
* @var string * @var string
*/ */
private $id; private $id;
/**
* @var LoggerService
*/
private $logger;
/** /**
* @var string * @var string
*/ */
...@@ -58,7 +53,6 @@ class KudosButton { ...@@ -58,7 +53,6 @@ class KudosButton {
public function __construct( array $atts ) { public function __construct( array $atts ) {
$this->twig = TwigService::factory(); $this->twig = TwigService::factory();
$this->logger = new LoggerService();
$this->title = $atts['modal_title']; $this->title = $atts['modal_title'];
$this->text = $atts['welcome_text']; $this->text = $atts['welcome_text'];
$this->label = $atts['button_label']; $this->label = $atts['button_label'];
......
...@@ -4,15 +4,10 @@ namespace Kudos\Front; ...@@ -4,15 +4,10 @@ namespace Kudos\Front;
use Kudos\Helpers\Settings; use Kudos\Helpers\Settings;
use Kudos\Helpers\Utils; use Kudos\Helpers\Utils;
use Kudos\Service\LoggerService;
use Kudos\Service\TwigService; use Kudos\Service\TwigService;
class KudosModal { class KudosModal {
/**
* @var LoggerService
*/
private $logger;
/** /**
* @var TwigService * @var TwigService
*/ */
...@@ -25,7 +20,6 @@ class KudosModal { ...@@ -25,7 +20,6 @@ class KudosModal {
*/ */
public function __construct() { public function __construct() {
$this->logger = new LoggerService();
$this->twig = TwigService::factory(); $this->twig = TwigService::factory();
} }
......
...@@ -16,7 +16,7 @@ abstract class AbstractService { ...@@ -16,7 +16,7 @@ abstract class AbstractService {
*/ */
public function __construct() { public function __construct() {
$this->logger = new LoggerService(); $this->logger = LoggerService::factory();
} }
......
...@@ -32,9 +32,9 @@ class ActivatorService { ...@@ -32,9 +32,9 @@ class ActivatorService {
*/ */
public static function activate( $old_version = null ) { public static function activate( $old_version = null ) {
$logger = new LoggerService(); $logger = LoggerService::factory();
LoggerService::init(); $logger::init();
TwigService::initCache(); TwigService::initCache();
self::create_donors_table(); self::create_donors_table();
self::create_transactions_table(); self::create_transactions_table();
......
...@@ -26,8 +26,9 @@ class DeactivatorService { ...@@ -26,8 +26,9 @@ class DeactivatorService {
* @since 1.0.0 * @since 1.0.0
*/ */
public static function deactivate() { public static function deactivate() {
$logger = new LoggerService();
$logger->info( 'Kudos Donations plugin deactivated' ); LoggerService::factory()->info( 'Kudos Donations plugin deactivated' );
} }
} }
...@@ -39,11 +39,7 @@ class LoggerService extends Monolog { ...@@ -39,11 +39,7 @@ class LoggerService extends Monolog {
*/ */
public static function init() { public static function init() {
$logger = new LoggerService();
if ( wp_mkdir_p( self::LOG_DIR ) ) { if ( wp_mkdir_p( self::LOG_DIR ) ) {
$logger->info( 'Log directory created successfully' );
return; return;
} }
...@@ -51,6 +47,26 @@ class LoggerService extends Monolog { ...@@ -51,6 +47,26 @@ class LoggerService extends Monolog {
} }
/**
* The class factory. In most cases this
* should be used instead of instantiating the object
* directly.
*
* @return static
* @since 2.0.0
*/
public static function factory() {
static $instance = false;
if ( ! $instance ) {
$instance = new static;
}
return $instance;
}
/** /**
* Clears the log file * Clears the log file
* *
......
...@@ -121,7 +121,7 @@ class TwigService extends AbstractService { ...@@ -121,7 +121,7 @@ class TwigService extends AbstractService {
*/ */
public static function initCache() { public static function initCache() {
$logger = new LoggerService(); $logger = LoggerService::factory();
if ( wp_mkdir_p( self::CACHE_DIR ) ) { if ( wp_mkdir_p( self::CACHE_DIR ) ) {
$logger->info( 'Twig cache directory created successfully' ); $logger->info( 'Twig cache directory created successfully' );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment