/**
  * Writes the log to the database by utilizing the Log model
  *
  * @param $record array
  * @return void
  */
 public function write(array $record)
 {
     # Log to database
     /** @var \ClassyLlama\AvaTax\Model\Log $log */
     $log = $this->logFactory->create();
     $log->setData('level', isset($record['level_name']) ? $record['level_name'] : null);
     $log->setData('message', isset($record['message']) ? $record['message'] : null);
     if (isset($record['extra']['store_id'])) {
         $log->setData('store_id', $record['extra']['store_id']);
         unset($record['extra']['store_id']);
     }
     if (isset($record['extra']['class']) && isset($record['extra']['line'])) {
         $log->setData('source', $record['extra']['class'] . " [line:" . $record['extra']['line'] . "]");
     }
     if ($this->avaTaxConfig->getLogDbDetail() == LogDetail::MINIMAL && $record['level'] >= Logger::WARNING) {
         $log->setData('request', $this->getRequest($record));
         $log->setData('result', $this->getResult($record));
     } elseif ($this->avaTaxConfig->getLogDbDetail() == LogDetail::NORMAL) {
         $log->setData('request', $this->getRequest($record));
         $log->setData('result', $this->getResult($record));
         $log->setData('additional', $this->getContextVarExport($record));
     } elseif ($this->avaTaxConfig->getLogDbDetail() == LogDetail::EXTRA) {
         $log->setData('request', $this->getRequest($record));
         $log->setData('result', $this->getResult($record));
         $log->setData('additional', $this->getExtraVarExport($record) . (strlen($this->getExtraVarExport($record)) > 0 ? "\n" : '') . $this->getContextVarExport($record));
     }
     $log->save();
 }