Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
log a request ID and the current version
  • Loading branch information
MorrisJobke committed Sep 21, 2016
commit bf28fd5e1dfb0759698f8ae72354dcbcec782cf6
26 changes: 25 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class Updater {
private $buildTime;
/** @var bool */
private $updateAvailable = false;
/** @var string */
private $requestID = null;

public function __construct() {
$configFileName = __DIR__ . '/../config/config.php';
Expand Down Expand Up @@ -459,6 +461,8 @@ private function getUpdateServerResponse() {
$this->silentLog('[info] updaterServer: ' . $updaterServer);

$releaseChannel = !is_null($this->getConfigOption('updater.release.channel')) ? $this->getConfigOption('updater.release.channel') : 'stable';
$this->silentLog('[info] releaseChannel: ' . $releaseChannel);
$this->silentLog('[info] internal version: ' . $this->getConfigOption('version'));

// Download update response
$curl = curl_init();
Expand Down Expand Up @@ -961,7 +965,17 @@ public function log($message) {
throw new \LogException('Could not open updater.log');
}

$logLine = date(\DateTime::ISO8601) . ' ' . $message . PHP_EOL;
if($this->requestID === null) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 10; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want people complaining about that. Can we just use http://php.net/manual/en/function.random-int.php?

Also you might want to add $_SERVER['UNIQUE_ID'] which is used by http://httpd.apache.org/docs/current/mod/mod_unique_id.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for making the log more readable.

}
$this->requestID = $randomString;
}

$logLine = date(\DateTime::ISO8601) . ' ' . $this->requestID . ' ' . $message . PHP_EOL;

$result = fwrite($fh, $logLine);
if($result === false) {
Expand All @@ -984,6 +998,15 @@ public function silentLog($message) {
/* ignore log exception here (already detected later anyways) */
}
}


/**
* Logs current version
*
*/
public function logVersion() {
$this->silentLog('[info] current version: ' . $this->currentVersion . ' build time: ' . $this->buildTime);
}
}

ini_set('display_errors', '0');
Expand Down Expand Up @@ -1120,6 +1143,7 @@ public function silentLog($message) {
}

$updater->log('[info] show HTML page');
$updater->logVersion();
$updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
?>

Expand Down