[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r1297676 - /subversion/trunk/subversion/tests/cmdline/svntest/main.py

From: Hyrum K Wright <hyrum.wright_at_wandisco.com>
Date: Tue, 6 Mar 2012 14:58:44 -0600

On Tue, Mar 6, 2012 at 2:42 PM, Greg Stein <gstein_at_gmail.com> wrote:
> On Tue, Mar 6, 2012 at 15:18,  <hwright_at_apache.org> wrote:
>>...
>> +++ subversion/trunk/subversion/tests/cmdline/svntest/main.py Tue Mar  6 20:18:16 2012
>>...
>> @@ -78,6 +79,10 @@ SVN_VER_MINOR = 8
>>
>>  default_num_threads = 5
>>
>> +# Set up logging
>> +logger = logging.getLogger(__name__)
>
> You may as well use the default logger. That way, every module can
> just: import logging ; logging.info('whatever: %s %s', foo, bar)

I thought about that, but figured using the custom logger would give
us more flexibility. Separate test suites could use separate loggers
when run in parallel, for instance, and they wouldn't interleave each.
 By establishing the habit of using a named logger, rather than the
default one, it means we can just change the logger reference, instead
of go back and rewrite everything to use a custom logger later.

This first pass is to just get as much as possible using the logging
framework, and then we can go back and worry about such things. I
just don't want us to prematurely optimize. :)

>>...
>> @@ -1473,6 +1469,9 @@ def create_default_options():
>>
>>  def _create_parser():
>>   """Return a parser for our test suite."""
>> +  def set_log_debug(option, opt, value, parser):
>> +    logger.setLevel(logging.DEBUG)
>
> axe this, see below:
>
>> +
>>   # set up the parser
>>   _default_http_library = 'serf'
>>   usage = 'usage: %prog [options] [<test> ...]'
>> @@ -1481,7 +1480,8 @@ def _create_parser():
>>                     help='Print test doc strings instead of running them')
>>   parser.add_option('--milestone-filter', action='store', dest='milestone_filter',
>>                     help='Limit --list to those with target milestone specified')
>> -  parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
>> +  parser.add_option('-v', '--verbose', action='callback',
>> +                    callback=set_log_debug,
>>                     help='Print binary command-lines (not with --quiet)')
>
> callback=logger.setLevel, callback_args=(logging.DEBUG,)

Mentioned this on IRC, but:
TypeError: setLevel() takes exactly 2 arguments (6 given)

Essentially, the optparser provides a number of extra arguments that
setLevel() doesn't expect (or use).

>>...
>
> You may want to change most of the calls to logging.FOO rather than
> logger.FOO for consistency with other modules that will use the
> logging framework.
>
> I would also recommend creating a Formatter and attaching it to that
> StreamHandler:
>
>    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s',
>                                  '%Y-%m-%d %H:%M:%S')
>    handler.setFormatter(formatter)
>
> that will give us a timestamp for each line.

Future Work. A valuable suggestion, but right now I'm focused on
getting the logging infrastructure in place, so we can make this kind
of changes on a system-wide basis.

-Hyrum

-- 
uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com/
Received on 2012-03-06 21:59:16 CET

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.