XayOn / pyrcrack

Python Aircrack-ng bindings
122 stars 30 forks source link

import breaks root Logger #53

Open defkev opened 11 months ago

defkev commented 11 months ago

Nice little module with one major caveat, you are overriding the root logger which will break logging in every app importing your module:

Demo:

import logging
import pyrcrack

#logging.getLogger().handlers.clear()

logging.basicConfig(
    format = '%(asctime)s %(name)s[%(process)s-%(threadName)s] %(levelname)7s: %(message)s',
    level = logging.DEBUG
)
logging.debug("I'm a debug")
logging.warning("I'm a warning")
logging.error("I'm an error")
logging.info("I'm a info")

Output:

WARNING:root:I'm a warning
ERROR:root:I'm an error
INFO:root:I'm a info

Notice a) the debug message is missing and b) the formatter ignored.

The only workaround i can think off is by resetting the (your) root logger:

...

logging.getLogger().handlers.clear()

...

Output:

2023-11-30 04:28:34,563 root[182602-MainThread]   DEBUG: I'm a debug
2023-11-30 04:28:34,563 root[182602-MainThread] WARNING: I'm a warning
2023-11-30 04:28:34,563 root[182602-MainThread]   ERROR: I'm an error
2023-11-30 04:28:34,563 root[182602-MainThread]    INFO: I'm a info
2023-11-30 04:28:34,563 asyncio[182602-MainThread]   DEBUG: Using selector: EpollSelector
2023-11-30 04:28:34,570 AirmonNg[182602-MainThread]   DEBUG: Parsing options: {}
2023-11-30 04:28:34,570 AirmonNg[182602-MainThread]   DEBUG: Got options: []
2023-11-30 04:28:34,570 AirmonNg[182602-MainThread]   DEBUG: Running command: ['airmon-ng']

Which of course also resets your logger.