Browse Source

merged branch stof/loggerinterface (PR #1356)

Commits
-------

72d0ebe9 [WebProfilerBundle] Added the support of the the logging context in the template
410b3e0 [HttpKernel] Added the context in the LoggerInterface

Discussion
----------

context in the LoggerInterface

This adds the context in the LoggerInterface. The change is totally BC for people using the logger. However this affects people implementing the interface.

Note that this require Seldaek/monolog#33 for the implementation

---------------------------------------------------------------------------

by Seldaek at 2011/06/17 04:24:18 -0700

@fabpot: just ping me when you are merging this one, so I can merge in monolog and we avoid out-of-sync issues.

---------------------------------------------------------------------------

by stof at 2011/06/17 04:49:05 -0700

@Seldaek you can merge in Monolog when you want. Monolog is BC so merging it before the PR in Symfony2 does not break things.

---------------------------------------------------------------------------

by Seldaek at 2011/06/17 05:08:34 -0700

Ah right, I thought the interfaces wouldn't match, but PHP allows extra args it seems so I'll merge right now.

---------------------------------------------------------------------------

by stof at 2011/06/17 05:32:58 -0700

PHP allows extra *optionnal* args and it is the case here :)

---------------------------------------------------------------------------

by Seldaek at 2011/06/17 05:35:00 -0700

Well yes otherwise you break the interface. Anyway it's merged so @fabpot, anytime :)
Fabien Potencier 14 years ago
parent
commit
1c14010ebf

+ 1 - 0
src/Symfony/Bridge/Monolog/Handler/DebugHandler.php

@@ -34,6 +34,7 @@ class DebugHandler extends TestHandler implements DebugLoggerInterface
                 'message' => $record['message'],
                 'priority' => $record['level'],
                 'priorityName' => $record['level_name'],
+                'context' => $record['context'],
             );
         }
 

+ 6 - 0
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig

@@ -32,6 +32,12 @@
             {% for log in collector.logs %}
                 <li class="{{ cycle(['odd', 'even'], loop.index) }}{% if 'ERR' == log.priorityName or 'ERROR' == log.priorityName %} error{% endif %}">
                     {{ log.message }}
+                    {% if log.context is defined and log.context is not empty %}
+                        <br />
+                        <small>
+                            <strong>Context</strong>: {{ log.context|yaml_encode }}
+                        </small>
+                    {% endif %}
                 </li>
             {% endfor %}
         </ul>

+ 1 - 0
src/Symfony/Component/HttpKernel/Log/DebugLoggerInterface.php

@@ -23,6 +23,7 @@ interface DebugLoggerInterface
      *
      * A log is an array with the following mandatory keys:
      * timestamp, message, priority, and priorityName.
+     * It can also have an optionnal context key containing an array.
      *
      * @return array An array of logs
      */

+ 8 - 8
src/Symfony/Component/HttpKernel/Log/LoggerInterface.php

@@ -18,19 +18,19 @@ namespace Symfony\Component\HttpKernel\Log;
  */
 interface LoggerInterface
 {
-    function emerg($message);
+    function emerg($message, array $context = array());
 
-    function alert($message);
+    function alert($message, array $context = array());
 
-    function crit($message);
+    function crit($message, array $context = array());
 
-    function err($message);
+    function err($message, array $context = array());
 
-    function warn($message);
+    function warn($message, array $context = array());
 
-    function notice($message);
+    function notice($message, array $context = array());
 
-    function info($message);
+    function info($message, array $context = array());
 
-    function debug($message);
+    function debug($message, array $context = array());
 }

+ 8 - 8
src/Symfony/Component/HttpKernel/Log/NullLogger.php

@@ -20,19 +20,19 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface;
  */
 class NullLogger implements LoggerInterface
 {
-    public function emerg($message) {}
+    public function emerg($message, array $context = array()) {}
 
-    public function alert($message) {}
+    public function alert($message, array $context = array()) {}
 
-    public function crit($message) {}
+    public function crit($message, array $context = array()) {}
 
-    public function err($message) {}
+    public function err($message, array $context = array()) {}
 
-    public function warn($message) {}
+    public function warn($message, array $context = array()) {}
 
-    public function notice($message) {}
+    public function notice($message, array $context = array()) {}
 
-    public function info($message) {}
+    public function info($message, array $context = array()) {}
 
-    public function debug($message) {}
+    public function debug($message, array $context = array()) {}
 }

+ 8 - 8
tests/Symfony/Tests/Component/HttpKernel/Logger.php

@@ -46,42 +46,42 @@ class Logger implements LoggerInterface
         $this->logs[$priority][] = $message;
     }
 
-    public function emerg($message)
+    public function emerg($message, array $context = array())
     {
         $this->log($message, 'emerg');
     }
 
-    public function alert($message)
+    public function alert($message, array $context = array())
     {
         $this->log($message, 'alert');
     }
 
-    public function crit($message)
+    public function crit($message, array $context = array())
     {
         $this->log($message, 'crit');
     }
 
-    public function err($message)
+    public function err($message, array $context = array())
     {
         $this->log($message, 'err');
     }
 
-    public function warn($message)
+    public function warn($message, array $context = array())
     {
         $this->log($message, 'warn');
     }
 
-    public function notice($message)
+    public function notice($message, array $context = array())
     {
         $this->log($message, 'notice');
     }
 
-    public function info($message)
+    public function info($message, array $context = array())
     {
         $this->log($message, 'info');
     }
 
-    public function debug($message)
+    public function debug($message, array $context = array())
     {
         $this->log($message, 'debug');
     }