mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 13:33:14 +00:00
Switch task manager logging to monolog
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Monolog\Handler;
|
||||
use Monolog\Logger;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -28,25 +30,6 @@ class module_console_schedulerStart extends Command
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Start the scheduler');
|
||||
$this->addOption(
|
||||
'nolog'
|
||||
, NULL
|
||||
, 1 | InputOption::VALUE_NONE
|
||||
, 'do not log (scheduler) to logfile'
|
||||
, NULL
|
||||
);
|
||||
$this->addOption(
|
||||
'notasklog'
|
||||
, NULL
|
||||
, 1 | InputOption::VALUE_NONE
|
||||
, 'do not log (tasks) to logfiles'
|
||||
, NULL
|
||||
);
|
||||
$this->setHelp(
|
||||
"You should use launch the command and finish it with `&`"
|
||||
. " to return to the console\n\n"
|
||||
. "\tie : <info>bin/console scheduler:start &</info>"
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -59,9 +42,18 @@ class module_console_schedulerStart extends Command
|
||||
return 1;
|
||||
}
|
||||
|
||||
$logger = new Logger('Task logger');
|
||||
|
||||
$handler = new Handler\StreamHandler(fopen('php://stdout'), $input->getOption('verbose') ? Logger::DEBUG : Logger::WARNING);
|
||||
$logger->pushHandler($handler);
|
||||
|
||||
$logfile = __DIR__ . '/../../../../scheduler.log';
|
||||
$handler = new Handler\RotatingFileHandler($logfile, 10, $level = Logger::WARNING);
|
||||
$logger->pushHandler($handler);
|
||||
|
||||
try {
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($input, $output);
|
||||
$scheduler->run($logger);
|
||||
} catch (\Exception $e) {
|
||||
switch ($e->getCode()) {
|
||||
case task_Scheduler::ERR_ALREADY_RUNNING: // 114 : aka EALREADY (Operation already in progress)
|
||||
|
@@ -9,17 +9,20 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Monolog\Handler;
|
||||
use Monolog\Logger;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_taskrun extends Command
|
||||
{
|
||||
@@ -95,14 +98,26 @@ class module_console_taskrun extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$logger = new Logger('Task logger');
|
||||
|
||||
if ($input->getOption('verbose')) {
|
||||
$handler = new Handler\StreamHandler(fopen('php://stdout', 'a'));
|
||||
$logger->pushHandler($handler);
|
||||
}
|
||||
|
||||
$logfile = __DIR__ . '/../../../../task_l_' . $task_id . '.log';
|
||||
$handler = new Handler\RotatingFileHandler($logfile, 10, $level = Logger::WARNING);
|
||||
$logger->pushHandler($handler);
|
||||
|
||||
register_tick_function(array($this, 'tick_handler'), true);
|
||||
declare(ticks = 1);
|
||||
|
||||
if (function_exists('pcntl_signal')) {
|
||||
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
|
||||
}
|
||||
|
||||
try {
|
||||
$this->task->run($runner, $input, $output);
|
||||
$this->task->run($runner, $logger);
|
||||
} catch (Exception $e) {
|
||||
$this->task->log(sprintf("taskrun : exception from 'run()', %s \n", $e->getMessage()));
|
||||
|
||||
|
Reference in New Issue
Block a user