You are expected to implement logging feature to an existing
code which uses the function below.
def my_ugly_debug(s, level=0):
pre_text = [ "INFO",
"WARNING",
"ERROR"
]
print(f"{pre_text[level]}: {s}")
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!
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!
On 19Nov2022 11:08, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
<baran200167@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.
Cheers,
Cameron Simpson <cs@cskk.id.au>
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...
On 19Nov2022 18:26, Thomas Passin <list1@tompassin.net> wrote:
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...
Indeed, though I don't think the OP is up to decorators yet.
But really, is there any problem which cannot be solved with a
decorator? I've even got a @decorator decorator for my decorators.
On Sun, 20 Nov 2022 at 12:27, Cameron Simpson <cs@cskk.id.au> wrote:
But really, is there any problem which cannot be solved with a
decorator? I've even got a @decorator decorator for my decorators.
Do you have a @toomanydecorators decorator to reduce the number of
decorators you need to decorate your decorators?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 74:51:43 |
Calls: | 6,715 |
Calls today: | 3 |
Files: | 12,246 |
Messages: | 5,357,277 |