Logging

Thomas Passin list1 at tompassin.net
Sat Nov 19 18:26:25 EST 2022


On 11/19/2022 5:27 PM, Cameron Simpson wrote:
> On 19Nov2022 11:08, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>> <baran200167 at gmail.com> writes:
>>> You are expected to implement logging feature to an existing
>>> code which uses the function below. [...]
>>> You are not allowed to make changes in my_ugly_debug, so find another 
>>> way.
>>
>>  If found a solution that is even more ugly than your
>>  function. I was just about to post it here, but then
>>  remembered about the "no homework" rule. Bummer!
> 
> I suspect that the OP is just being asked to modify existing code which 
> calls my_ugly_debug to use more conventional logging calls.
> 
> Baran, in addition to the various info(), warning() etc logging calls 
> there is a log() logging call which accepts a log level (the warning() 
> etc calls basicly call this with their own logging level).
> 
> I would be inclined to write a my_better_debug(s,level=0) function which 
> took those existing levels (0,1,2) and mapped them to the official 
> logging levels logging.INFO, logging.WARNING etc, and then called 
> logging.log() with the official level.
> 
> Then adjust the calling code to call your new function.
> 
> The alternative is to just replace every calling function which uses 
> my_ugly_debug() to directly call a logging.whatever() call.

Maybe a place for a decorator...


> Cheers,
> Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list