<?php
/**
 * PHPCI - Continuous Integration for PHP
 *
 * @copyright    Copyright 2014, Block 8 Limited.
 * @license      https://github.com/Block8/PHPCI/blob/master/LICENSE.md
 * @link         https://www.phptesting.org/
 */

namespace PHPCI\Logging;

use b8\Store\Factory;
use Monolog\Handler\AbstractProcessingHandler;
use PHPCI\Model\Build;

class BuildDBLogHandler extends AbstractProcessingHandler
{
    /**
     * @var Build
     */
    protected $build;

    protected $logValue;

    public function __construct(
        Build $build,
        $level = LogLevel::INFO,
        $bubble = true
    ) {
        parent::__construct($level, $bubble);
        $this->build = $build;
        // We want to add to any existing saved log information.
        $this->logValue = $build->getLog();
    }

    protected function write(array $record)
    {
        $message = (string)$record['message'];
        $message = str_replace($this->build->currentBuildPath, '/', $message);

        $this->logValue .= $message . PHP_EOL;
        $this->build->setLog($this->logValue);

        Factory::getStore('Build')->save($this->build);
    }
}

<?php
/**
 * PHPCI - Continuous Integration for PHP
 *
 * @copyright    Copyright 2014, Block 8 Limited.
 * @license      https://github.com/Block8/PHPCI/blob/master/LICENSE.md
 * @link         https://www.phptesting.org/
 */

namespace PHPCI\Logging;

use b8\Store;
use Monolog\Handler\AbstractProcessingHandler;
use PHPCI\Model\Build;

class BuildDBLogHandler extends AbstractProcessingHandler
{
    /**
     * @var Build
     */
    protected $build;

    protected $logValue;

    public function __construct(
        Build $build,
        $level = LogLevel::INFO,
        $bubble = true
    ) {
        parent::__construct($level, $bubble);
        $this->build = $build;
        // We want to add to any existing saved log information.
        $this->logValue = $build->getLog();
    }

    protected function write(array $record)
    {
        $message = (string)$record['message'];
        $message = str_replace($this->build->currentBuildPath, '/', $message);

        $this->logValue .= $message . PHP_EOL;
        $this->build->setLog($this->logValue);
    }
}

--- 
+++ 
@@ -9,7 +9,7 @@
 
 namespace PHPCI\Logging;
 
-use b8\Store;
+use b8\Store\Factory;
 use Monolog\Handler\AbstractProcessingHandler;
 use PHPCI\Model\Build;
 
@@ -40,5 +40,7 @@
 
         $this->logValue .= $message . PHP_EOL;
         $this->build->setLog($this->logValue);
+
+        Factory::getStore('Build')->save($this->build);
     }
 }
Save the build log every time the log is updated.
