Skip to content

Commit

Permalink
Move facedancer logging to a sub-logger of the python root
Browse files Browse the repository at this point in the history
Issue originally reported in greatscottgadgets#51
Initial pull-request in greatscottgadgets#52

Closes greatscottgadgets#51
Closes greatscottgadgets#52
  • Loading branch information
antoinevg authored and kauwua committed Sep 6, 2024
1 parent 3d44ead commit be27c9a
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 165 deletions.
11 changes: 3 additions & 8 deletions facedancer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@

# Alias objects to make them easier to import.
from .backends import *
from .core import FacedancerUSBApp, FacedancerUSBHostApp, FacedancerBasicScheduler
from .devices import default_main as main

# Set up our extra log levels.
import logging
from .constants import LOGLEVEL_TRACE
logging.addLevelName(LOGLEVEL_TRACE, 'TRACE')
from .core import FacedancerUSBApp, FacedancerUSBHostApp, FacedancerBasicScheduler
from .devices import default_main as main

# Wildcard import.
__all__ = [
Expand All @@ -35,5 +30,5 @@
'to_any_endpoint', 'to_this_interface', 'to_any_interface', 'to_other',
'USBDirection', 'USBTransferType', 'USBUsageType', 'USBSynchronizationType',
'USBRequestType', 'USBRequestRecipient', 'USBStandardRequests', 'LanguageIDs',
'use_automatically', 'use_inner_classes_automatically', 'LOGLEVEL_TRACE',
'use_automatically', 'use_inner_classes_automatically',
]
6 changes: 3 additions & 3 deletions facedancer/backends/goodfet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import serial
import sys
import time
import logging

from ..core import FacedancerApp
from ..core import FacedancerApp
from ..backends.MAXUSBApp import MAXUSBApp
from ..logging import log


class GoodfetMaxUSBApp(MAXUSBApp):
Expand All @@ -31,7 +31,7 @@ def appropriate_for_environment(cls, backend_name):
gf.close()
return True
except ImportError:
logging.info("Skipping GoodFET-based devices, as pyserial isn't installed.")
log.info("Skipping GoodFET-based devices, as pyserial isn't installed.")
return False
except:
return False
Expand Down
26 changes: 12 additions & 14 deletions facedancer/backends/greatdancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import sys
import time
import codecs
import logging
import traceback

from ..core import *
from ..types import *
from ..core import *
from ..types import *

from ..logging import log

# FIXME: abstract this to the logging library
LOGLEVEL_TRACE = 5

class GreatDancerApp(FacedancerApp):
"""
Expand Down Expand Up @@ -63,7 +61,7 @@ def appropriate_for_environment(cls, backend_name):
gf = greatfet.GreatFET()
return gf.supports_api('greatdancer')
except ImportError:
logging.info("Skipping GreatFET-based devices, as the greatfet python module isn't installed.")
log.info("Skipping GreatFET-based devices, as the greatfet python module isn't installed.")
return False
except:
return False
Expand Down Expand Up @@ -176,7 +174,7 @@ def _generate_endpoint_config_arguments(self, config):

for interface in config.get_interfaces():
for endpoint in interface.get_endpoints():
logging.info(f"Configuring {endpoint}.")
log.info(f"Configuring {endpoint}.")

triple = (endpoint.get_address(), endpoint.max_packet_size, endpoint.transfer_type,)
arguments.append(triple)
Expand All @@ -199,19 +197,19 @@ def connect(self, usb_device, max_ep0_packet_size=64):

# Compute our quirk flags.
if 'manual_set_address' in self.quirks:
logging.info("Handling SET_ADDRESS on the host side!")
log.info("Handling SET_ADDRESS on the host side!")

quirks |= self.QUIRK_MANUAL_SET_ADDRESS

self.api.connect(self.max_ep0_packet_size, quirks)
self.connected_device = usb_device

logging.info("Connecting to host.")
log.info("Connecting to host.")


def disconnect(self):
""" Disconnects the GreatDancer from its target host. """
logging.info("Disconnecting from host.")
log.info("Disconnecting from host.")
self.device.comms.release_exclusive_access()
self.api.disconnect()

Expand Down Expand Up @@ -240,7 +238,7 @@ def send_on_endpoint(self, ep_num, data, blocking=True):
data: The data to be sent.
blocking: If true, this function will wait for the transfer to complete.
"""
logging.log(LOGLEVEL_TRACE, f"EP{ep_num}/IN: <- {bytes(data)}")
log.trace(f"EP{ep_num}/IN: <- {bytes(data)}")

self._wait_until_ready_to_send(ep_num)
self.api.send_on_endpoint(ep_num, bytes(data))
Expand Down Expand Up @@ -291,7 +289,7 @@ def stall_endpoint(self, ep_num, direction=0):
"""

in_vs_out = "IN" if direction else "OUT"
logging.log(LOGLEVEL_TRACE, "Stalling EP{} {}".format(ep_num, in_vs_out))
log.trace("Stalling EP{} {}".format(ep_num, in_vs_out))

self.endpoint_stalled[ep_num] = True
self.api.stall_endpoint(self._endpoint_address(ep_num, direction))
Expand Down Expand Up @@ -566,7 +564,7 @@ def _handle_transfer_complete_on_endpoint(self, endpoint_number, direction):
# callback.
else:
data = self._finish_primed_read_on_endpoint(endpoint_number)
logging.log(LOGLEVEL_TRACE, f"EP{endpoint_number}/OUT -> {data}")
log.trace(f"EP{endpoint_number}/OUT -> {data}")
self.connected_device.handle_data_available(endpoint_number, data)


Expand Down Expand Up @@ -675,7 +673,7 @@ def _bus_reset(self):
Triggers the GreatDancer to perform its side of a bus reset.
"""

logging.debug("Host issued bus reset.")
log.debug("Host issued bus reset.")

if self.connected_device:
self.connected_device.handle_bus_reset()
Expand Down
5 changes: 3 additions & 2 deletions facedancer/backends/greathost.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import time
import codecs
import struct
import logging

from ..core import *
from ..types import *

from ..logging import log


class GreatDancerHostApp(FacedancerUSBHost):
"""
Expand Down Expand Up @@ -102,7 +103,7 @@ def appropriate_for_environment(cls, backend_name):
greatfet.GreatFET()
return True
except ImportError:
logging.info("Skipping GreatFET-based devices, as the greatfet python module isn't installed.")
log.info("Skipping GreatFET-based devices, as the greatfet python module isn't installed.")
return False
except:
return False
Expand Down
Loading

0 comments on commit be27c9a

Please sign in to comment.