Beispiel #1
0
 /**
  * log any data to target specified by XAPP_PROFILER_MODE. all not string values
  * will be compiled to string separated values as defined by XAPP_PROFILER_STRING_SEPARATOR and
  * according to the profiler mode send/executed by the target value. see XAPP_PROFILER_MODE
  * option for more info.
  *
  * @error 15205
  * @return void
  */
 public function log()
 {
     $log = array();
     $mode = xapp_get_option(self::MODE, $this);
     $separator = xapp_get_option(self::STRING_SEPARATOR, $this);
     if (func_num_args() > 0) {
         foreach (func_get_args() as $a) {
             if (is_array($a)) {
                 $log[] = implode($separator, $a);
             } else {
                 $log[] = $a;
             }
         }
         $log = implode($separator, $log);
         switch ($mode) {
             case $mode === 1 || $mode === true:
                 //do nothing since data will be flushed on shutdown
                 break;
             case $mode === 2 || $mode === 'console':
                 xapp_console($log, 'profiler');
                 break;
             case $mode instanceof Xapp_Console:
                 $mode->log($log, 'profiler');
                 break;
             case $mode instanceof Xapp_Log:
                 $mode->log($log);
                 break;
             case is_file($mode):
                 file_put_contents($mode, "{$log}\n", FILE_APPEND);
                 break;
             case is_dir($mode):
                 file_put_contents(rtrim($mode, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'profiler.log', "{$log}\n", FILE_APPEND);
                 break;
             default:
         }
     }
     $log = null;
 }
Beispiel #2
0
 /**
  * class destructor iterates through error stack an sorts all errors according to intended action
  * or target. since error have different severity level some errors need to be routed to specific
  * log writers only. therefore: the default implementation will route all errors to the designated
  * log writer. if the default log writers are overwritten than all errors are written to all registered
  * log writers at the same time - regardless of error log severity and mapped error action, e.g. only
  * mailing alert errors via email.
  *
  * @error 11605
  * @return void
  */
 public function __destruct()
 {
     $all = array();
     $mail = array();
     $file = array();
     $map = xapp_get_option(self::ACTION_MAP, $this);
     foreach ($this->stack as $k => $v) {
         if (!array_key_exists((int) $v->severity, $map)) {
             $v->severity = self::LOG;
         }
         if (array_key_exists((int) $v->severity, $map)) {
             $v->action = $map[(int) $v->severity];
         }
         if (isset($v->action) && !is_null($v->action)) {
             if (in_array($v->action, array(self::DUMP))) {
                 xapp_console($v->object, null, 'error');
             }
             if (in_array($v->action, array(self::LOG, self::LOG | self::MAIL))) {
                 $file[] = $v->message;
             }
             if (in_array($v->action, array(self::MAIL, self::LOG | self::MAIL))) {
                 $mail[] = $v->object;
             }
             $all[] = $v->object;
         }
     }
     if (xapp_is_option(self::WRITER, $this)) {
         $this->write($all);
     } else {
         if (sizeof($file) > 0) {
             $this->write($file, 'file');
         }
         if (sizeof($mail) > 0) {
             if (xapp_is_option(self::EMAIL, $this)) {
                 $this->write($mail, 'mail');
             }
         }
     }
 }
Beispiel #3
0
function xapp_clog($message = '')
{
    $type = XApp_Service_Entry_Utils::getConsoleType();
    if ($type === 'firephp') {
        xapp_console($message);
    } elseif ($type === 'chromephp') {
        Xapp_Console::instance('chromephp')->info($message);
    }
    return;
}
Beispiel #4
0
 /**
  * xapp error shortcut function used system wide to redirect errors back to xapp base class if xapp base class is used.
  * this function can be easily overwritten to handle errors thrown by exceptions and internal php errors channeled
  * through xapps internal error handler defined in XAPP_CONF_HANDLE_ERROR. use the the this function in all derived
  * exception classes inheriting from phps native ErrorException class in constructor - see Xapp_Error for example. when
  * implementing your own error handler you can bounce back your errors to this function or overwrite it. if xapp base
  * class is not used with direct error to default error handling defined either via phps set_error_handler function
  * or error_log function and triggered by phps trigger_error function. this functions expects exception as well as
  * errors passed as it there where an exception but only for logging purpose or even act as set_error_handler if needed.
  * when redirecting all errors to console you must load and enable Xapp_Console by defining an external console driver
  * like "firephp" and define XAPP_CONF_HANDLE_ERROR with value "console".
  *
  * overwrite like:
  * <code>
  *      function xapp_error($e, $c = 0, $s = 0, $f = null, $l = null)
  *      {
  *          //your custom code here
  *      }
  * </code>
  *
  * @param   string|Exception|Xapp_Error|array $e expects either string error message, instance of Exception or array
  *          return from phps native function error_get_last
  * @param   int $c expects optional error code
  * @param   int $s expects optional severity
  * @param   null|string $f expects the file where error occurred
  * @param   null|int $l expects the line where error occurred
  * @return  boolean|Xapp_Error returns Xapp_Error instance or false as deault
  */
 function xapp_error($e, $c = 0, $s = XAPP_ERROR_ERROR, $f = null, $l = null)
 {
     if (xapped()) {
         xapp_event('xapp.error', array($e));
         //redirect all errors to console
         if (xapped('Xapp_Console') && (bool) xapp_conf(XAPP_CONF_CONSOLE) && strtolower((string) xapp_conf(XAPP_CONF_HANDLE_ERROR) === 'console')) {
             if ($e instanceof Exception) {
                 xapp_console($e, $e->getMessage(), 'error');
             } else {
                 if (is_array($e) && isset($e['message'])) {
                     xapp_console($e, $e['message'], 'error');
                 } else {
                     $std = new stdClass();
                     $std->message = (string) $e;
                     $std->code = (int) $c;
                     $std->severity = (int) $s;
                     $std->file = (string) $f;
                     $std->line = (int) $l;
                     xapp_console($std, $std->message, 'error');
                 }
             }
             //redirect all error to xapp error handling
         } else {
             if ($e instanceof Xapp_Error) {
                 //do nothing because all has been done already since instance of Xapp_Error can only exists after constructor has
                 //been called and with calling parent constructor and stacking the error all has been done!
             } else {
                 if ($e instanceof Exception) {
                     return Xapp::e($e, (int) $c, (int) $s, $f, $l);
                 } else {
                     if (is_array($e) && isset($e['message'])) {
                         return Xapp::e($e['message'], (int) $e['type'], XAPP_ERROR_ERROR, $e['file'], $e['line']);
                     } else {
                         return Xapp::e((string) $e, (int) $c, (int) $s, $f, $l);
                     }
                 }
             }
         }
     } else {
         xapp_profile('error', $e);
         trigger_error((string) $e, E_USER_ERROR);
     }
     return false;
 }