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
{{ message }}
Repository navigation
Relax constraint on logger class in register_loggerΒ #4783
Allow any logger instance to be registered via register_logger, as long as it has info and warning methods defined.
Motivation
Currently only instance of logging.Logger or its subclass can be registered. I'd like to use logger from loguru, which is more convenient, however it will trigger TypeError now. Since only info and warning are used to log messages, any logger class providing these two methods would suffice.
Description
Instead of checking the class of logger, just check the existence of info and warning method.
Reference implementation:
defregister_logger(logger) ->None:
def_has_method(method):
returncallable(getattr(logger, method, None))
ifnot_has_method("info") ornot_has_method("warning"):
raiseTypeError("Logger must provide 'info' and 'warning' method")
global_LOGGER_LOGGER=logger
@RustingSword are you interested in contributing this? If you are and if other Python maintainers I've tagged support the idea, I'd be happy to answer any questions you have about the contribution process.
This issue has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.
Activity
jameslamb commentedon Dec 4, 2021
Thanks very much for the excellent feature request, and sorry for the delayed response. I totally support this relaxed constraint.
@StrikerRUS @jmoralez what do you think?
@RustingSword are you interested in contributing this? If you are and if other Python maintainers I've tagged support the idea, I'd be happy to answer any questions you have about the contribution process.
RustingSword commentedon Dec 4, 2021
Sure, happy to contribute :)
StrikerRUS commentedon Dec 4, 2021
I support the idea of allowing to register custom advanced logger classes.
Also, I think that for the forward compatibility we should ask custom class to provide
error()method, even though we are not using it right now.github-actions commentedon Aug 15, 2023
This issue has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.