Bug 35484 - check-webkit-style: Start using Python's logging module
Summary: check-webkit-style: Start using Python's logging module
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Chris Jerdonek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-27 13:33 PST by Chris Jerdonek
Modified: 2010-03-02 08:50 PST (History)
6 users (show)

See Also:


Attachments
Proposed patch (14.11 KB, patch)
2010-02-27 15:41 PST, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch 2 (14.10 KB, patch)
2010-02-27 15:48 PST, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch 3 (19.53 KB, patch)
2010-02-27 20:44 PST, Chris Jerdonek
hamaji: review-
Details | Formatted Diff | Diff
Proposed patch (19.65 KB, patch)
2010-03-02 00:18 PST, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch 5 (19.62 KB, patch)
2010-03-02 00:22 PST, Chris Jerdonek
no flags Details | Formatted Diff | Diff
Proposed patch 6 (20.01 KB, patch)
2010-03-02 07:52 PST, Chris Jerdonek
hamaji: review+
cjerdonek: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Jerdonek 2010-02-27 13:33:10 PST
Start using the logging module in check-webkit-style.

Also provide an example of how to unit test logging when using the logging module.
Comment 1 Chris Jerdonek 2010-02-27 15:41:19 PST
Created attachment 49687 [details]
Proposed patch
Comment 2 Chris Jerdonek 2010-02-27 15:48:26 PST
Created attachment 49688 [details]
Proposed patch 2

Removed the trailing newline from two logging calls since the logging module appends a newline automatically.
Comment 3 Chris Jerdonek 2010-02-27 20:44:40 PST
Created attachment 49691 [details]
Proposed patch 3

Refactored the patch so that the supporting unit test code is in a central location.

In a later patch, I can rename the webkitpy/init directory to something like webkitpy/infra to signify that it contains infrastructure-related code (autoinstall, logging, etc).
Comment 4 Shinichiro Hamaji 2010-03-01 00:10:29 PST
Comment on attachment 49691 [details]
Proposed patch 3

Generally looks great. r- for now, but some of my comments would be wrong.

> diff --git a/WebKitTools/Scripts/webkitpy/init/wklogging.py b/WebKitTools/Scripts/webkitpy/init/wklogging.py

Are you planning to put non-unittest code into this module? If not, I think the name isn't the best. Maybe logging_test_utils.py or something more verbose naming would be better.

If you are planning to add non-unittest code, I'd suggest splitting this file into two files.

> +"""Support for logging."""

It would be better to say this module supports testing of logging.

> +    This method returns a list of references to the logging handlers
> +    added so that the caller can later remove the handlers using
> +    logger.removeHandler.  This is primarily useful in testing
> +    situations where the caller may want to enable logging temporarily
> +    and then undo the enabling.

I'm not sure if this style is widely used, but I prefer the following style

  Returns:
    a list of references to the logging handlers...

cpp.py has bunch of docstrings with this style.

Will we return more than two handlers? If not, I think we can return tuple and explicitly say "this function returns an error-handler and a non-error-handler using tuple".

> +    def test_info_message(self):
> +        # We test the tighter boundary case rather than logging.INFO,
> +        # which equals 30.

Hmm... I'm confused. It seems logging.INFO is 20. I'm not sure, but if I understand the logging module correctly, logging.INFO should be outputted but logging.INFO-1 should not, right? If so, I think logging.INFO is the boundary. Maybe I'm misunderstanding?
Comment 5 Chris Jerdonek 2010-03-01 22:36:20 PST
(In reply to comment #4)
> (From update of attachment 49691 [details])

Thanks a lot for the helpful comments.

> Are you planning to put non-unittest code into this module? If not, I think the
> name isn't the best. Maybe logging_test_utils.py or something more verbose
> naming would be better.
> 
> If you are planning to add non-unittest code, I'd suggest splitting this file
> into two files.

I was planning to put non-unittest code in the file.  Good idea.  I will rename.

I may choose something a bit shorter though since PEP8 encourages short module names.

> Will we return more than two handlers? If not, I think we can return tuple and
> explicitly say "this function returns an error-handler and a non-error-handler
> using tuple".

For now, just two.  But I would prefer to keep it a list since the calling code only needs to loop through it.  It does not need to know its contents or use the sequence in a structured way as a tuple would imply.

> > +    def test_info_message(self):
> > +        # We test the tighter boundary case rather than logging.INFO,
> > +        # which equals 30.
> 
> Hmm... I'm confused. It seems logging.INFO is 20. I'm not sure, but if I
> understand the logging module correctly, logging.INFO should be outputted but
> logging.INFO-1 should not, right? If so, I think logging.INFO is the boundary.
> Maybe I'm misunderstanding?

You're right -- that was a typo (should be 20 rather than 30).  I'm sorry.  I knew about it and failed to correct.

In any case, the configured handlers should style messages with level 30 and above as an error message, and 29 and below as an info message.

The purpose of my comment was to explain why I was testing 29 even though in practice we would only be using 20 (i.e. _log.info).  I will make the comment clearer.
Comment 6 Shinichiro Hamaji 2010-03-01 23:14:29 PST
> I may choose something a bit shorter though since PEP8 encourages short module
> names.

Yeah, I think shorter name is OK. I tend to like verbose names maybe because I'm not good at coming up with cool short names :(

> For now, just two.  But I would prefer to keep it a list since the calling code
> only needs to loop through it.  It does not need to know its contents or use
> the sequence in a structured way as a tuple would imply.

I see. It's OK as is.

> You're right -- that was a typo (should be 20 rather than 30).  I'm sorry.  I
> knew about it and failed to correct.
> 
> In any case, the configured handlers should style messages with level 30 and
> above as an error message, and 29 and below as an info message.
> 
> The purpose of my comment was to explain why I was testing 29 even though in
> practice we would only be using 20 (i.e. _log.info).  I will make the comment
> clearer.

Ah, I was also wrong. I missed you are setting logging.WARNING for your filter in configure_logging. Thanks for clarification!
Comment 7 Chris Jerdonek 2010-03-02 00:18:17 PST
Created attachment 49787 [details]
Proposed patch
Comment 8 Chris Jerdonek 2010-03-02 00:22:18 PST
Created attachment 49788 [details]
Proposed patch 5

Fixed ChangeLog (extraneous reviewed by line).
Comment 9 Chris Jerdonek 2010-03-02 07:52:05 PST
Created attachment 49805 [details]
Proposed patch 6

Added __init__,py back to webkitpy/init directory. 

The __init__.py file was deleted from webkitpy/init when the directory was emptied in a recent rollout:

http://trac.webkit.org/changeset/55363

(Note that we will be renaming webkitpy/init to something like webkitpy/infra in a later patch.)
Comment 10 Shinichiro Hamaji 2010-03-02 08:20:14 PST
Comment on attachment 49805 [details]
Proposed patch 6

Looks good!
Comment 11 Chris Jerdonek 2010-03-02 08:50:22 PST
Committed (via "webkit-patch land-from-bug"):

http://trac.webkit.org/changeset/55409