MedCAT
MedCAT copied to clipboard
CU-2vzhd93 Logging improvements
As I understand, some users of MedCAT have raised an issue with logging.
The previous logging behaviour was removed in #242. And for good reason. The library should leave the choice of how, when, and where to log information up to the user.
However, there are a few things we can do to make things easier for those users who wish to use the previous behaviour. And we can provide guidance on how to further customise the behaviour of the loggers within the project.
The above is the main aim of this current PR. In addition to the above, there were a few side objectives
- Move everything to a logger based output (instead of using
print
) - Make the logging more consistent (each module has its own logger)
Previously, some of the loggers used within the project were package-level loggers. They've now all been converted to module level ones. Each module has its own logger (the log
class attributes now refer to this module level logger where they were previously present). This allows for the user to fine-tune their logging to their preference (i.e use different handlers and/or level for different modules).
There is now a module level function that allows a user to recreate the previous default behaviour (i.e logging to console as well as medcat.log
). That is the medcat.add_default_log_handlers
function. It can be used with no arguments to add the functionality to the package level logger. Or, a logger and/or target log file can be provided if needed.
I have also added a section the the README regarding the logging situation. It refers the users to the MedCATtutorials. However, since the logging changes have not been released, the actual tutorial is currently in the tutorials
folder.
I have removed almost all of the print
calls from the project. Some of this may be overkill (especially in the utils
package). The only parts I left were in the cat_print_stats
method (this has its own ClickUp task anyway) as well as the modules in utils/deprecated
.
I also moved the f-strings to lazy formatting wherever I felt that was appropriate.
PS:
Any comments and suggestions are welcome. I am not entirely sure that all the changes to the print
calls are fully warranted. But since I didn't know the exact use cases for each parts, I dealt with everything in the same manner.
I'd even go to say as much as Class level logging instances aren't needed also, I see the dotted around but I don't think they offer anything over the package level logger instance, especially as for the most part they are assigned the package level ref anyways.
I agree, they shouldn't really be needed. But I left them in for backwards compatibility. If someone is using these for something, they can continue to do so.
I just wasn't confident enough that they wouldn't be used by someone, somewhere.
But if you're confident that we can simply remove those class-level references, I'd be more than happy to remove them.
Yeah I think you're safe to remove