-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove log handler from PSClient #470
Comments
Hi @SirSkaro, |
Thank you! I think the pain point of the workaround really depends on how the agent is constructed and how you want to unregister the handler. If you're just constructing a
And you'd need to do this for every My workaround is a little more painful. I'm using the Dependency Injector library to setup an IoC container for dependency injection. The first thing my |
One thing I did that you may be interested in is that I created a configurable filter to not log specified Showdown events. You pass in a comma-separated list of events to the filter, add the filter to the class ShowdownEventFilter(logging.Filter):
def __init__(self, events_to_ignore: List[str] = []):
super().__init__()
regex = '|'.join(events_to_ignore)
self._record_regex = re.compile(f'\\|{regex}\\|')
def filter(self, record: logging.LogRecord) -> bool:
if record.levelno >= logging.WARN:
return True
log_message = record.getMessage()
return self._record_regex.search(log_message) is None Then player = Player(...)
log_ignore = get_ignore_list_from_configs() # e.g., ['request', 'updatesearch']
player.logger.addFilter(ShowdownEventFilter(log_ignore)) |
I'm creating an application where I register my own handler for root. However, I noticed that
PSClient
registers its own handler with a logger by the name of the logged-in user. Because the way the logging hierarchy works, thePSClient
's log messages (and thus thePlayer
's log messages) are getting logged twice. As a result, I'm having to manually remove the handler when I create thePlayer
object.It's my understanding that it's best practice to not have distributed packages declare their own handlers (or at least check if they are main before doing so). In my opinion, I think it would be best to either remove the handler or at least check that there aren't any other handlers registered at the root.
I'm admittedly not the most well-versed with
logging
in Python (most of my work in it has been academic), so please let me know if there is a better way to silence these duplicate log messages.The text was updated successfully, but these errors were encountered: