This commit is contained in:
Jean-Yves Gaulier
2015-12-23 11:14:26 +01:00
parent 97dde2edbb
commit 78be8977de
6 changed files with 69 additions and 31 deletions

View File

@@ -182,26 +182,29 @@ class TaskManagerController extends Controller
$factory = $this->app['task-manager.log-file.factory'];
$logFile = $factory->forManager();
if ($request->query->get('clr')) {
$logFile->clear();
$logFile->clear($request->query->get('version'));
}
return $this->render('admin/task-manager/log.html.twig', [
'logfile' => $logFile,
'version' => $request->query->get('version'),
'logname' => 'Scheduler',
]);
}
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 */
$factory = $this->app['task-manager.log-file.factory'];
$logFile = $factory->forTask($task);
if ($request->query->get('clr')) {
$logFile->clear();
$logFile->clear($request->query->get('version'));
}
return $this->render('admin/task-manager/log.html.twig', [
'logfile' => $logFile,
'version' => $request->query->get('version'),
'logname' => sprintf('%s (task id %d)', $task->getName(), $task->getId()),
]);
}

View File

@@ -34,11 +34,11 @@ abstract class AbstractLogFile implements LogFileInterface
/**
* {@inheritdoc}
*/
public function getContent()
public function getContent($version)
{
$path = $this->getPath();
$path = $this->getPath($version);
if (is_file($path)) {
return file_get_contents($this->getPath());
return file_get_contents($this->getPath($version));
}
return '';
@@ -47,9 +47,9 @@ abstract class AbstractLogFile implements LogFileInterface
/**
* {@inheritdoc}
*/
public function getContentStream()
public function getContentStream($version)
{
$path = $this->getPath();
$path = $this->getPath($version);
return function () use ($path) {
$handle = fopen($path, 'r');
@@ -64,8 +64,8 @@ abstract class AbstractLogFile implements LogFileInterface
/**
* {@inheritdoc}
*/
public function clear($logfile)
public function clear($version)
{
file_put_contents($this->getPath(), '');
file_put_contents($this->getPath($version), '');
}
}

View File

@@ -14,34 +14,44 @@ namespace Alchemy\Phrasea\TaskManager\Log;
interface LogFileInterface
{
/**
* Returns the path to the logfile.
* Returns versions (suffixes due to logrotate) of the logfiles.
* ex. foo.log --> ""
* bar-2015-12-25.log --> "2015-12-25"
*
* @return string[]
*/
public function getLogFiles();
public function getVersions();
/**
* Returns the path of a logfile.
*
* @param string $version
* @return string
*/
public function getPath($version);
/**
* Returns the content of a logfile.
*
* @param string $logfile
* @param string $version
* @return string
*/
public function getContent($logfile);
public function getContent($version);
/**
* Streams the content of a logfile.
*
* This methods returns a closure that echoes the output.
*
* @param string $logfile
* @param string $version
* @return Closure
*/
public function getContentStream($logfile);
public function getContentStream($version);
/**
* Clears the content of a logfile.
*
* @param string $logfile
* @param string $version
*/
public function clear($logfile);
public function clear($version);
}

View File

@@ -16,8 +16,16 @@ class ManagerLogFile extends AbstractLogFile implements LogFileInterface
/**
* {@inheritdoc}
*/
public function getPath()
public function getVersions()
{
return sprintf('%s/scheduler.log', $this->root);
return array('');
}
/**
* {@inheritdoc}
*/
public function getPath($version)
{
return sprintf('%s/scheduler%s.log', $this->root, $version ? ('-'.$version) : '' );
}
}

View File

@@ -24,6 +24,14 @@ class TaskLogFile extends AbstractLogFile implements LogFileInterface
$this->task = $task;
}
/**
* {@inheritdoc}
*/
public function getVersions()
{
return array('', '2015-12-21');
}
/**
* Returns the related Task entity.
*
@@ -37,8 +45,8 @@ class TaskLogFile extends AbstractLogFile implements LogFileInterface
/**
* {@inheritdoc}
*/
public function getPath()
public function getPath($version)
{
return sprintf('%s/task_%d.log', $this->root, $this->task->getId());
return sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version ? ('-'.$version) : '');
}
}

View File

@@ -1,12 +1,21 @@
<h4>
<a href="{{ path('admin_tasks_list') }} ">
< {{ 'Return' | trans }}
</a>
{{ logname }}
<a href="{{ path('admin_tasks_scheduler_log', { 'clr' : logfile.getPath() }) }} ">
<h4>{{ logname }}</h4>
{% for v in logfile.getVersions() %}
{% if version != null and v == version %}
<b>{{v}}]</b>
{% else %}
<a href="{{ path('admin_tasks_scheduler_log', { 'version' : v }) }}">[{{v}}]</a>
{% endif %}
&nbsp;
{% endfor %}
{% if version != null %}
<a href="{{ path('admin_tasks_scheduler_log', { 'clr' : logfile.getPath(version) }) }} ">
{{ 'Clear' | trans }}
</a>
</h4>
<pre>
{{ logfile.getContent() }}
{{ logfile.getContent(version) }}
</pre>
{% endif %}