3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Log\Writer
;
13 use Zend\Log\Writer\ChromePhp\ChromePhpBridge
;
14 use Zend\Log\Writer\ChromePhp\ChromePhpInterface
;
15 use Zend\Log\Formatter\ChromePhp
as ChromePhpFormatter
;
17 use Zend\Log\Exception
;
19 class ChromePhp
extends AbstractWriter
22 * The instance of ChromePhpInterface that is used to log messages to.
24 * @var ChromePhpInterface
29 * Initializes a new instance of this class.
31 * @param null|ChromePhpInterface|array|Traversable $instance An instance of ChromePhpInterface
32 * that should be used for logging
34 public function __construct($instance = null)
36 if ($instance instanceof Traversable
) {
37 $instance = iterator_to_array($instance);
40 if (is_array($instance)) {
41 parent
::__construct($instance);
42 $instance = isset($instance['instance']) ?
$instance['instance'] : null;
45 if (!($instance instanceof ChromePhpInterface ||
$instance === null)) {
46 throw new Exception\
InvalidArgumentException('You must pass a valid Zend\Log\Writer\ChromePhp\ChromePhpInterface');
49 $this->chromephp
= $instance === null ?
$this->getChromePhp() : $instance;
50 $this->formatter
= new ChromePhpFormatter();
54 * Write a message to the log.
56 * @param array $event event data
59 protected function doWrite(array $event)
61 $line = $this->formatter
->format($event);
63 switch ($event['priority']) {
68 $this->chromephp
->error($line);
71 $this->chromephp
->warn($line);
75 $this->chromephp
->info($line);
78 $this->chromephp
->trace($line);
81 $this->chromephp
->log($line);
87 * Gets the ChromePhpInterface instance that is used for logging.
89 * @return ChromePhpInterface
91 public function getChromePhp()
93 // Remember: class names in strings are absolute; thus the class_exists
94 // here references the canonical name for the ChromePhp class
95 if (!$this->chromephp
instanceof ChromePhpInterface
96 && class_exists('ChromePhp')
98 $this->setChromePhp(new ChromePhpBridge());
100 return $this->chromephp
;
104 * Sets the ChromePhpInterface instance that is used for logging.
106 * @param ChromePhpInterface $instance The instance to set.
109 public function setChromePhp(ChromePhpInterface
$instance)
111 $this->chromephp
= $instance;