Skip to content

Commit

Permalink
feat(log): Group loggers in gallia context
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinandjarisch committed Sep 15, 2023
1 parent 557b70e commit 4f72681
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/gallia/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class BaseCommand(ABC):
EPILOG: str | None = None

#: The name of the logger when this command is run.
LOGGER_NAME = "gallia"
LOGGER_NAME = __name__
#: Enable a artifacts_dir. Setting this property to
#: True enables the creation of a logfile.
HAS_ARTIFACTS_DIR: bool = False
Expand Down
1 change: 1 addition & 0 deletions src/gallia/commands/scan/uds/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ServicesScanner(UDSScanner):
EPILOG = (
"https://fraunhofer-aisec.github.io/gallia/uds/scan_modes.html#service-scan"
)
LOGGER_NAME = "gallia.scan.services"

def configure_parser(self) -> None:
self.parser.add_argument(
Expand Down
1 change: 1 addition & 0 deletions src/gallia/commands/scan/uds/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SessionsScanner(UDSScanner):

COMMAND = "sessions"
SHORT_HELP = "session scan on an ECU"
LOGGER_NAME = "gallia.scan.sessions"

def configure_parser(self) -> None:
self.parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/db/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self, database: Path):
self.target: str | None = None
self.discovery_run: int | None = None
self.meta: int | None = None
self.logger = get_logger("db")
self.logger = get_logger("gallia.db")

async def connect(self) -> None:
assert self.connection is None, "Already connected to the database"
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/dumpcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def start(
target: TargetURI,
artifacts_dir: Path,
) -> Dumpcap:
logger = get_logger("dumpcap")
logger = get_logger("gallia.dumpcap")

ts = int(datetime.now().timestamp())
if target.scheme in [ISOTPTransport.SCHEME, RawCANTransport.SCHEME]:
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/powersupply.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def product_id(self) -> str:

class PowerSupply:
def __init__(self, client: BaseNetzteil, channel_id: int | list[int]) -> None:
self.logger = get_logger("power_supply")
self.logger = get_logger("gallia.power_supply")
self.channel_id = channel_id
self.netzteil = client
self.mutex = asyncio.Lock()
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/services/uds/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
self.retry_wait = 0.2
self.pending_timeout = 5
self.mutex = asyncio.Lock()
self.logger = get_logger("uds")
self.logger = get_logger("gallia.uds")

async def reconnect(self, timeout: int | None = None) -> None:
"""Calls the underlying transport to trigger a reconnect"""
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/services/uds/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
uds_memory_parameters,
)

logger = get_logger("uds")
logger = get_logger("gallia.uds")

# ****************
# * Base classes *
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/services/uds/ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
power_supply: PowerSupply | None = None,
) -> None:
super().__init__(transport, timeout, max_retry)
self.logger = get_logger("ecu")
self.logger = get_logger("gallia.ecu")
self.tester_present_task: Task[None] | None = None
self.tester_present_interval: float | None = None
self.power_supply = power_supply
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/services/xcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class XCPService:
def __init__(self, transport: BaseTransport, timeout: float = 1.0) -> None:
self.logger = get_logger("xcp")
self.logger = get_logger("gallia.xcp")
self.timeout = timeout
self.transport = transport
# This uses construct types which would result in a new
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class BaseTransport(ABC):

def __init__(self, target: TargetURI) -> None:
self.mutex = asyncio.Lock()
self.logger = get_logger(self.SCHEME)
self.logger = get_logger(f"gallia.{self.SCHEME}")
self.target = target
self.is_closed = False

Expand Down
2 changes: 1 addition & 1 deletion src/gallia/transports/doip.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __init__(
src_addr: int,
target_addr: int,
):
self.logger = get_logger("doip")
self.logger = get_logger("gallia.doip")
self.reader = reader
self.writer = writer
self.src_addr = src_addr
Expand Down

0 comments on commit 4f72681

Please sign in to comment.