Browse Source

add log support

main
ghost 1 year ago
parent
commit
94b1ca5700
  1. 4
      .gitignore
  2. 15
      example/environment/env.example.php
  3. 48
      src/crontab/export/feed.php
  4. 50
      src/crontab/export/push.php
  5. 14
      src/crontab/import/feed.php
  6. 0
      src/storage/log/index.html

4
.gitignore vendored

@ -6,13 +6,15 @@
/src/public/api/*.json /src/public/api/*.json
/src/config/* /src/config/
!/src/config/bootstrap.php !/src/config/bootstrap.php
!/src/config/nodes.php !/src/config/nodes.php
!/src/config/trackers.php !/src/config/trackers.php
/src/public/sitemap.xml /src/public/sitemap.xml
/src/storage/log/*.log
/composer.lock /composer.lock
*test* *test*

15
example/environment/env.example.php

@ -175,3 +175,18 @@ define('API_IMPORT_MAGNET_COMMENTS_ENABLED', true); // depends of API_IMP
define('API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY', false); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED, API_IMPORT_MAGNET_COMMENTS_ENABLED define('API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY', false); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED, API_IMPORT_MAGNET_COMMENTS_ENABLED
define('API_IMPORT_MAGNET_STARS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED define('API_IMPORT_MAGNET_STARS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED
define('API_IMPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED define('API_IMPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED
// Logs
define('LOG_DIRECTORY', __DIR__ . '/../storage/log');
define('LOG_CRONTAB_EXPORT_FEED_ENABLED', true);
define('LOG_CRONTAB_EXPORT_FEED_FILENAME', sprintf('crontab_export_feed_%s.log', date('Y-m-d')));
define('LOG_CRONTAB_EXPORT_PUSH_ENABLED', true);
define('LOG_CRONTAB_EXPORT_PUSH_FILENAME', sprintf('crontab_export_push_%s.log', date('Y-m-d')));
define('LOG_CRONTAB_IMPORT_FEED_ENABLED', true);
define('LOG_CRONTAB_IMPORT_FEED_FILENAME', sprintf('crontab_import_feed_%s.log', date('Y-m-d')));
define('LOG_API_PUSH_ENABLED', true);
define('LOG_API_PUSH_FILENAME', sprintf('api_push_%s.log', date('Y-m-d')));

48
src/crontab/export/feed.php

@ -5,7 +5,7 @@ $semaphore = sem_get(crc32('yggtracker.crontab.export.feed'), 1);
if (false === sem_acquire($semaphore, true)) if (false === sem_acquire($semaphore, true))
{ {
exit (PHP_EOL . 'yggtracker.crontab.export.feed process locked by another thread.' . PHP_EOL); exit (_('yggtracker.crontab.export.feed process locked by another thread.'));
} }
// Bootstrap // Bootstrap
@ -14,10 +14,21 @@ require_once __DIR__ . '/../../config/bootstrap.php';
// Init Debug // Init Debug
$debug = $debug =
[ [
'dump' => [],
'time' => [ 'time' => [
'ISO8601' => date('c'), 'ISO8601' => date('c'),
'total' => microtime(true), 'total' => microtime(true),
], ],
'http' =>
[
'total' => 0,
],
'memory' =>
[
'start' => memory_get_usage(),
'total' => 0,
'peaks' => 0
],
]; ];
// Define public registry // Define public registry
@ -521,15 +532,26 @@ try
// Debug output // Debug output
$debug['time']['total'] = microtime(true) - $debug['time']['total']; $debug['time']['total'] = microtime(true) - $debug['time']['total'];
print_r( $debug['memory']['total'] = memory_get_usage() - $debug['memory']['start'];
array_merge($debug, [ $debug['memory']['peaks'] = memory_get_peak_usage();
'db' => [
'total' => [ $debug['db']['total']['select'] = $db->getDebug()->query->select->total;
'select' => $db->getDebug()->query->select->total, $debug['db']['total']['insert'] = $db->getDebug()->query->insert->total;
'insert' => $db->getDebug()->query->insert->total, $debug['db']['total']['update'] = $db->getDebug()->query->update->total;
'update' => $db->getDebug()->query->update->total, $debug['db']['total']['delete'] = $db->getDebug()->query->delete->total;
'delete' => $db->getDebug()->query->delete->total,
] print_r($debug);
]
]) // Debug log
); if (LOG_CRONTAB_EXPORT_FEED_ENABLED)
{
@mkdir(LOG_DIRECTORY, 0770, true);
if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_FEED_FILENAME, 'a+'))
{
fwrite($handle, print_r($debug, true));
fclose($handle);
chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_FEED_FILENAME, 0770);
}
}

50
src/crontab/export/push.php

@ -14,12 +14,21 @@ require_once __DIR__ . '/../../config/bootstrap.php';
// Init Debug // Init Debug
$debug = $debug =
[ [
'time' => 'dump' => [],
[ 'time' => [
'ISO8601' => date('c'), 'ISO8601' => date('c'),
'total' => microtime(true), 'total' => microtime(true),
], ],
'result' => [] 'http' =>
[
'total' => 0,
],
'memory' =>
[
'start' => memory_get_usage(),
'total' => 0,
'peaks' => 0
],
]; ];
// Define public registry // Define public registry
@ -367,15 +376,26 @@ else
// Debug output // Debug output
$debug['time']['total'] = microtime(true) - $debug['time']['total']; $debug['time']['total'] = microtime(true) - $debug['time']['total'];
print_r( $debug['memory']['total'] = memory_get_usage() - $debug['memory']['start'];
array_merge($debug, [ $debug['memory']['peaks'] = memory_get_peak_usage();
'db' => [
'total' => [ $debug['db']['total']['select'] = $db->getDebug()->query->select->total;
'select' => $db->getDebug()->query->select->total, $debug['db']['total']['insert'] = $db->getDebug()->query->insert->total;
'insert' => $db->getDebug()->query->insert->total, $debug['db']['total']['update'] = $db->getDebug()->query->update->total;
'update' => $db->getDebug()->query->update->total, $debug['db']['total']['delete'] = $db->getDebug()->query->delete->total;
'delete' => $db->getDebug()->query->delete->total,
] print_r($debug);
]
]) // Debug log
); if (LOG_CRONTAB_EXPORT_PUSH_ENABLED)
{
@mkdir(LOG_DIRECTORY, 0770, true);
if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_PUSH_FILENAME, 'a+'))
{
fwrite($handle, print_r($debug, true));
fclose($handle);
chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_PUSH_FILENAME, 0770);
}
}

14
src/crontab/import/feed.php

@ -1142,3 +1142,17 @@ $debug['db']['total']['update'] = $db->getDebug()->query->update->total;
$debug['db']['total']['delete'] = $db->getDebug()->query->delete->total; $debug['db']['total']['delete'] = $db->getDebug()->query->delete->total;
print_r($debug); print_r($debug);
// Debug log
if (LOG_CRONTAB_IMPORT_FEED_ENABLED)
{
@mkdir(LOG_DIRECTORY, 0770, true);
if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_IMPORT_FEED_FILENAME, 'a+'))
{
fwrite($handle, print_r($debug, true));
fclose($handle);
chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_IMPORT_FEED_FILENAME, 0770);
}
}

0
src/storage/log/index.html

Loading…
Cancel
Save