24 lines
601 B
PHP
24 lines
601 B
PHP
<?php
|
|
$input = file_get_contents('php://input');
|
|
$data = json_decode($input, true);
|
|
|
|
if ($data) {
|
|
$logFile = 'metric.log';
|
|
|
|
$logEntry = sprintf(
|
|
"[%s] Metric Type: %s, Metric Value: %s, Page: %s, Entries: %s\n",
|
|
$data['date'],
|
|
$data['metricType'],
|
|
$data['metricValue'],
|
|
$data['page'],
|
|
json_encode($data['entries']) // konwertowanie wpisów na ciąg JSON
|
|
);
|
|
|
|
// Dodawanie danych do pliku dziennika
|
|
file_put_contents($logFile, $logEntry, FILE_APPEND);
|
|
|
|
// Odpowiedź serwera
|
|
echo "Metric logged successfully";
|
|
}
|
|
?>
|