示例#1
0
 /**
  * Static method for preparing a GELF message to be sent
  *
  * @param GelfMessage $message
  *
  * @return array
  */
 protected function prepareMessage(GelfMessage $message)
 {
     try {
         if (false === ($_gzJson = gzcompress($message->toJson()))) {
             return false;
         }
         //  If we are less than the max chunk size, we're done
         if (strlen($_gzJson) <= static::MAX_CHUNK_SIZE) {
             return [$_gzJson];
         }
     } catch (\Exception $_ex) {
         //  Eschew failure
         return false;
     }
     return $this->prepareChunks(str_split($_gzJson, static::MAX_CHUNK_SIZE));
 }
 /**
  * Logs API requests to logging system
  *
  * @param array      $data    The data to log
  * @param int|string $level   The level, defaults to INFO
  * @param Request    $request The request, if available
  * @param string     $type    Optional type -- DFE fills with the source "cluster-id"
  *
  * @return bool
  */
 protected function log($data = [], $level = AuditLevels::INFO, $request = null, $type = null)
 {
     try {
         $_request = $request ?: Request::createFromGlobals();
         $_data = array_merge($this->buildBasicEntry($_request), $data);
         $type && ($_data['type'] = $type);
         $_message = GelfMessage::make($_data, $level, $_request->getMethod() . ' ' . $_request->getRequestUri(), implode(' | ', [static::MESSAGE_TAG, implode(', ', $_data['source_ip']), date('Y-m-d H-i-s', $_data['request_timestamp'])]));
         $_result = $this->getLogger()->send($_message);
     } catch (\Exception $_ex) {
         //  Completely ignore any issues
         $_result = false;
     }
     if (env('DF_MANAGED_ENABLE_AUDIT_LOGGING', false)) {
         logger('audit ' . ($_result ? 'success' : 'failure') . ': ' . (isset($_message) ? $_message->toJson() : 'no message made'));
     }
 }