You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For now, multiple output-related things exist in VIP:
verbose parameter to functions
debug parameter to functions
timing information
progress bars.
solution
I propose a new class, Logger, which takes care of these.
Internally, a Logger is defined by a numeric logging level (roughly following the logging levels of the standard library's logging module):
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
and one or multiple boolean tags:
progressbar = True
timing = True.
example
The new Logger class can be used as follows:
fromxyzimportLogger@Logger.timing()defandromeda(datacube=None, verbose=False):
logger=Logger("andromeda", verbose)
ifdatacubeisNone:
logger.warn("The datacube is not set, that is maybe not what you want!")
foriinProgressbar(range(1000), verbose=logger):
logger.debug("loop #{}...".format(i))
# ...logger.info("done.")
These set level=20, progressbar=True, timing=True.
It will show the timing information, the progressbar, and the output of info and warn with the string "andromeda: " prefixed.
if I want to disable the timing information, e.g. when I run andromeda inside a loop, I can add -timing to the verbose parameter: andromeda(verbose="info-timing") .
→ level=20, progressbar=True, timing=False
if I want to disable the output, I use andromeda(verbose=False) or andromeda(verbose='error').
It sets internally level=40, progressbar=False, timing=False.
if I want just the progressbar, I can enable it separately using +progressbar: andromeda(verbose='error+progressbar')
→ level=40, progressbar=True, timing=False
notes
The Progressbar class would check if the progressbar=True is set inside the Logger object it gets. The @Logger.timing() decorator does the same for the timing tag.
The Logger objects are entirely backwards-compatible to functions which expect a boolean as their verbose parameter, as they behave like a boolean when using e.g. if logger:. So there is no need to change anything existing.
I have the Logger class already coded, except for the @Logger.timing. I'll add that shortly, so we can try it out.
What do you think?
The text was updated successfully, but these errors were encountered:
problem
For now, multiple output-related things exist in VIP:
verbose
parameter to functionsdebug
parameter to functionssolution
I propose a new class,
Logger
, which takes care of these.Internally, a
Logger
is defined by a numeric logging level (roughly following the logging levels of the standard library'slogging
module):and one or multiple boolean tags:
progressbar = True
timing = True
.example
The new
Logger
class can be used as follows:I can then call
andromeda
like so:andromeda(verbose=True)
/andromeda(verbose="info")
level=20
,progressbar=True
,timing=True
.info
andwarn
with the string"andromeda: "
prefixed.andromeda
inside a loop, I can add-timing
to theverbose
parameter:andromeda(verbose="info-timing")
.level=20
,progressbar=True
,timing=False
andromeda(verbose=False)
orandromeda(verbose='error')
.level=40
,progressbar=False
,timing=False
.+progressbar
:andromeda(verbose='error+progressbar')
level=40
,progressbar=True
,timing=False
notes
The
Progressbar
class would check if theprogressbar=True
is set inside theLogger
object it gets. The@Logger.timing()
decorator does the same for thetiming
tag.The
Logger
objects are entirely backwards-compatible to functions which expect a boolean as theirverbose
parameter, as they behave like a boolean when using e.g.if logger:
. So there is no need to change anything existing.I have the
Logger
class already coded, except for the@Logger.timing
. I'll add that shortly, so we can try it out.What do you think?
The text was updated successfully, but these errors were encountered: