| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Logger; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
class Logger |
| 8 |
{ |
| 9 |
private static $instance = []; |
| 10 |
private $logger; |
| 11 |
|
| 12 |
private function __construct($channel) |
| 13 |
{ |
| 14 |
if ($channel == "woo" && class_exists('WC_Logger')) { |
| 15 |
$this->logger = new WooLogger(); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
public static function getInstance($channel = "woo") |
| 20 |
{ |
| 21 |
if (!isset(self::$instance[$channel])) { |
| 22 |
self::$instance[$channel] = new self($channel); |
| 23 |
} |
| 24 |
|
| 25 |
return self::$instance[$channel]; |
| 26 |
} |
| 27 |
|
| 28 |
public static function channel($channel) |
| 29 |
{ |
| 30 |
return self::getInstance($channel)->logger; |
| 31 |
} |
| 32 |
|
| 33 |
public static function log($level, $message, $context = []) |
| 34 |
{ |
| 35 |
self::getInstance()->logger->log($level, $message, $context); |
| 36 |
} |
| 37 |
|
| 38 |
public static function info($message, $context = []) |
| 39 |
{ |
| 40 |
self::getInstance()->logger->info($message, $context); |
| 41 |
} |
| 42 |
|
| 43 |
public static function debug($message, $context = []) |
| 44 |
{ |
| 45 |
self::getInstance()->logger->debug($message, $context); |
| 46 |
} |
| 47 |
|
| 48 |
public static function warning($message, $context = []) |
| 49 |
{ |
| 50 |
self::getInstance()->logger->warning($message, $context); |
| 51 |
} |
| 52 |
|
| 53 |
public static function error($message, $context = []) |
| 54 |
{ |
| 55 |
self::getInstance()->logger->error($message, $context); |
| 56 |
} |
| 57 |
|
| 58 |
public static function alert($message, $context = []) |
| 59 |
{ |
| 60 |
self::getInstance()->logger->alert($message, $context); |
| 61 |
} |
| 62 |
|
| 63 |
public static function getLogs() |
| 64 |
{ |
| 65 |
return self::getInstance()->logger->getLogs(); |
| 66 |
} |
| 67 |
} |
| 68 |
|