diff --git a/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php b/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php index 186100c19c..164b481aec 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php @@ -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()), ]); } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php b/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php index 53d79b9867..e0c33941b9 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php @@ -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), ''); } } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php b/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php index 534d9a9cac..fab254bc4d 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php @@ -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); } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php b/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php index 22964e8604..5aeec9ee7b 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php @@ -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) : '' ); } } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php b/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php index 3888c4df69..c85ef5d67f 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php @@ -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) : ''); } } diff --git a/templates/web/admin/task-manager/log.html.twig b/templates/web/admin/task-manager/log.html.twig index b9efb1864a..e7f748f5d9 100644 --- a/templates/web/admin/task-manager/log.html.twig +++ b/templates/web/admin/task-manager/log.html.twig @@ -1,12 +1,21 @@ -
- {{ logfile.getContent() }} + {{ logfile.getContent(version) }}+{% endif %}