mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
PHRAS-846 #time 1d
display of tasks logs in admin is ok. if many logs (logrotate) display links
This commit is contained in:
@@ -178,35 +178,31 @@ class TaskManagerController extends Controller
|
|||||||
|
|
||||||
public function getSchedulerLog(Request $request)
|
public function getSchedulerLog(Request $request)
|
||||||
{
|
{
|
||||||
file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export(null, true)), FILE_APPEND);
|
|
||||||
/** @var LogFileFactory $factory */
|
/** @var LogFileFactory $factory */
|
||||||
$factory = $this->app['task-manager.log-file.factory'];
|
$factory = $this->app['task-manager.log-file.factory'];
|
||||||
$logFile = $factory->forManager();
|
$logFile = $factory->forManager();
|
||||||
if ($request->query->get('clr')) {
|
if ($request->query->get('clr') && $request->query->get('version') !== null) {
|
||||||
$logFile->clear($request->query->get('version'));
|
$logFile->clear($request->query->get('version'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('admin/task-manager/log_scheduler.html.twig', [
|
return $this->render('admin/task-manager/log_scheduler.html.twig', [
|
||||||
'logfile' => $logFile,
|
'logfile' => $logFile,
|
||||||
'version' => $request->query->get('version'),
|
'version' => $request->query->get('version')
|
||||||
'logname' => 'Scheduler',
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTaskLog(Request $request, Task $task)
|
public function getTaskLog(Request $request, Task $task)
|
||||||
{
|
{
|
||||||
file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export(null, true)), FILE_APPEND);
|
|
||||||
/** @var LogFileFactory $factory */
|
/** @var LogFileFactory $factory */
|
||||||
$factory = $this->app['task-manager.log-file.factory'];
|
$factory = $this->app['task-manager.log-file.factory'];
|
||||||
$logFile = $factory->forTask($task);
|
$logFile = $factory->forTask($task);
|
||||||
if ($request->query->get('clr')) {
|
if ($request->query->get('clr') && $request->query->get('version') !== null) {
|
||||||
$logFile->clear($request->query->get('version'));
|
$logFile->clear($request->query->get('version'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('admin/task-manager/log_task.html.twig', [
|
return $this->render('admin/task-manager/log_task.html.twig', [
|
||||||
'logfile' => $logFile,
|
'logfile' => $logFile,
|
||||||
'version' => $request->query->get('version'),
|
'version' => $request->query->get('version')
|
||||||
'logname' => sprintf('%s (task id %d)', $task->getName(), $task->getId()),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,6 +66,15 @@ abstract class AbstractLogFile implements LogFileInterface
|
|||||||
*/
|
*/
|
||||||
public function clear($version)
|
public function clear($version)
|
||||||
{
|
{
|
||||||
file_put_contents($this->getPath($version), '');
|
file_put_contents($this->getPath($version), sprintf("File cleared %s\n", date('r')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function versionExists($version)
|
||||||
|
{
|
||||||
|
return file_exists($this->getPath($version));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -54,4 +54,13 @@ interface LogFileInterface
|
|||||||
* @param string $version
|
* @param string $version
|
||||||
*/
|
*/
|
||||||
public function clear($version);
|
public function clear($version);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the logfile exists
|
||||||
|
*
|
||||||
|
* @param $version
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function versionExists($version);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\TaskManager\Log;
|
namespace Alchemy\Phrasea\TaskManager\Log;
|
||||||
|
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
|
||||||
class ManagerLogFile extends AbstractLogFile implements LogFileInterface
|
class ManagerLogFile extends AbstractLogFile implements LogFileInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +21,17 @@ class ManagerLogFile extends AbstractLogFile implements LogFileInterface
|
|||||||
*/
|
*/
|
||||||
public function getVersions()
|
public function getVersions()
|
||||||
{
|
{
|
||||||
return array('');
|
$x = '/^scheduler(|(-.*))\.log$/';
|
||||||
|
$f = new Finder();
|
||||||
|
$versions = [];
|
||||||
|
/** @var \SplFileInfo $file */
|
||||||
|
foreach($f->files()->in($this->root) as $file) {
|
||||||
|
$matches = [];
|
||||||
|
if(preg_match($x, $file->getBasename(), $matches)) {
|
||||||
|
$versions[] = $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +39,6 @@ class ManagerLogFile extends AbstractLogFile implements LogFileInterface
|
|||||||
*/
|
*/
|
||||||
public function getPath($version)
|
public function getPath($version)
|
||||||
{
|
{
|
||||||
return sprintf('%s/scheduler%s.log', $this->root, $version ? ('-'.$version) : '' );
|
return sprintf('%s/scheduler%s.log', $this->root, $version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,8 @@
|
|||||||
namespace Alchemy\Phrasea\TaskManager\Log;
|
namespace Alchemy\Phrasea\TaskManager\Log;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Model\Entities\Task;
|
use Alchemy\Phrasea\Model\Entities\Task;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
|
||||||
class TaskLogFile extends AbstractLogFile implements LogFileInterface
|
class TaskLogFile extends AbstractLogFile implements LogFileInterface
|
||||||
{
|
{
|
||||||
@@ -29,7 +31,17 @@ class TaskLogFile extends AbstractLogFile implements LogFileInterface
|
|||||||
*/
|
*/
|
||||||
public function getVersions()
|
public function getVersions()
|
||||||
{
|
{
|
||||||
return array('', '2015-12-21');
|
$x = sprintf('/^task_%d(|(-.*))\.log$/', $this->task->getId());
|
||||||
|
$f = new Finder();
|
||||||
|
$versions = [];
|
||||||
|
/** @var \SplFileInfo $file */
|
||||||
|
foreach($f->files()->in($this->root) as $file) {
|
||||||
|
$matches = [];
|
||||||
|
if(preg_match($x, $file->getBasename(), $matches)) {
|
||||||
|
$versions[] = $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,8 +59,7 @@ class TaskLogFile extends AbstractLogFile implements LogFileInterface
|
|||||||
*/
|
*/
|
||||||
public function getPath($version)
|
public function getPath($version)
|
||||||
{
|
{
|
||||||
$path = sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version ? ('-'.$version) : '');
|
return sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version);
|
||||||
file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($path, true)), FILE_APPEND);
|
|
||||||
return sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version ? ('-'.$version) : '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,22 @@
|
|||||||
<a href="{{ path('admin_tasks_list') }} ">
|
{% if version is null and logfile.versionExists('') %}
|
||||||
< {{ 'Return' | trans }}
|
{% set version = '' %}
|
||||||
</a>
|
{% endif %}
|
||||||
<h4>{{ logname }}</h4>
|
|
||||||
|
<h4>
|
||||||
|
sheduler log
|
||||||
|
{% if version is not null %}
|
||||||
|
version {{ version ? version : "(now)" }}
|
||||||
|
{% endif %}
|
||||||
|
</h4>
|
||||||
|
|
||||||
{% for v in logfile.getVersions() %}
|
{% for v in logfile.getVersions() %}
|
||||||
<a href="{{ path('admin_tasks_scheduler_log', { 'version' : v }) }}">[{{v}}]</a>
|
<a href="{{ path('admin_tasks_scheduler_log', 'version' : v }) }}">{{ v ? v : "(now)" }}</a>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if version != null %}
|
|
||||||
<a href="{{ path('admin_tasks_scheduler_log', { 'clr' : logfile.getPath(version) }) }} ">
|
{% if version is not null %}
|
||||||
|
<pre>{{ logfile.getContent(version) }}</pre>
|
||||||
|
<a href="{{ path('admin_tasks_scheduler_log', 'version' : version, 'clr':'1' }) }} ">
|
||||||
{{ 'Clear' | trans }}
|
{{ 'Clear' | trans }}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<pre>
|
|
||||||
{{ logfile.getContent(version) }}
|
|
||||||
</pre>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
|
{% if version is null and logfile.versionExists('') %}
|
||||||
|
{% set version = '' %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<a href="{{ path('admin_tasks_list') }} ">
|
|
||||||
< {{ 'Return' | trans }}
|
|
||||||
</a>
|
|
||||||
<h4>
|
<h4>
|
||||||
{{ logfile.getTask().getName() }} (task id {{ logfile.getTask.getId() }})
|
{{ logfile.getTask().getName() }} (task id {{ logfile.getTask.getId() }})
|
||||||
{% if version is not null %}
|
{% if version is not null %}
|
||||||
@@ -15,10 +15,8 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if version is not null %}
|
{% if version is not null %}
|
||||||
<pre>
|
<pre>{{ logfile.getContent(version) }}</pre>
|
||||||
{{ logfile.getContent(version) }}
|
<a href="{{ path('admin_tasks_task_log', {'task':logfile.getTask.getId(), 'version' : version, 'clr':'1' }) }} ">
|
||||||
</pre>
|
|
||||||
<a href="{{ path('admin_tasks_task_log', {'task':logfile.getTask.getId(), 'clr' : logfile.getPath(version) }) }} ">
|
|
||||||
{{ 'Clear' | trans }}
|
{{ 'Clear' | trans }}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Reference in New Issue
Block a user