Beispiel #1
0
 /**
  * @return BaseLogger
  **/
 public final function logRecord(LogRecord $record)
 {
     $levelMatches = $this->level === null || $record->getLevel()->getId() <= $this->level->getId();
     if ($levelMatches && $this->isLoggable($record)) {
         $this->publish($record);
     }
     return $this;
 }
 /**
  * @return StreamLogger
  **/
 protected function publish(LogRecord $record)
 {
     if (!$this->stream) {
         return $this;
     }
     $this->stream->write($record->toString() . "\n");
     return $this;
 }
 /**
  * @param LogRecord $logRecord
  * @return string
  */
 public function format($logRecord)
 {
     $time = $logRecord->getTime();
     $result = $time->format('Y-m-d H:i:s') . ' [' . LogLevel::getName($logRecord->getLevel()) . '] ' . getmypid();
     $message = (string) $logRecord->getMessage();
     if ($message !== '') {
         $result .= ' | ' . str_replace("\n", "\n  ", $message);
     }
     return $result . PHP_EOL;
 }
Beispiel #4
0
 /**
  * @param  string
  * @param  int
  * @return void
  * @throws IOException
  */
 public function publish(LogRecord $rec)
 {
     if (!$this->fd) {
         if (($this->fd = fopen('php://' . $this->pipe, 'w')) === false) {
             throw new IOException('Failed to open output stream on php://' . $this->pipe . ' for writing');
         }
     }
     if (fwrite($this->fd, $rec->toString() . "\n") === false) {
         throw new IOException('Failed to log message');
     }
     # Maybe this is overkill...
     @fflush($this->fd);
 }
 function logWrite($event_type, $content, $from_ip = "127.0.0.1", $by_user = 3)
 {
     //define user_id
     $by_user = isset(App::$instance->user->id) ? App::$instance->user->id : 3;
     //define ip
     $from_ip = App::$instance->user->ip;
     $this->validator->validate(['event_type' => [$event_type, 'between(1,25)'], 'content' => [$content, 'max(8000)']]);
     //if no passes
     if (!$this->validator->passes()) {
         //trim string if it's lenght more than 8000
         $content = substr($content, 0, 7999);
     }
     $logRecord = new LogRecord();
     $logRecord->event_type = $event_type;
     $logRecord->from_ip = $from_ip;
     $logRecord->by_user = $by_user;
     $logRecord->content = $content;
     $logRecord->save();
 }
 public function index($eventType = false)
 {
     Auth::isAdminOrDie(App::$instance);
     if (!$eventType) {
         $logList = LogRecord::take($this->getQlimit(50))->skip($this->getQOffset())->orderBy($this->getQOrder(), $this->getQVector())->with("user")->get();
     } else {
         $logList = LogRecord::where('event_type', $eventType)->take($this->getQlimit(50))->skip($this->getQOffset())->orderBy($this->getQOrder(), $this->getQVector())->with("user")->get();
     }
     //define event type
     foreach ($logList as $log) {
         $log->humanized = new stdClass();
         $log->humanized->event_type = $this->defineLogType($log->event_type);
     }
     $eventType = $this->defineLogType($eventType);
     $recordsCount = LogRecord::all()->count();
     //pages
     $pages = RenderEngine::makePagination($recordsCount, $this->getQlimit(50), 'route');
     $this->render("logs/index", compact('logList', 'pages', 'eventType'));
 }
Beispiel #7
0
 /**
  * @param  LogRecord
  * @return bool  If false, the filter chain will break
  * @throws Exception
  */
 public function filter(LogRecord $rec)
 {
     // dont't filter?
     if ($rec->getLevel() < $this->parameters['level'] || cdCtx('cli_debug')) {
         return true;
     }
     // Message
     $msg = '';
     if ($rec->getMessage()) {
         $msg .= $rec->getMessage() . "\n";
     }
     if ($rec->getThrown()) {
         $msg .= ABException::format($rec->getThrown(), true, false);
     }
     $msg = trim($msg);
     // forward
     $this->insertRecord($rec, $msg);
     return true;
 }
Beispiel #8
0
 /**
  * @param  string
  * @param  int
  * @return bool  If the message should be passed on to the next filter or to the log handler.
  * @throws Exception
  */
 public function filter(LogRecord $rec)
 {
     // dont't filter?
     if ($rec->getLevel() < $this->conf['level'] || cdCtx('cli_debug')) {
         return true;
     }
     // get group
     $group = '?';
     if (($id = @posix_getegid()) !== false) {
         if (($id = @posix_getgrgid($id)) !== false) {
             $group = $id['name'];
         }
     }
     // Date & Level
     $msg = 'Time:       ' . $rec->getTimeFormat() . "\n" . 'Group:User: '******':' . cdUser() . "\n" . 'CWD:        ' . getcwd() . "\n" . 'Level:      ' . $rec->getLevelName() . "\n";
     // Prefix
     $prefix = $rec->getPrefix();
     if ($prefix) {
         $msg .= "Log Prefix: {$prefix}\n";
     } else {
         $prefix = 'main';
     }
     $msg .= "\n";
     // Message
     if ($rec->getThrown()) {
         $msg .= ABException::format($rec->getThrown(), true, false);
     }
     if ($rec->getMessage()) {
         $msg .= $rec->getMessage();
     }
     // Email headers
     $headers = 'From: ' . $this->conf['from'] . "\r\nX-Mailer: contentd/" . cdVersion();
     // Subject
     // %e = exception name, %l = log level, %j = job name
     $logLevelName = ucfirst(trim(strtolower($rec->getLevelName())));
     $subject = strtr($this->conf['subject'], array('%e' => $rec->getThrown() ? get_class($rec->getThrown()) : $logLevelName, '%l' => $logLevelName, '%j' => $prefix));
     // Action
     if (!mail($this->conf['to'], $subject, $msg, $headers)) {
         $rec->setMessage($rec->getMessage() . '. Additionaly, the Mail log filter failed to mail "' . $this->conf['to'] . '"');
     }
     return true;
 }
Beispiel #9
0
 /**
  * Passes the \TYPO3\CMS\Core\Log\LogRecord to all registered writers.
  *
  * @param \TYPO3\CMS\Core\Log\LogRecord $record
  * @return void
  */
 protected function writeLog(LogRecord $record)
 {
     if (!empty($this->writers[$record->getLevel()])) {
         foreach ($this->writers[$record->getLevel()] as $writer) {
             $writer->writeLog($record);
         }
     }
 }
Beispiel #10
0
$status = "success";
$errors = array();
$logRecordId = $_GET[logRecordId];
//error_log("\$logRecordId is $logRecordId ");
// If user is not logged in then create an error.
// Do not bother validating the other fields if not logged in.
if ($user->getIsLoggedIn()) {
    if (!$logRecordId) {
        $status = "fail";
        $errors[logRecordId] = "No logRecordId specefied.";
    }
} else {
    $status = "fail";
    $errors[user] = "You are not logged in.";
}
$logRec = new LogRecord();
if ($status == "success") {
    // Everything is OK. Do the DELETE:
    $logRec->setId($logRecordId);
    if (!$logRec->deleteRecord()) {
        $status = "fail";
        $errors[deleteRecordFailed] = "Failed to delete record.";
    }
}
header("content-type: text/xml");
?>


<DeleteLogRecord>
	<logId><?php 
echo $logRec->getId();
Beispiel #11
0
 /**
  * Called upon to store (INSERT) a log record into the database.
  *
  * Normally called upon by the <samp>filter</samp> method after
  * figuring out a record should be logged.
  *
  * @param  LogRecord
  * @param  string    A preformatted message, compiled by the <samp>filter</samp> 
  *                   method, containing <samp>$record->getMessage()</samp> and/or 
  *                   <samp>ABException::format($record->getThrown())</samp>
  * @return void
  * @throws SQLiteException
  */
 public function insertRecord(LogRecord $rec, $formattedMessage)
 {
     # compile final sql
     $sql = $this->insertSQL;
     foreach ($this->parameters['db.columns'] as $col) {
         if ($col == 'time') {
             $sql .= $rec->getTime();
         } elseif ($col == 'level') {
             $sql .= $rec->getLevel();
         } elseif ($col == 'prefix') {
             $sql .= "'" . sqlite_escape_string($rec->getPrefix()) . "'";
         } elseif ($col == 'message') {
             $sql .= "'" . sqlite_escape_string($formattedMessage) . "'";
         } elseif ($col == 'cwd') {
             $sql .= "'" . sqlite_escape_string(getcwd()) . "'";
         } else {
             continue;
         }
         $sql .= ',';
     }
     $sql = trim($sql, ',') . ');';
     $this->run($sql);
 }
Beispiel #12
0
 /**
  * Forward a message to the current <samp>{@link LogHandler}</samp>
  *
  * If <samp>$msg</samp> is an <samp>object</samp>, it will be converted to a string 
  * using $obj->__toString()</samp>. If <samp>$msg</samp> is an <samp>Exception</samp>,
  * it will be converted to a string using <samp>ABException::format($e)</samp>. However,
  * this is done by the LogHandler, so these are more or less guidelines than rules.
  *
  * @param  LogRecord
  * @return void
  */
 public function log(LogRecord $rec)
 {
     if ($this->handler != null) {
         // don't log?
         if ($rec->getLevel() < $this->level) {
             return;
         }
         // Filter
         foreach ($this->filters as $filter) {
             try {
                 if (!$filter->filter($rec)) {
                     return;
                 }
             } catch (Exception $e) {
                 $rec->setMessage($rec->getMessage() . ' [LogFilterException in ' . get_class($filter) . '->filter(): ' . $e->getMessage() . '] ');
             }
         }
         // Publish
         $this->handler->publish($rec);
     }
 }
Beispiel #13
0
    }
    if ($_POST["gallons"] == "" || $_POST["gallons"] < 0 || $_POST["gallons"] > 10000) {
        $errors = "true";
        $errGallons = "Gallons outside acceptable range; 0 - 10,000.";
    }
    if ($_POST["octane"] < 87 || $_POST["octane"] > 94) {
        $errors = "true";
        $errOctane = "The only supported octanes are 87 - 94.";
    }
} else {
    $errors = "true";
    $errLogin = "******";
}
if ($errors != "true") {
    // Everything is OK. Do the INSERT:
    $logRec = new LogRecord();
    $logRec->setAutoId($user->getCurrentAutoId());
    $logRec->setUserId($user->getUserId());
    $logRec->setLogDate($_POST["date"]);
    $logRec->setOdometer($_POST["odometer"]);
    $logRec->setGallons($_POST["gallons"]);
    $logRec->setOctane($_POST["octane"]);
    $logRecordId = $logRec->writeRecord();
}
header("content-type: text/xml");
?>


<AddRecordErrors>
	<errors><?php 
echo $errors;
Beispiel #14
0
 /**
  * @param  string
  * @param  int
  * @return void
  */
 public function publish(LogRecord $rec)
 {
     if (@error_log($rec->toString(), 3, $this->file) === false) {
         throw new IOException('Failed to log message');
     }
 }
Beispiel #15
0
    }
    //if (!is_numeric($logRecordDipstick) && ($logRecordDipstick < 0.00 || $logRecordDipstick > 1.00)) {
    if (is_numeric($logRecordDipstick)) {
        if ($logRecordDipstick < 0.0 || $logRecordDipstick > 1.0) {
            $isErrors = "true";
            $errors[logRecordDipstick] = "Dipstick reading must be between 0.00 and 1.00 ({$logRecordDipstick})";
        }
    } else {
        $isErrors = "true";
        $errors[logRecordDipstick] = "Dipstick reading must be a numeric value. You entered \"{$logRecordDipstick}\"";
    }
} else {
    $isErrors = "true";
    $errors[user] = "You are not logged in.";
}
$logRec = new LogRecord();
if ($isErrors != "true") {
    // Everything is OK. Do the INSERT:
    $logRec->setId($logRecordId);
    $logRec->setAutoId($user->getCurrentAutoId());
    $logRec->setUserId($user->getUserId());
    $logRec->setLogDate($logRecordDate);
    $logRec->setOdometer($logRecordOdometer);
    $logRec->setGallons($logRecordGallons);
    $logRec->setOctane($logRecordOctane);
    $logRec->setDipstick($logRecordDipstick);
    $logRec->writeRecord();
}
header("content-type: text/xml");
?>
Beispiel #16
0
if ($logRecordId) {
    $query = sprintf("SELECT DATE_FORMAT(LOG_DATE, '%%Y-%%m-%%d %%H:%%i') AS LOG_DATE_FORMAT, L.* FROM LOG L WHERE L.USER_ID='%s' AND L.AUTO_ID='%s' AND ACTIVE=1 AND LOG_ID IN ('%s', '%s')", mysql_real_escape_string($user->getUserId(), $conn), mysql_real_escape_string($user->getCurrentAutoId(), $conn), mysql_real_escape_string($previousLogRecordId, $conn), mysql_real_escape_string($logRecordId, $conn));
} else {
    $query = sprintf("SELECT DATE_FORMAT(LOG_DATE, '%%Y-%%m-%%d %%H:%%i') AS LOG_DATE_FORMAT, L.* FROM LOG L WHERE L.USER_ID='%s' AND L.AUTO_ID='%s' AND ACTIVE=1 ORDER BY L.ODOMETER LIMIT {$maxRows} OFFSET %s", mysql_real_escape_string($user->getUserId(), $conn), mysql_real_escape_string($user->getCurrentAutoId(), $conn), mysql_real_escape_string($totalRows - $maxRows, $conn));
}
/*
$query = sprintf("SELECT DATE_FORMAT(LOG_DATE, '%%Y-%%m-%%d %%H:%%i') AS LOG_DATE_FORMAT, L.* FROM LOG L WHERE L.USER_ID='%s' AND L.AUTO_ID='%s' AND ACTIVE=1 ORDER BY L.ODOMETER LIMIT $maxRows OFFSET %s",
	mysql_real_escape_string($user->getUserId(), $conn),
	mysql_real_escape_string($user->getCurrentAutoId(), $conn),
	mysql_real_escape_string($totalRows - $maxRows, $conn)
);
*/
$resultSet = mysql_query($query);
//error_log($query);
while ($row = mysql_fetch_array($resultSet, MYSQL_ASSOC)) {
    $logRec = new LogRecord();
    $logRec->setId($row["LOG_ID"]);
    $logRec->setAutoId($row["AUTO_ID"]);
    $logRec->setLogDate($row["LOG_DATE_FORMAT"]);
    $logRec->setOdometer($row["ODOMETER"]);
    $logRec->setGallons($row["GALLONS"]);
    $logRec->setOctane($row["OCTANE"]);
    $logRec->setDipstick($row["DIPSTICK"]);
    ?>

	<record>
		<id><?php 
    echo $logRec->getId();
    ?>
</id>
		<date><?php