/** * Create a new log event (Saves a line or two) * @param int $level * @param string|\Exception $msg * @param array $context * @param string $appName * @param mixed $exceptionToArrayHandler * @return LogEvent */ public static function create($level, $msg, array $context, $appName, $exceptionToArrayHandler = null) { $logEvent = new LogEvent($context); $logEvent->setLevel($level); if ($msg instanceof \Exception) { $exceptionHandler = $exceptionToArrayHandler; if (empty($exceptionHandler) || !is_callable($exceptionHandler)) { $exceptionHandler = static::DEFAULT_EXCEPTION_HANDLER; } $logEvent->setException(call_user_func($exceptionHandler, $msg)); $msg = $msg->getMessage(); } $logEvent->setMsg($msg); $logEvent->setName($appName); $logEvent->setTime(static::getTimestamp($context)); return $logEvent; }
/** * Test if exception handler is actually executed * Setting the exception handler from outside is tested in LoggerTest::testExternalExceptionHandler() * @see LoggerTest::testExternalExceptionHandler() */ public function testExternalExceptionHandler() { $exHandler = function (\Exception $ex) { $e = array(); $e['message'] = $ex->getMessage(); $e['exceptionHandler'] = __METHOD__; return $e; }; $logEvent = LogEvent::create(ILogger::LEVEL_FATAL, new \Exception('Hallo'), array(), 'PHPUnit', $exHandler); $this->arrayHasKey('message', $logEvent['exception']); $this->arrayHasKey('exceptionHandler', $logEvent['exception']); $this->assertEquals($logEvent['exception']['message'], 'Hallo'); $this->assertStringEndsWith('{closure}', $logEvent['exception']['exceptionHandler']); }
/** * Loads a log chunk from the database. * */ function fetchLogChunk($jobId, $fileId, $startOffset, $endOffset) { log::doLog($endOffset); // include_once INIT::$MODEL_ROOT . "/LogEvent.class.php"; $db = Database::obtain(); $queryId = $db->query("SELECT * FROM log_event_header h WHERE h.job_id = '{$jobId}' AND h.file_id = '{$fileId}'" . " AND h.type != 'gaze'" . " ORDER BY h.time, h.id ASC LIMIT {$startOffset}, {$endOffset}"); $err = $db->get_error(); $errno = $err["error_code"]; if ($errno != 0) { log::doLog("CASMACAT: fetchLogChunk(): " . print_r($err, true)); throw new Exception("CASMACAT: fetchLogChunk(): " . print_r($err, true)); // return $errno * -1; } // log::doLog("CASMACAT: fetchLogChunk(): Event headers found: '$db->affected_rows'"); $logListChunk = array(); $headerRow = null; while (($headerRow = $db->fetch($queryId)) != false) { $headerRowAsObject = snakeToCamel($headerRow); // log::doLog("CASMACAT: fetchLogChunk(): Next headerRow: " . print_r($headerRowAsObject, true)); $logEvent = new LogEvent($jobId, $fileId, $headerRowAsObject); // log::doLog("CASMACAT: fetchLogChunk(): Processing header id: '$logEvent->id'"); switch ($logEvent->type) { case LogEvent::START_SESSION: break; case LogEvent::STOP_SESSION: break; case LogEvent::RESIZE: $eventRow = fetchEventRow($logEvent->id, "resize_event"); $logEvent->resizeData($eventRow); break; case LogEvent::TEXT: $eventRow = fetchEventRow($logEvent->id, "text_event"); $logEvent->textData($eventRow); break; case LogEvent::SELECTION: $eventRow = fetchEventRow($logEvent->id, "selection_event"); $logEvent->selectionData($eventRow); break; case LogEvent::SCROLL: $eventRow = fetchEventRow($logEvent->id, "scroll_event"); $logEvent->scrollData($eventRow); break; // case LogEvent::GAZE: // $eventRow = fetchEventRow($logEvent->id, "gaze_event"); // $logEvent->gazeData($eventRow); // break; // case LogEvent::GAZE: // $eventRow = fetchEventRow($logEvent->id, "gaze_event"); // $logEvent->gazeData($eventRow); // break; case LogEvent::FIXATION: $eventRow = fetchEventRow($logEvent->id, "fixation_event"); $logEvent->fixationData($eventRow); break; case LogEvent::DRAFTED: case LogEvent::TRANSLATED: case LogEvent::APPROVED: case LogEvent::REJECTED: break; case LogEvent::VIEWPORT_TO_SEGMENT: break; case LogEvent::SOURCE_COPIED: break; case LogEvent::SEGMENT_OPENED: break; case LogEvent::SEGMENT_CLOSED: break; case LogEvent::LOADING_SUGGESTIONS: break; case LogEvent::SUGGESTIONS_LOADED: $eventRow = fetchEventRow($logEvent->id, "suggestions_loaded_event"); $logEvent->suggestionsLoadedData($eventRow); break; case LogEvent::SUGGESTION_CHOSEN: $eventRow = fetchEventRow($logEvent->id, "suggestion_chosen_event"); $logEvent->suggestionChosenData($eventRow); break; case LogEvent::DELETING_SUGGESTION: $eventRow = fetchEventRow($logEvent->id, "deleting_suggestion_event"); $logEvent->deletingSuggestionData($eventRow); break; case LogEvent::SUGGESTION_DELETED: break; case LogEvent::STATS_UPDATED: $eventRow = fetchEventRow($logEvent->id, "stats_event"); $logEvent->statsUpdatedData($eventRow); break; case LogEvent::DECODE: case LogEvent::ALIGNMENTS: case LogEvent::SUFFIX_CHANGE: case LogEvent::CONFIDENCES: case LogEvent::TOKENS: case LogEvent::SHOW_ALIGNMENT_BY_KEY: case LogEvent::HIDE_ALIGNMENT_BY_KEY: $eventRow = fetchEventRow($logEvent->id, "itp_event"); $logEvent->itpData($eventRow); break; case LogEvent::SHOW_ALIGNMENT_BY_MOUSE: case LogEvent::HIDE_ALIGNMENT_BY_MOUSE: break; case LogEvent::KEY_DOWN: case LogEvent::KEY_UP: $eventRow = fetchEventRow($logEvent->id, "key_event"); $logEvent->keyData($eventRow); break; case LogEvent::MOUSE_DOWN: case LogEvent::MOUSE_UP: case LogEvent::MOUSE_CLICK: case LogEvent::MOUSE_MOVE: $eventRow = fetchEventRow($logEvent->id, "mouse_event"); $logEvent->mouseData($eventRow); break; case LogEvent::BEFORE_CUT: case LogEvent::BEFORE_COPY: case LogEvent::BEFORE_PASTE: break; case LogEvent::VIS_MENU_DISPLAYED: case LogEvent::VIS_MENU_HIDDEN: break; case LogEvent::INITIAL_CONFIG: case LogEvent::CONFIG_CHANGED: $eventRow = fetchEventRow($logEvent->id, "config_event"); $logEvent->configData($eventRow); break; case LogEvent::MOUSE_WHEEL_DOWN: case LogEvent::MOUSE_WHEEL_UP: case LogEvent::MOUSE_WHEEL_INVALIDATE: break; case LogEvent::MEMENTO_UNDO: case LogEvent::MEMENTO_REDO: case LogEvent::MEMENTO_INVALIDATE: break; case LogEvent::SR_MENU_DISPLAYED: case LogEvent::SR_MENU_HIDDEN: case LogEvent::SR_MATCH_CASE_ON: case LogEvent::SR_MATCH_CASE_OFF: case LogEvent::SR_REG_EXP_ON: case LogEvent::SR_REG_EXP_OFF: case LogEvent::SR_RULES_SETTING: break; case LogEvent::SR_RULES_SET: $eventRow = fetchEventRow($logEvent->id, "sr_event"); $logEvent->srRulesSetData($eventRow); break; case LogEvent::SR_RULES_APPLIED: case LogEvent::SR_RULE_DELETED: break; // merc - adding floatPrediction, biconcordancer and translationOption // merc - adding floatPrediction, biconcordancer and translationOption case LogEvent::FLOAT_PREDICTION: break; case LogEvent::BICONCOR: $eventRow = fetchEventRow($logEvent->id, "biconcor_event"); $logEvent->biconcorData($eventRow); break; case LogEvent::BICONCOR_CLOSED: break; case LogEvent::TRANSLATION_OPTION: break; // merc - adding epen // merc - adding epen case LogEvent::EPEN_OPENED: break; case LogEvent::EPEN_CLOSED: break; case LogEvent::HTR_RESULT: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_UPDATE: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_NBEST_CLICK: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_TEXT_CHANGE: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_START: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_ADD_STROKE: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_END: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; case LogEvent::HTR_GESTURE: $eventRow = fetchEventRow($logEvent->id, "epen_event"); $logEvent->epenData($eventRow); break; // merc - blur/focus // merc - blur/focus case LogEvent::BLUR: break; case LogEvent::FOCUS: break; default: log::doLog("CASMACAT: fetchLogChunk(): Unknown log event type: '{$logEvent->type}', header id: '{$logEvent->id}'"); throw new Exception("CASMACAT: fetchLogChunk(): Unknown log event type: '{$logEvent->type}', header id: '{$logEvent->id}'"); // return -1; } $logListChunk[] = $logEvent; // log::doLog("CASMACAT: fetchLogChunk(): Loaded: '" . $logEvent->toString() . "'"); } if (empty($logListChunk)) { return false; } else { return $logListChunk; } }
/** * get list of all available log actions */ function get_log_actions() { $log_count = LogEvent::countByActions(); $actions = LogAction::findBySQL('1 ORDER BY name'); $log_actions = array(); foreach ($actions as $action) { $log_actions[$action->getId()] = $action->toArray(); $log_actions[$action->getId()]['log_count'] = (int) $log_count[$action->getId()]; } return $log_actions; }
/** * Finds all users by given search string. Searches for the users id, * part of the name or the username. * * @param type $needle The needle to search for. * @return array */ public static function searchUser($needle) { $result = array(); $users = User::findBySQL("Nachname LIKE CONCAT('%', :needle, '%')\n OR Vorname LIKE CONCAT('%', :needle, '%')\n OR CONCAT(Nachname, ', ', Vorname) LIKE CONCAT('%', :needle, '%')\n OR CONCAT(Vorname, ' ', Nachname) LIKE CONCAT('%', :needle, '%')\n OR username LIKE CONCAT('%', :needle, '%')", array(':needle' => $needle)); foreach ($users as $user) { $name = sprintf('%s (%s)', my_substr($user->getFullname(), 0, 20), $user->username); $result[] = array($user->getId(), $name); } // search for deleted users // // The name of the user is part of info field, // old id (still in DB) is in affected column. // // The log action "USER_DEL" was removed from the list of initially // registered log actions in the past. // Search for the user if it is still in database. If not, the search // for deleted users is not possible. $log_action_deleted_user = SimpleORMapCollection::createFromArray(LogAction::findByName('USER_DEL'))->first(); if ($log_action_deleted_user) { $log_events_deleted_user = LogEvent::findBySQL("action_id = ? AND info LIKE CONCAT('%', ?, '%')", array($log_action_deleted_user->getId(), $needle)); foreach ($log_events_deleted_user as $log_event) { $name = sprintf('%s (%s)', $log_event->info, _('gelöscht')); $result[] = array($log_event->affected_range_id, $name); } } return $result; }
public function get_log_event(Request $request, LogEvent $log_event) { if (!$this->bool_has_role) { return $this->roleHelper->call_redirect(); } else { $validation_rules = ['log_event_id' => 'required|integer|min:1']; $this->validate($request, $validation_rules); Storage::put('get_log_event.txt', $request->log_event_id); $obj_log_event = $log_event->where('id', $request->log_event_id)->first(); return response()->json($obj_log_event); } }
//config_event $to_print = $to_print . "Configuration:\n"; $q = "SELECT h.id as id, h.job_id as job_id, h.file_id as file_id, h.element_id as element_id, h.x_path as x_path, h.time as time, h.type as type, " . "c.config" . " FROM log_event_header h, config_event c WHERE h.job_id = '{$jobId}' AND h.file_id = '{$fileId}' AND h.id = c.header_id ORDER BY h.time, h.id ASC"; $queryId = $db->query($q); $err = $db->get_error(); $errno = $err["error_code"]; if ($errno != 0) { log::doLog("CASMACAT: fetchLogChunk(): " . print_r($err, true)); throw new Exception("CASMACAT: fetchLogChunk(): " . print_r($err, true)); } $configRow = null; $configEvents = array(); while (($configRow = $db->fetch($queryId)) != false) { $configRowAsObject = snakeToCamel($configRow); //log::doLog("CASMACAT: fetchLogChunk(): Next headerRow: " . print_r($configRowAsObject, true)); $configEvent = new LogEvent($jobId, $fileId, $configRowAsObject); $configEvent->configData($configRowAsObject); //log::doLog("CASMACAT: fetchLogChunk(): configEvent: " . print_r($configEvent,true)); $configs = explode(",", $configEvent->config); foreach ($configs as $c) { $to_print = $to_print . "{$c}\n"; } //$to_print = $to_print. $configEvent->config."\n"; array_push($configEvents, $configEvent); } if (!empty($configEvents)) { //log::doLog("CASMACAT: configEvents: " . print_r($configEvents, true)); $count_config = 0; $len_config = count($configEvents); //print "configEvents: " . print_r($configEvents->config, true); } else {
} //------------------------------------------------------------------------------------------- //biconcor_event $queryId = $db->query("SELECT h.id as id, h.job_id, h.file_id, h.element_id, h.x_path, h.time, h.type" . ", b.word, b.info" . " FROM log_event_header h, biconcor_event b WHERE h.job_id = '{$jobId}' AND h.file_id = '{$fileId}' AND h.id = b.header_id ORDER BY h.time, h.id ASC"); $err = $db->get_error(); $errno = $err["error_code"]; if ($errno != 0) { log::doLog("CASMACAT: fetchLogChunk(): " . print_r($err, true)); throw new Exception("CASMACAT: fetchLogChunk(): " . print_r($err, true)); } $biconcorRow = null; $biconcorEvents = array(); while (($biconcorRow = $db->fetch($queryId)) != false) { $biconcorRowAsObject = snakeToCamel($biconcorRow); //log::doLog("CASMACAT: fetchLogChunk(): Next headerRow: " . print_r($textRowAsObject, true)); $biconcorEvent = new LogEvent($jobId, $fileId, $biconcorRowAsObject); $biconcorEvent->biconcorData($biconcorRowAsObject); array_push($biconcorEvents, $biconcorEvent); } if (!empty($biconcorEvents)) { //log::doLog("CASMACAT: textEvents: " . print_r($textEvents, true)); $count_biconcors = 0; $len_biconcors = count($biconcorEvents); //print "len_texts: ".$len_texts."\n"; } else { $len_biconcors = 0; } //------------------------------------------------------------------------------------------- //log_event_header $queryId = $db->query("SELECT * FROM log_event_header h WHERE h.job_id = '{$jobId}' AND h.file_id = '{$fileId}'" . " ORDER BY h.time, h.id ASC"); $err = $db->get_error();