[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread Lluís

New submission from Lluís llpam...@pamies.cat:

One of the problems with the logging library is that it can affect code 
performance when logging calls are over-utilized.

One possible solution would be to allow the compiler to remove logging calls 
when code is optimized with python -O by wrapping log calls with an assert:

   assert logging.debug(This is a test.)

Note that now debug(), info(), etc in the logging module always return None 
and this is not possible. An enhancement would be to make all logging calls to 
return True. In normal conditions messages would be logged without raising any 
error, but in optimized code they would never be called.

It is really easy to implement and I would be pleased to provide a patch for 
this, but I want to receive feedback from python core developers.

Thanks…

--
components: Library (Lib)
messages: 161251
nosy: Lluís
priority: normal
severity: normal
status: open
title: Allow log calls to return True for code optimization.
type: enhancement
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread Serhiy Storchaka

Serhiy Storchaka storch...@gmail.com added the comment:

assert logging.debug(This is a test.) or True

--
nosy: +storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread Lluís

Lluís llpam...@pamies.cat added the comment:

storchaka, you're right, but since non of the debug(), info() etc. functions 
have a return value, it would cause no trouble and would be neater to add a 
return True. I'm not sure, but probably also more efficient.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

I would also, however, not be a typical Python coding pattern.  Functions 
normally return None by default.  The 'assertor True' pattern makes it 
reasonably clear what the intent is, which just having logging return True 
would not, particularly.  As for efficiency, since your are using the assert to 
improve the efficiency in -O case, the efficiency in the non -O case becomes 
less important.

I'm -1 on this suggestion (given that there is an easy way to spell what you 
want to do).  But we can let Vinay decide :)

There is also another way to spell it, by the way:

   if __debug__: 
   logger.debug('log it')

That is even clearer as to intent.  In fact, I'd be inclined to call that 
TWOWTDI (The One Obvious Way To Do It).

--
nosy: +r.david.murray, vinay.sajip

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread Lluís

Lluís llpam...@pamies.cat added the comment:

David, the problem is that if you have the logging inside a loop, the 
interpreter will have to evaluate the condition every time. With an assert you 
guarantee that *no code* is executed.

I know that we can find thousands of ways to do that, even writing a dynamic 
proxy for the Logger, and wrap the debug(), error() calls and return True, etc.

My is not telling developers to write assert logger.debug('aa') every time 
that they want to log something, but instead giving them the option to do that 
and be sure that *no code* is executed. Specially, because the return value of 
log functions is not used at all.

Thanks for the responses.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

I was definitely wrong about the obvious part, then.  The 'if __debug__:' 
idiom is completely optimized away by -O, just like asserts are.  That is, in 
-O mode, there is no if test, the code block is just omitted entirely.

Having said that, though, I can't find it documented other than by the implicit 
equivalence given in the assert docs.

Hmm.  Yes, it does seem to be a CPython implementation detail.  See issue 8379. 
 Assert being removed is also an implementation detail, though (see the 
reference to the current code generator... in the assert docs).  I suppose 
that '-O' itself is a CPython implementation detail, in a sense :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14868] Allow log calls to return True for code optimization.

2012-05-21 Thread Lluís

Lluís llpam...@pamies.cat added the comment:

Thanks for the explanation, I didn't know of the exact behavior of __debug__.

I close ticket.

--
resolution:  - works for me
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com