Patch metric logs.

This commit is contained in:
Christian P. MOMON 2021-11-17 01:59:25 +01:00 committed by root
parent c0ef04fb36
commit 017b000305
1 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,7 @@ class Filesystem extends AbstractData
if (!is_dir($storagedir)) { if (!is_dir($storagedir)) {
mkdir($storagedir, 0700, true); mkdir($storagedir, 0700, true);
} }
self::logToMetrics("CREATE",$pasteid);
return DataStore::store($file, $paste); return DataStore::store($file, $paste);
} }
@ -78,6 +79,7 @@ class Filesystem extends AbstractData
if (!$this->exists($pasteid)) { if (!$this->exists($pasteid)) {
return false; return false;
} }
self::logToMetrics("READ",$pasteid);
return self::upgradePreV1Format( return self::upgradePreV1Format(
DataStore::get(self::_dataid2path($pasteid) . $pasteid . '.php') DataStore::get(self::_dataid2path($pasteid) . $pasteid . '.php')
); );
@ -111,6 +113,7 @@ class Filesystem extends AbstractData
$dir->close(); $dir->close();
rmdir($discdir); rmdir($discdir);
} }
self::logToMetrics("DELETE",$pasteid);
} }
} }
@ -165,6 +168,7 @@ class Filesystem extends AbstractData
if (!is_dir($storagedir)) { if (!is_dir($storagedir)) {
mkdir($storagedir, 0700, true); mkdir($storagedir, 0700, true);
} }
self::logToMetrics("COMMENT",$pasteid);
return DataStore::store($file, $comment); return DataStore::store($file, $comment);
} }
@ -362,4 +366,18 @@ class Filesystem extends AbstractData
{ {
return (bool) preg_match('/^[a-f0-9]{2}$/', $element); 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);
}
} }