Skip to content

Commit

Permalink
Moved loger config to stack module
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 15, 2024
1 parent 1bd0a0f commit c4447f2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 33 deletions.
28 changes: 0 additions & 28 deletions pytcp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,6 @@
assert version_info >= (3, 12), "PyTCP requires Python version 3.12 or higher."


# Logger configuration - LOG__CHANNEL sets which subsystems of stack log to the
# console, LOG__DEBUG adds info about class/method caller.
# Following subsystems are supported:
# stack, timer, rx-ring, tx-ring, arp-c, nd-c, ether, arp, ip4, ip6, icmp4,
# icmp6, udp, tcp, socket, tcp-ss, service.
LOG__CHANNEL = {
"stack",
# "timer",
"rx-ring",
"tx-ring",
"arp-c",
"nd-c",
"ether",
"arp",
"ip4",
"ip6",
"icmp4",
"icmp6",
"udp",
"tcp",
"socket",
"tcp-ss",
"dhcp4",
"service",
"client",
}
LOG__DEBUG = False

# IPv6 default Hop Limit value.
IP6__DEFAULT_HOP_LIMIT = 64

Expand Down
6 changes: 3 additions & 3 deletions pytcp/lib/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import inspect
import time

from pytcp import config
from pytcp import stack

STYLES = {
"</>": "\33[0m",
Expand Down Expand Up @@ -75,8 +75,8 @@ def log(
Log message if channel and severity match configured values.
"""

if channel in config.LOG__CHANNEL:
if config.LOG__DEBUG:
if channel in stack.LOG__CHANNEL:
if stack.LOG__DEBUG:
frame_info = inspect.stack()[inspect_depth]
caller_class = frame_info.frame.f_locals["self"].__class__.__name__
caller_method = frame_info.function
Expand Down
28 changes: 28 additions & 0 deletions pytcp/stack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@
ICMP6__ND__CACHE__ENTRY_MAX_AGE = 3600
ICMP6__ND__CACHE__ENTRY_REFRESH_TIME = 300

# Logger configuration - LOG__CHANNEL sets which subsystems of stack log to the
# console, LOG__DEBUG adds info about class/method caller.
# Following subsystems are supported:
# stack, timer, rx-ring, tx-ring, arp-c, nd-c, ether, arp, ip4, ip6, icmp4,
# icmp6, udp, tcp, socket, tcp-ss, service.
LOG__CHANNEL = {
"stack",
# "timer",
"rx-ring",
"tx-ring",
"arp-c",
"nd-c",
"ether",
"arp",
"ip4",
"ip6",
"icmp4",
"icmp6",
"udp",
"tcp",
"socket",
"tcp-ss",
"dhcp4",
"service",
"client",
}
LOG__DEBUG = False

version_string = "ver 3.0.2"
github_repository = "https://github.com/ccie18643/PyTCP"

Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/arp_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

from __future__ import annotations

from dataclasses import dataclass, field
import threading
import time
from dataclasses import dataclass, field

from net_addr import Ip4Address, MacAddress
from pytcp import stack
Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/nd_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

from __future__ import annotations

from dataclasses import dataclass, field
import threading
import time
from dataclasses import dataclass, field

from net_addr import Ip6Address, MacAddress
from pytcp import stack
Expand Down
1 change: 1 addition & 0 deletions tests__legacy/integration/packet_flows_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def _patch_config(self) -> None:
Patch critical config setting for all packet handler modules.
"""
for attribute, new_value in CONFIG_PATCHES.items():
stack.__dict__[attribute] = new_value
config.__dict__[attribute] = new_value

# Test name format:
Expand Down
1 change: 1 addition & 0 deletions tests__legacy/integration/packet_flows_rx_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def _patch_config(self) -> None:
Patch critical config setting for all packet handler modules.
"""
for attribute, new_value in CONFIG_PATCHES.items():
stack.__dict__[attribute] = new_value
config.__dict__[attribute] = new_value

# Test name format:
Expand Down
1 change: 1 addition & 0 deletions tests__legacy/unit/mock_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def patch_config(self: TestCase, *, enable_log: bool = False) -> None:
Patch critical config setting for all packet handler modules.
"""
for attribute, new_value in CONFIG_PATCHES.items():
stack.__dict__[attribute] = new_value
config.__dict__[attribute] = new_value


Expand Down

0 comments on commit c4447f2

Please sign in to comment.