Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[2.1] Added a ChromePhp logger #2080

Closed
wants to merge 4 commits into from

5 participants

@waltertamboer

This is basically a copy of FirePhp but than referencing the external class called ChromePhp taken from http://www.chromephp.com/

@travisbot

This pull request passes (merged 1c846c52 into f30ec3f).

@Maks3w
Collaborator

Please add tests

@Maks3w
Collaborator

And an entry in the README mentioning this new capability

@travisbot

This pull request fails (merged 73b481be into f30ec3f).

@travisbot

This pull request fails (merged bfafb2e1 into f30ec3f).

@Maks3w Maks3w closed this
@Maks3w Maks3w reopened this
@travisbot

This pull request fails (merged bfafb2e1 into f30ec3f).

@Maks3w
Collaborator

Hi,

We have renamed the folder for tests from Zend to ZendTest.

Can you rebase your PR to catch this change?

Thanks in advance.

@travisbot

This pull request fails (merged 2221468 into fa03b37).

@b-durand

Maybe we can have a WIldfireFormatter, because FirePhpFormatter and ChromePhpFormatter has exactly the same code at this moment. Maybe we can have a base class for wildfire, and FirePhp and ChromePhp are an adapter.

@WalterTamboer can you fix the CS (trailing spaces)? And, can you fix the same problem as ZF2-454?

@b-durand

We need to add ChromePhp like an optional dependency for composer.

@waltertamboer

@b-durand We could create an "EmptyFormatter" that is the same as the old SimpleFormatter. It could just pass the message.

I don't know if this is an actual problem though. Yes it cleans up the code base a bit but it's not like you can't follow what's going on right now. Either way I'm fine with any decision, @weierophinney probably knows the right thing to do :)

@b-durand

@WalterTamboer What do you mean bu the old SimpleFormatter? I don't understand your EmptyFormatter... I talk about FirePhpFormatter.

Maybe you could look PR 2239: the current SimpleFormatter can display only the message. The beginning of my thinking is just that we have two identical Formatters (FirePhp and ChromePhp).

@waltertamboer

@b-durand I meant the SimpleFormatter class that we first had, that was simly a class that forwarded the message, now it also has stuff in it for date and times.

@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'feature/chromephp' of https://github.com/WalterTamboer/zf2
 into feature/log-chrome-writer

PR #2080
69d5c50
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#2080] CS fixes
- Trailing whitespace
954e09c
@basz basz referenced this pull request from a commit
@weierophinney weierophinney [#2080] CS fixes
- Trailing whitespace
1b71273
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'feature/chromephp' of https://github.com/WalterTamboer/zf2
 into feature/log-chrome-writer

PR #2080
70807d3
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#2080] CS fixes
- Trailing whitespace
c86d788
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'feature/log-chrome-writer'
Close #2080
4e9cd4e
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-log
@weierophinney weierophinney Merge branch 'feature/chromephp' of https://github.com/WalterTamboer/zf2
 into feature/log-chrome-writer

PR zendframework/zf2#2080
b9d61be
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-log
@weierophinney weierophinney [zendframework/zf2#2080] CS fixes
- Trailing whitespace
04c654e
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-log
@weierophinney weierophinney Merge branch 'feature/log-chrome-writer' a8104b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
51 library/Zend/Log/Formatter/ChromePhp.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Log
+ */
+
+namespace Zend\Log\Formatter;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Formatter
+ */
+class ChromePhp implements FormatterInterface
+{
+ /**
+ * Formats the given event data into a single line to be written by the writer.
+ *
+ * @param array $event The event data which should be formatted.
+ * @return string
+ */
+ public function format($event)
+ {
+ return $event['message'];
+ }
+
+ /**
+ * This method is implemented for FormatterInterface but not used.
+ *
+ * @return string
+ */
+ public function getDateTimeFormat()
+ {
+ return '';
+ }
+
+ /**
+ * This method is implemented for FormatterInterface but not used.
+ *
+ * @param string $dateTimeFormat
+ * @return FormatterInterface
+ */
+ public function setDateTimeFormat($dateTimeFormat)
+ {
+ return $this;
+ }
+}
View
105 library/Zend/Log/Writer/ChromePhp.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Log
+ */
+
+namespace Zend\Log\Writer;
+
+use Zend\Log\Writer\ChromePhp\ChromePhpBridge;
+use Zend\Log\Writer\ChromePhp\ChromePhpInterface;
+use Zend\Log\Formatter\ChromePhp as ChromePhpFormatter;
+use Zend\Log\Logger;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ */
+class ChromePhp extends AbstractWriter
+{
+ /**
+ * The instance of ChromePhpInterface that is used to log messages to.
+ *
+ * @var ChromePhpInterface
+ */
+ protected $chromephp;
+
+ /**
+ * Initializes a new instance of this class.
+ *
+ * @param null|ChromePhpInterface $instance An instance of ChromePhpInterface
+ * that should be used for logging
+ */
+ public function __construct(ChromePhpInterface $instance = null)
+ {
+ $this->chromephp = $instance === null ? $this->getChromePhp() : $instance;
+ $this->formatter = new ChromePhpFormatter();
+ }
+
+ /**
+ * Write a message to the log.
+ *
+ * @param array $event event data
+ * @return void
+ */
+ protected function doWrite(array $event)
+ {
+ $line = $this->formatter->format($event);
+
+ switch ($event['priority']) {
+ case Logger::EMERG:
+ case Logger::ALERT:
+ case Logger::CRIT:
+ case Logger::ERR:
+ $this->chromephp->error($line);
+ break;
+ case Logger::WARN:
+ $this->chromephp->warn($line);
+ break;
+ case Logger::NOTICE:
+ case Logger::INFO:
+ $this->chromephp->info($line);
+ break;
+ case Logger::DEBUG:
+ $this->chromephp->trace($line);
+ break;
+ default:
+ $this->chromephp->log($line);
+ break;
+ }
+ }
+
+ /**
+ * Gets the ChromePhpInterface instance that is used for logging.
+ *
+ * @return ChromePhpInterface
+ */
+ public function getChromePhp()
+ {
+ // Remember: class names in strings are absolute; thus the class_exists
+ // here references the canonical name for the ChromePhp class
+ if (!$this->chromephp instanceof ChromePhpInterface
+ && class_exists('ChromePhp')
+ ) {
+ $this->setChromePhp(new ChromePhpBridge());
+ }
+ return $this->chromephp;
+ }
+
+ /**
+ * Sets the ChromePhpInterface instance that is used for logging.
+ *
+ * @param ChromePhpInterface $instance The instance to set.
+ * @return ChromePhp
+ */
+ public function setChromePhp(ChromePhpInterface $instance)
+ {
+ $this->chromephp = $instance;
+ return $this;
+ }
+}
View
71 library/Zend/Log/Writer/ChromePhp/ChromePhpBridge.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Log
+ */
+
+namespace Zend\Log\Writer\ChromePhp;
+
+use ChromePhp;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ */
+class ChromePhpBridge implements ChromePhpInterface
+{
+ /**
+ * Log an error message
+ *
+ * @param string $line
+ */
+ public function error($line)
+ {
+ ChromePhp::error($line);
+ }
+
+ /**
+ * Log a warning
+ *
+ * @param string $line
+ */
+ public function warn($line)
+ {
+ ChromePhp::warn($line);
+ }
+
+ /**
+ * Log informational message
+ *
+ * @param string $line
+ */
+ public function info($line)
+ {
+ ChromePhp::info($line);
+ }
+
+ /**
+ * Log a trace
+ *
+ * @param string $line
+ */
+ public function trace($line)
+ {
+ ChromePhp::error($line);
+ }
+
+ /**
+ * Log a message
+ *
+ * @param string $line
+ */
+ public function log($line)
+ {
+ ChromePhp::log($line);
+ }
+}
View
54 library/Zend/Log/Writer/ChromePhp/ChromePhpInterface.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Log
+ */
+
+namespace Zend\Log\Writer\ChromePhp;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ */
+interface ChromePhpInterface
+{
+ /**
+ * Log an error message
+ *
+ * @param string $line
+ */
+ public function error($line);
+
+ /**
+ * Log a warning
+ *
+ * @param string $line
+ */
+ public function warn($line);
+
+ /**
+ * Log informational message
+ *
+ * @param string $line
+ */
+ public function info($line);
+
+ /**
+ * Log a trace
+ *
+ * @param string $line
+ */
+ public function trace($line);
+
+ /**
+ * Log a message
+ *
+ * @param string $line
+ */
+ public function log($line);
+}
View
46 tests/ZendTest/Log/TestAsset/MockChromePhp.php
@@ -0,0 +1,46 @@
+<?php
+namespace ZendTest\Log\TestAsset;
+
+use Zend\Log\Writer\ChromePhp\ChromePhpInterface;
+
+class MockChromePhp implements ChromePhpInterface
+{
+ public $calls = array();
+
+ protected $enabled;
+
+ public function __construct($enabled = true)
+ {
+ $this->enabled = $enabled;
+ }
+
+ public function getEnabled()
+ {
+ return $this->enabled;
+ }
+
+ public function error($line)
+ {
+ $this->calls['error'][] = $line;
+ }
+
+ public function warn($line)
+ {
+ $this->calls['warn'][] = $line;
+ }
+
+ public function info($line)
+ {
+ $this->calls['info'][] = $line;
+ }
+
+ public function trace($line)
+ {
+ $this->calls['trace'][] = $line;
+ }
+
+ public function log($line)
+ {
+ $this->calls['log'][] = $line;
+ }
+}
View
83 tests/ZendTest/Log/Writer/ChromePhpTest.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace ZendTest\Log\Writer;
+
+use ZendTest\Log\TestAsset\MockChromePhp;
+use Zend\Log\Writer\ChromePhp;
+use Zend\Log\Writer\ChromePhp\ChromePhpInterface;
+use Zend\Log\Logger;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Log
+ */
+class ChromePhpTest extends \PHPUnit_Framework_TestCase
+{
+ protected $chromephp;
+
+ public function setUp()
+ {
+ $this->chromephp = new MockChromePhp();
+
+ }
+
+ public function testGetChromePhp()
+ {
+ $writer = new ChromePhp($this->chromephp);
+ $this->assertTrue($writer->getChromePhp() instanceof ChromePhpInterface);
+ }
+
+ public function testSetChromePhp()
+ {
+ $writer = new ChromePhp($this->chromephp);
+ $chromephp2 = new MockChromePhp();
+
+ $writer->setChromePhp($chromephp2);
+ $this->assertTrue($writer->getChromePhp() instanceof ChromePhpInterface);
+ $this->assertEquals($chromephp2, $writer->getChromePhp());
+ }
+
+ public function testWrite()
+ {
+ $writer = new ChromePhp($this->chromephp);
+ $writer->write(array(
+ 'message' => 'my msg',
+ 'priority' => Logger::DEBUG
+ ));
+ $this->assertEquals('my msg', $this->chromephp->calls['trace'][0]);
+ }
+
+ public function testWriteDisabled()
+ {
+ $chromephp = new MockChromePhp(false);
+ $writer = new ChromePhp($chromephp);
+ $writer->write(array(
+ 'message' => 'my msg',
+ 'priority' => Logger::DEBUG
+ ));
+ $this->assertTrue(empty($this->chromephp->calls));
+ }
+}
Something went wrong with that request. Please try again.