You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by "Christian Hammers (JIRA)" <ji...@apache.org> on 2012/05/25 17:04:22 UTC

[jira] [Created] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Christian Hammers created LOG4PHP-178:
-----------------------------------------

             Summary: Avoid usage errors by adding Type Hints
                 Key: LOG4PHP-178
                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
             Project: Log4php
          Issue Type: Improvement
    Affects Versions: 2.2.1
            Reporter: Christian Hammers
            Priority: Minor


It's tempting to write:
        $this->log = Logger::getRootLogger();
        $this->log->setLevel(LoggerLevel::WARN);

which at first succeedes but throws an exception when first using this Logger.
It would be more obvious to the user when he gets an immediate compiler error due to type hints.

--- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
+++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
@@ -376,9 +376,11 @@                                                                                                                                        
        /**                                                                                                                                                 
         * Set the Logger level.
         *
+        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
+        *
         * @param LoggerLevel $level the level to set
         */
-       public function setLevel($level) {
+       public function setLevel(LoggerLevel $level) {
                $this->level = $level;
        }
 


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ivan Habunek closed LOG4PHP-178.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.3.0
    
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Assignee: Ivan Habunek
>            Priority: Minor
>              Labels: patch
>             Fix For: 2.3.0
>
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13283967#comment-13283967 ] 

Ivan Habunek commented on LOG4PHP-178:
--------------------------------------

Leave the issue open for a bit longer, this broke some tests. I have to fix them. :)
                
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Priority: Minor
>              Labels: patch
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13284362#comment-13284362 ] 

Ivan Habunek commented on LOG4PHP-178:
--------------------------------------

Well, that works as well. :)
I have comitted the changes.
                
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Assignee: Ivan Habunek
>            Priority: Minor
>              Labels: patch
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Vladimir Gorej (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13284336#comment-13284336 ] 

Vladimir Gorej commented on LOG4PHP-178:
----------------------------------------

You can overcome this problem by defining the signature of the method as follows:

public function setLevel(LoggerLevel $level = null)

This way, seLevel method can only accept LoggerLevel instance or null
                
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Assignee: Ivan Habunek
>            Priority: Minor
>              Labels: patch
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13284331#comment-13284331 ] 

Ivan Habunek commented on LOG4PHP-178:
--------------------------------------

It seems this was not a good change. 

After reviewing the code, I remembered that Logger level can be set to null. This means that it inherits the parent's level. Of course, the root logger's level must not be set to null.

When we added the type hint, we removed the possibility of doing:
$logger->setLevel(null);

Therefore, I suggest that we revert this change, and add some code which will check that the provided object is indeed LoggerLevel. Also we can allow usage of level constants (LoggerLevel::WARN, etc.). This might make things a bit easier for the developer.

Regards,
Ivan
                
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Assignee: Ivan Habunek
>            Priority: Minor
>              Labels: patch
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Florian Semm (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13283965#comment-13283965 ] 

Florian Semm commented on LOG4PHP-178:
--------------------------------------

done. 

Ivan has commited your changes
                
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Priority: Minor
>              Labels: patch
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (LOG4PHP-178) Avoid usage errors by adding Type Hints

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-178?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ivan Habunek reassigned LOG4PHP-178:
------------------------------------

    Assignee: Ivan Habunek
    
> Avoid usage errors by adding Type Hints
> ---------------------------------------
>
>                 Key: LOG4PHP-178
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-178
>             Project: Log4php
>          Issue Type: Improvement
>    Affects Versions: 2.2.1
>            Reporter: Christian Hammers
>            Assignee: Ivan Habunek
>            Priority: Minor
>              Labels: patch
>
> It's tempting to write:
>         $this->log = Logger::getRootLogger();
>         $this->log->setLevel(LoggerLevel::WARN);
> which at first succeedes but throws an exception when first using this Logger.
> It would be more obvious to the user when he gets an immediate compiler error due to type hints.
> --- Logger.php.orig     2012-05-25 16:55:35.000000000 +0200                                                                                                 
> +++ Logger.php  2012-05-25 17:02:04.000000000 +0200                                                                                                         
> @@ -376,9 +376,11 @@                                                                                                                                        
>         /**                                                                                                                                                 
>          * Set the Logger level.
>          *
> +        * Use LoggerLevel::getLevelWarn() etc. to get a LoggerLevel object.
> +        *
>          * @param LoggerLevel $level the level to set
>          */
> -       public function setLevel($level) {
> +       public function setLevel(LoggerLevel $level) {
>                 $this->level = $level;
>         }
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira