Permalink
Browse files

Log update API requests to a request.log file in a /logs subdirectory.

  • Loading branch information...
1 parent ffd5265 commit 16bcc79964522e9c697874371dd506c6aa33525d @YahnisElsts committed Mar 5, 2013
Showing with 31 additions and 0 deletions.
  1. +29 −0 includes/Wpup/UpdateServer.php
  2. +2 −0 logs/.htaccess
@@ -1,6 +1,7 @@
<?php
class Wpup_UpdateServer {
protected $packageDirectory;
+ protected $logDirectory;
protected $cache;
protected $serverUrl;
protected $startTime = 0;
@@ -21,6 +22,7 @@ public function __construct($serverUrl = null, $serverDirectory = null) {
$this->serverUrl = $serverUrl;
$this->packageDirectory = $serverDirectory . '/packages';
+ $this->logDirectory = $serverDirectory . '/logs';
$this->cache = new Wpup_FileCache($serverDirectory . '/cache');
}
@@ -36,6 +38,7 @@ public function handleRequest($query = null) {
}
$request = $this->initRequest($query);
+ $this->logRequest($request);
$this->checkAuthorization($request);
$this->dispatch($request);
exit;
@@ -191,6 +194,32 @@ protected function generateDownloadUrl(Wpup_Package $package) {
}
/**
+ * Log an API request.
+ *
+ * @param Wpup_Request $request
+ */
+ protected function logRequest($request) {
+ $logFile = $this->logDirectory . '/request.log';
+ $handle = fopen($logFile, 'a');
+ if ( $handle && flock($handle, LOCK_EX) ) {
+ fwrite(
+ $handle,
+ sprintf(
+ "[%s] %s\t%s\t%s\n",
+ date('Y-m-d H:i:s'),
+ $request->action,
+ $request->slug,
+ http_build_query($request->query, '', '&')
+ )
+ );
+ flock($handle, LOCK_UN);
+ }
+ if ( $handle ) {
+ fclose($handle);
+ }
+ }
+
+ /**
* Output something as JSON.
*
* @param mixed $response
View
@@ -0,0 +1,2 @@
+Order deny,allow
+Deny from all

0 comments on commit 16bcc79

Please sign in to comment.