diff --git a/lib/Data/Filesystem.php b/lib/Data/Filesystem.php index 96ee691..cafff11 100644 --- a/lib/Data/Filesystem.php +++ b/lib/Data/Filesystem.php @@ -63,6 +63,7 @@ class Filesystem extends AbstractData if (!is_dir($storagedir)) { mkdir($storagedir, 0700, true); } + self::logToMetrics("CREATE",$pasteid); return DataStore::store($file, $paste); } @@ -78,6 +79,7 @@ class Filesystem extends AbstractData if (!$this->exists($pasteid)) { return false; } + self::logToMetrics("READ",$pasteid); return self::upgradePreV1Format( DataStore::get(self::_dataid2path($pasteid) . $pasteid . '.php') ); @@ -111,6 +113,7 @@ class Filesystem extends AbstractData $dir->close(); rmdir($discdir); } + self::logToMetrics("DELETE",$pasteid); } } @@ -165,6 +168,7 @@ class Filesystem extends AbstractData if (!is_dir($storagedir)) { mkdir($storagedir, 0700, true); } + self::logToMetrics("COMMENT",$pasteid); return DataStore::store($file, $comment); } @@ -362,4 +366,18 @@ class Filesystem extends AbstractData { return (bool) preg_match('/^[a-f0-9]{2}$/', $element); } + + /** + * Add custom log + * + * @access private + * @return bool + */ + private function logToMetrics($message, $id=null) + { + $today = date('Y-m-d H:i:s'); + $line="$today $message \t$id\n"; + $dir= '/var/www/paste.libre-service.eu/data'; + return (bool) file_put_contents("$dir/metrics.log",$line,FILE_APPEND|LOCK_EX); + } }