timezone = $timezone; $this->_fileDriver = $fileDriver; $this->newDirectory = $file->getDirectoryWrite(DirectoryList::VAR_DIR); parent::__construct($context); } public function writeLog($message, $type = 'info', $name = 'netsuite') { if (!$this->logger) { $this->initLog($name); } switch ($type) { case 'info': $this->logger->info($message); break; case 'warn': $this->logger->warn($message); break; case 'error': $this->logger->err($message); break; default: $this->logger->info($message); break; } } public function initLog($name = 'netsuite') { $today = $this->timezone->date()->format('d-m-Y'); $logPath = BP . '/var'. NetSuiteConstants::NETSUITE_LOG_DIR . $today; if (!$this->isFileExist($logPath)) { $this->createDirectory($logPath); } $writer = new \Laminas\Log\Writer\Stream($logPath . '/' . $name . '.log'); $this->logger = new \Laminas\Log\Logger(); $this->logger->addWriter($writer); return $this->logger; } public function isFileExist($fileName) { return $this->_fileDriver->isExists($fileName); } /** * Create new folder * * @return bool * @throws LocalizedException */ public function createDirectory($directoryName) { $newDirectory = false; try { $newDirectory = $this->newDirectory->create($directoryName); } catch (FileSystemException $e) { return false; } return $newDirectory; } }