Exemplo n.º 1
0
 /**
  * @covers \Phramework\SystemLog\Log\DatabaseLog::log
  */
 public function testLog()
 {
     //Force URI route
     $_SERVER['REQUEST_URI'] = '/dummy/1';
     $_SERVER['REQUEST_METHOD'] = Phramework::METHOD_GET;
     $this->systemLog->register();
     $this->phramework->invoke();
 }
Exemplo n.º 2
0
 /**
  * @covers Phramework\SystemLog\SystemLog::prepareObject
  */
 public function testPrepareObject()
 {
     $this->setUp();
     $method = Phramework::METHOD_GET;
     //Force URI route
     $_SERVER['REQUEST_URI'] = '/dummy/1';
     $_SERVER['REQUEST_METHOD'] = $method;
     $additionalParameters = (object) ['API' => 'phpunit'];
     $this->systemLog->register($additionalParameters);
     //$that = $this
     $object = Bootstrap::invokeMethod($this->systemLog, 'prepareObject', [SystemLog::LOG_USER_ID | SystemLog::LOG_REQUEST_HEADERS | SystemLog::LOG_REQUEST_HEADER_ACCEPT | SystemLog::LOG_REQUEST_PARAMS | SystemLog::LOG_RESPONSE_BODY, (object) ['body_raw_limit' => 10], (object) [], $method, [], $additionalParameters]);
     $this->assertInternalType('object', $object);
     $this->assertObjectHasAttribute('request_id', $object);
     $this->assertObjectHasAttribute('URI', $object);
     $this->assertObjectHasAttribute('method', $object);
     $this->assertSame($method, $object->method);
 }
Exemplo n.º 3
0
<?php

use Phramework\SystemLog\SystemLog;
include __DIR__ . '/../../vendor/autoload.php';
$settings = \Phramework\SystemLog\APP\Bootstrap::getSettings();
$phramework = \Phramework\SystemLog\APP\Bootstrap::prepare(true);
//$settings['system-log']->log = 'Phramework\\SystemLog\\Log\\TerminalLog';
//$settings['system-log']->log = 'Phramework\\SystemLog\\Log\\DatabaseLog';
$systemLog = new SystemLog($settings['system-log']);
$systemLog->register((object) ['runtime' => 'php server']);
$phramework->invoke();
Exemplo n.º 4
0
 /**
  * Register system log instance to phramework
  * @param null|object $additionalParameters
  * @throws Exception
  * @return boolean
  */
 public function register($additionalParameters = null)
 {
     if ($additionalParameters && !is_object($additionalParameters)) {
         throw new \Exception('additionalParameters must be an object');
     }
     $settings = $this->settings;
     //Ignore registration if disabled setting is set to true
     if (isset($this->settings->disabled) && $this->settings->disabled) {
         return false;
     }
     $logMatrix = isset($settings->matrix) ? (array) $settings->matrix : [];
     $logMatrixException = isset($settings->{'matrix-exception'}) ? (array) $settings->{'matrix-exception'} : [];
     $logObject = $this->logObject;
     /*
      * Register step callbacks
      */
     //Register after call URIStrategy (after controller/method is invoked) callback
     Phramework::$stepCallback->add(StepCallback::STEP_AFTER_CALL_URISTRATEGY, function ($step, $params, $HTTPMethod, $headers, $callbackVariables, $invokedController, $invokedMethod) use($logObject, $logMatrix, $additionalParameters, $settings) {
         $matrixKey = trim($invokedController, '\\') . '::' . $invokedMethod;
         $flags = isset($logMatrix[$matrixKey]) ? $logMatrix[$matrixKey] : self::LOG_STANDARD;
         //If ignore flag is active, dont store anything
         if ($flags === self::LOG_IGNORE) {
             return false;
         }
         //For common properties
         $object = SystemLog::prepareObject($flags, $settings, $params, $HTTPMethod, $headers, $additionalParameters);
         //Write specific
         return $logObject->log($step, $object);
     });
     //Register on error callback
     Phramework::$stepCallback->add(StepCallback::STEP_ERROR, function ($step, $params, $HTTPMethod, $headers, $callbackVariables, $errors, $code, $exception) use($logObject, $logMatrixException, $additionalParameters, $settings) {
         $matrixKey = trim(get_class($exception), '\\');
         $flags = isset($logMatrixException[$matrixKey]) ? $logMatrixException[$matrixKey] : self::LOG_STANDARD;
         //If ignore flag is active, dont store anything
         if ($flags === self::LOG_IGNORE) {
             return false;
         }
         //For common properties
         $object = SystemLog::prepareObject($flags, $settings, $params, $HTTPMethod, $headers, $additionalParameters);
         //Write specific
         $object->errors = $errors;
         $object->exception = serialize(self::flattenExceptionBacktrace($exception));
         $object->exception_class = $matrixKey;
         $debugBacktrace = (array) (object) $exception;
         if (isset($debugBacktrace["Exceptiontrace"])) {
             //Get call trace from exception
             $debugBacktrace = $debugBacktrace["Exceptiontrace"];
             foreach ($debugBacktrace as $k => &$v) {
                 if (isset($v['class'])) {
                     $v = $v['class'] . '::' . $v['function'];
                 } else {
                     $v = $v['function'];
                 }
             }
             $object->call_trace = $debugBacktrace;
         }
         return $logObject->log($step, $object);
     });
     return true;
 }