1 <?php
2
3 namespace PayPal\Core;
4
5 use PayPal\Log\PayPalLogFactory;
6 use Psr\Log\LoggerInterface;
7
8 9 10 11 12
13 class PayPalLoggingManager
14 {
15 16 17
18 private static $instances = array();
19
20 21 22 23 24
25 private $logger;
26
27 28 29 30 31
32 private $loggerName;
33
34 35 36 37 38 39
40 public static function getInstance($loggerName = __CLASS__)
41 {
42 if (array_key_exists($loggerName, PayPalLoggingManager::$instances)) {
43 return PayPalLoggingManager::$instances[$loggerName];
44 }
45 $instance = new self($loggerName);
46 PayPalLoggingManager::$instances[$loggerName] = $instance;
47 return $instance;
48 }
49
50 51 52 53 54
55 private function __construct($loggerName)
56 {
57 $config = PayPalConfigManager::getInstance()->getConfigHashmap();
58
59 $factory = array_key_exists('log.AdapterFactory', $config) && in_array('PayPal\Log\PayPalLogFactory', class_implements($config['log.AdapterFactory'])) ? $config['log.AdapterFactory'] : '\PayPal\Log\PayPalDefaultLogFactory';
60
61 $factoryInstance = new $factory();
62 $this->logger = $factoryInstance->getLogger($loggerName);
63 $this->loggerName = $loggerName;
64 }
65
66 67 68 69 70
71 public function error($message)
72 {
73 $this->logger->error($message);
74 }
75
76 77 78 79 80
81 public function warning($message)
82 {
83 $this->logger->warning($message);
84 }
85
86 87 88 89 90
91 public function info($message)
92 {
93 $this->logger->info($message);
94 }
95
96 97 98 99 100
101 public function fine($message)
102 {
103 $this->info($message);
104 }
105
106 107 108 109 110
111 public function debug($message)
112 {
113 $config = PayPalConfigManager::getInstance()->getConfigHashmap();
114
115 if (array_key_exists('mode', $config) && $config['mode'] != 'live') {
116 $this->logger->debug($message);
117 }
118 }
119 }
120