Ortho4XP
Ortho4XP copied to clipboard
TECH DEBT | Follow pythons best practices for logging and error/exception handling.
- replace all "print" commands and equal practices
- do not just catch exceptions, log them correctly including the stacktrace
By these two measures it will be much easier to find bugs in the future.
What would be the ideal logging config for this project?
Most of the current logging and verbosity control is in src\O4_UI_Utils.py. The approach uses min_verbosity for deciding what to print and logs directly to a file within logprint.
def vprint(min_verbosity, *args):
if verbosity >= min_verbosity:
print(*args)
def logprint(*args):
try:
f = open(os.path.join(Ortho4XP_dir, "Ortho4XP.log"), "a")
f.write(
time.strftime("%c")
+ " | "
+ " ".join([str(x) for x in args])
+ "\n"
)
f.close()
except:
pass
We could start by wrapping the existing print and manual file logging statements in vprint, logprint, and lvprint with a proper logger setup.
Somethig that looks like this
setup_logging()
logger = get_logger(__name__)
def logprint(*args):
message = " | ".join(str(arg) for arg in args) # not really required
logger.info(message)
Moving away from numerical to logging levels (DEBUG, INFO, etc.) could make the application more intuitive. Now, even with descriptions, it can be confusing for end users.
I started utilizing logger in #269. Very early stages but I needed it as I was working on the application anyways. I'm hoping we can continue to incorporate logger for all the reasons mentioned.