LOG4PHP-180: Removed $_ENV and $_SERVER access from LoggerMDC
authorIvan Habunek <ihabunek@apache.org>
Tue, 29 May 2012 09:46:39 +0000 (09:46 +0000)
committerIvan Habunek <ihabunek@apache.org>
Tue, 29 May 2012 09:46:39 +0000 (09:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/logging/log4php/trunk@1343630 13f79535-47bb-0310-9956-ffa450edef68

src/changes/changes.xml
src/main/php/LoggerMDC.php
src/site/xdoc/changelog.xml
src/test/php/LoggerMDCTest.php

index 369d30f..396d85d 100644 (file)
@@ -21,6 +21,7 @@
        </properties>
        <body>
                <release version="2.3.0" date="SVN">
+                       <action date="2011-05-29" type="update" dev="Ivan Habunek">Removed $_ENV and $_SERVER access from LoggerMDC.</action>
                    <action date="2011-03-19" type="update" dev="Ivan Habunek">Made LoggerLayoutTTCC deprecated.</action>
                        <action date="2011-02-28" type="fix" issue="LOG4PHP-163" dev="Ivan Habunek">Fixed formatting bug in LoggerLayoutPattern.</action>
                        <action date="2011-02-28" type="update" issue="LOG4PHP-172" dev="Ivan Habunek">Rewritten pattern system to allow longer conversion words and some new ones.</action>
index a9c717d..05bb549 100644 (file)
  */
 
 /**
- * The LoggerMDC class provides <i>mapped diagnostic contexts</i>.
+ * The LoggerMDC class provides _mapped diagnostic contexts_.
  * 
- * A <i>Mapped Diagnostic Context</i>, or
- * MDC in short, is an instrument for distinguishing interleaved log
- * output from different sources. Log output is typically interleaved
- * when a server handles multiple clients near-simultaneously.
+ * A Mapped Diagnostic Context, or MDC in short, is an instrument for 
+ * distinguishing interleaved log output from different sources. Log output 
+ * is typically interleaved when a server handles multiple clients 
+ * near-simultaneously.
  * 
  * This class is similar to the {@link LoggerNDC} class except that 
  * it is based on a map instead of a stack.
  * 
- * Example:
- * 
- * {@example ../../examples/php/mdc.php 19}<br>
- *
- * With the properties file:
- * 
- * {@example ../../examples/resources/mdc.properties 18}<br>
- * 
- * Will result in the following (notice the username "knut" in the output):
- * 
- * <pre>
- * 2009-09-13 18:48:28 DEBUG root knut: Testing MDC in src/examples/php/mdc.php at 23
- * </pre>
- * 
  * @version $Revision$
  * @since 0.3
  * @package log4php
@@ -66,28 +52,12 @@ class LoggerMDC {
        /**
         * Returns the context value identified by the key parameter.
         *
-        * Special key identifiers can be used to map values in the global $_SERVER
-        * and $_ENV vars. To access them, use 'server.' or 'env.' followed by the 
-        * desired var name as the key.
-        *
         * @param string $key The key.
         * @return string The context or an empty string if no context found
         *      for given key.
         */
        public static function get($key) {
-               if(!empty($key)) {
-                       if(strpos($key, 'server.') === 0) {
-                               $varName = substr($key, 7);
-                               return isset($_SERVER[$varName]) ? $_SERVER[$varName] : '';
-                       } else if(strpos($key, 'env.') === 0) {
-                               $varName = substr($key, 4);
-                               $value = getenv($varName);
-                               return ($value !== false) ? $value : '';
-                       } else {
-                               return isset(self::$map[$key]) ? self::$map[$key] : '';
-                       }
-               }
-               return '';
+               return isset(self::$map[$key]) ? self::$map[$key] : '';
        }
 
        /**
index fe9adf2..07d21da 100644 (file)
                                \r
                                <p><strong>New features:</strong></p>\r
                                <ul>\r
-                                       <li>New appender: <a href="docs/appenders/fire-php.html">FirePHP</a> (thanks to Bruce Ingalls)</li>\r
+                                       <li>New appender: <a href="docs/appenders/firephp.html">FirePHP</a> (thanks to Bruce Ingalls)</li>\r
                                </ul>\r
                                \r
                                <p><strong>Improvements:</strong></p>\r
                                <ul>\r
                                        <li>The <a href="docs/layouts/pattern.html">pattern layout</a> has been greatly improved:\r
                                                <ul>\r
-                                                       <li>supports longer conversion words such as <em>%date</em> instead of <em>%d</em>, \r
-                                                               <em>%message</em> instead of <em>%m</em>, etc.</li>\r
+                                                       <li>supports longer conversion words such as <code>%date</code> instead of <code>%d</code>, \r
+                                                               <code>%message</code> instead of <code>%m</code>, etc.</li>\r
                                                        <li>added many new conversion words; check out the docs for the full list</li>\r
                                                </ul>\r
                                        </li>\r
                                \r
                                <p><strong>Breaking changes:</strong></p>\r
                                <ul>\r
-                                       <li>Several changes to <a href="docs/appenders/pdo.html">LoggerAppenderPDO</a>:\r
+                                       <li>Several changes to the <a href="docs/appenders/pdo.html">PDO appender</a>:\r
                                                <ul>\r
                                                        <li>a database table for logging will no longer be created by the appender; the user must \r
                                                                create this table manually.</li>\r
                                                        <li>the default date pattern does not include milliseconds (this is faster)</li>\r
                                                </ul>\r
                                        </li>\r
+                                       <li>In the <a href="docs/layouts/pattern.html">pattern layout</a>, it is no longer possible to \r
+                                               access $_SERVER and $_ENV values using <code>%X{server.*}</code> and <code>%X{env.*}</code>\r
+                                               conversion words; use the new words <code>%server{*}</code> and <code>%env{*}</code> instead.\r
+                                               </li>\r
                                </ul>\r
                                <p>Please review the documentation and make any necessary changes to your configuration.</p>\r
                                \r
index e691371..39f40fc 100644 (file)
@@ -43,15 +43,6 @@ class LoggerMDCTest extends PHPUnit_Framework_TestCase {
        /** A pattern without a key. */\r
        private $pattern5 = "%-5p %c: %X %m";\r
        \r
-       /** A pattern for testing values from $_ENV. */\r
-       private $patternEnv = "%-5p %c: %X{env.TEST} %m";\r
-       \r
-       /**\r
-        * A pattern for testing values from $_SERVER. PHP_SELF chosen because it\r
-        * appears on both Linux and Windows systems. \r
-        */\r
-       private $patternServer = "%-5p %c: %X{server.PHP_SELF} %m";\r
-       \r
        protected function setUp() {\r
                LoggerMDC::clear();\r
        }\r
@@ -114,48 +105,6 @@ class LoggerMDCTest extends PHPUnit_Framework_TestCase {
                self::assertEquals($expected, $actual);\r
     }\r
     \r
-    public function testEnvKey() {\r
-       \r
-       // Set an environment variable for testing\r
-       if (putenv('TEST=abc') === false) {\r
-               self::markTestSkipped("Unable to set environment variable for testing.");\r
-       }\r
-       \r
-       // Test reading of the set variable\r
-       self::assertEquals('abc', LoggerMDC::get('env.TEST'));\r
-       \r
-       // Test env variable in a pattern\r
-       $event = LoggerTestHelper::getInfoEvent("Test message");\r
-       $actual = $this->formatEvent($event, $this->patternEnv);\r
-               $expected = "INFO  test: abc Test message";\r
-               self::assertEquals($expected, $actual);\r
-               \r
-               // Test reading a non-existant env variable\r
-               self::assertEquals('', LoggerMDC::get('env.hopefully_this_variable_doesnt_exist'));\r
-               \r
-               // Test reading an empty env variable\r
-               self::assertEquals('', LoggerMDC::get('env.'));\r
-    }\r
-    \r
-    public function testServerKey() {\r
-       \r
-       // Test reading a server variable\r
-       $value = $_SERVER['PHP_SELF'];\r
-       self::assertEquals($value, LoggerMDC::get('server.PHP_SELF'));\r
-       \r
-               // Test the server variable in a pattern\r
-       $event = LoggerTestHelper::getInfoEvent("Test message");\r
-       $actual = $this->formatEvent($event, $this->patternServer);\r
-               $expected = "INFO  test: $value Test message";\r
-               self::assertEquals($expected, $actual);\r
-               \r
-               // Test reading a non-existant server variable\r
-               self::assertEquals('', LoggerMDC::get('server.hopefully_this_variable_doesnt_exist'));\r
-               \r
-               // Test reading an empty server variable\r
-               self::assertEquals('', LoggerMDC::get('server.'));\r
-    }\r
-    \r
        private function formatEvent($event, $pattern) {\r
                $layout = new LoggerLayoutPattern();\r
                $layout->setConversionPattern($pattern);\r