setLoggerName($loggerName); return $instance; } /** * Sets Logger Name. Generally defaulted to Logging Class * * @param string $loggerName */ public function setLoggerName($loggerName = __CLASS__) { $this->loggerName = $loggerName; } /** * Default Constructor */ public function __construct() { $config = PayPalConfigManager::getInstance()->getConfigHashmap(); $this->isLoggingEnabled = (array_key_exists('log.LogEnabled', $config) && $config['log.LogEnabled'] == '1'); if ($this->isLoggingEnabled) { $loggingLevel = strtoupper($config['log.LogLevel']); $this->setupLogger($config); $this->loggingLevel = (isset($loggingLevel) && defined(__NAMESPACE__ . "\\PayPalLoggingLevel::$loggingLevel")) ? constant(__NAMESPACE__ . "\\PayPalLoggingLevel::$loggingLevel") : PayPalLoggingManager::DEFAULT_LOGGING_LEVEL; } } private function setupLogger($config = array()) { // Checks if custom adapter defined, and is it an implementation of @LoggerInterface $loggingAdapter = array_key_exists('log.Adapter', $config) && in_array(LoggerInterface::class, class_implements($config['log.Adapter']))? $config['log.Adapter'] : PayPalLogger::class; $this->logger = new $loggingAdapter(); } /** * Log Error * * @param string $message */ public function error($message) { if ($this->isLoggingEnabled && $this->loggingLevel >= PayPalLoggingLevel::ERROR) { $this->logger->error($message); } } /** * Log Warning * * @param string $message */ public function warning($message) { if ($this->isLoggingEnabled && $this->loggingLevel >= PayPalLoggingLevel::WARN) { $this->logger->warning($message); } } /** * Log Info * * @param string $message */ public function info($message) { if ($this->isLoggingEnabled && $this->loggingLevel >= PayPalLoggingLevel::INFO) { $this->logger->info($message); } } /** * Log Fine * * @param string $message */ public function fine($message) { $this->info($message); } /** * Log Fine * * @param string $message */ public function debug($message) { if ($this->isLoggingEnabled) { $config = PayPalConfigManager::getInstance()->getConfigHashmap(); // Check if logging in live if (array_key_exists('mode', $config) && $config['mode'] == 'live' && $this->loggingLevel >= PayPalLoggingLevel::DEBUG) { $this->logger->error("Not allowed to keep 'Debug' level for Live Environments. Reduced to 'INFO'"); } elseif (PayPalLoggingLevel::DEBUG <= $this->loggingLevel) { $this->logger->debug($message); } } } }