Skip to content

Commit

Permalink
Fixes #6978 Empty output for archiving when using the web cron
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Jan 11, 2015
1 parent 3434b89 commit b3251b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/Log/WebCronArchiveLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Piwik\Log;

use Monolog\Logger;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;

/**
* Basic logger that streams messages to stdout.
*
* This logger is used in the archiving when archive.php is called from a HTTP request. In that specific case,
* we want to log to stdout.
*
* @see misc/cron/archive.php
*/
class WebCronArchiveLogger extends AbstractLogger implements LoggerInterface
{
public function log($level, $message, array $context = array())
{
if ($level <= Logger::DEBUG) {
return;
}
echo $message . "\n";
}
}
4 changes: 4 additions & 0 deletions misc/cron/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

use Piwik\Container\StaticContainer;
use Piwik\Log\WebCronArchiveLogger;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -66,6 +67,9 @@
/** @var ConsoleHandler $consoleLogHandler */
$consoleLogHandler = StaticContainer::getContainer()->get('Symfony\Bridge\Monolog\Handler\ConsoleHandler');
$consoleLogHandler->setOutput(new ConsoleOutput(OutputInterface::VERBOSITY_VERBOSE));
} else {
// HTTP request: logs needs to be dumped on stdout
StaticContainer::getContainer()->set('Psr\Log\LoggerInterface', new WebCronArchiveLogger);
}

$archiver = new Piwik\CronArchive();
Expand Down

0 comments on commit b3251b8

Please sign in to comment.