Skip to content

Commit f70ae5e

Browse files
committed
V5.0.1
1 parent 38d8dbe commit f70ae5e

18 files changed

+1137
-608
lines changed

.github/workflows/workflow.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ jobs:
3737
run: poetry run poe tests
3838
shell: bash
3939

40-
- name: Upload coverage reports to Codecov
40+
- name: Upload coverage to Codecov
4141
if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
4242
uses: codecov/codecov-action@v5
4343
with:
4444
token: ${{ secrets.CODECOV_TOKEN }}
4545
slug: ddc/pythonLogs
4646

47+
- name: Upload test results to Codecov
48+
if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
49+
uses: codecov/test-results-action@v1
50+
with:
51+
token: ${{ secrets.CODECOV_TOKEN }}
52+
slug: ddc/pythonLogs
53+
4754
build:
4855
name: Build for Python ${{ matrix.python-version }} on ${{ matrix.os }}
4956
runs-on: ${{ matrix.os }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ cython_debug/
162162
/profile_fixed.prof
163163
/profile_output.prof
164164
/profile_pytest.prof
165+
/junit.xml

poetry.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ pydantic-settings = "^2.10.1"
4343
python-dotenv = "^1.1.1"
4444

4545
[tool.poetry.group.test.dependencies]
46-
coverage = "^7.10.0"
4746
poethepoet = "^0.36.0"
4847
psutil = "^7.0.0"
4948
pytest = "^8.4.1"
49+
pytest-cov = "^6.2.1"
5050

5151
[tool.poe.tasks]
52-
_test = "coverage run -m pytest -v"
53-
_coverage_report = "coverage report"
54-
_coverage_xml = "coverage xml"
55-
tests = ["_test", "_coverage_report", "_coverage_xml"]
52+
_test = "python -m pytest -v --cov=pythonLogs --cov-report=term --cov-report=xml --junitxml=junit.xml -o junit_family=legacy"
53+
tests = ["_test"]
5654
test = ["tests"]
5755

5856
[tool.black]
@@ -66,6 +64,7 @@ markers = [
6664

6765
[tool.coverage.run]
6866
omit = [
67+
"build.py",
6968
"tests/*",
7069
]
7170

pythonLogs/log_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def is_older_than_x_days(path: str, days: int) -> bool:
153153

154154
# Cache stderr timezone for better performance
155155
@lru_cache(maxsize=1)
156-
def _get_stderr_timezone():
156+
def get_stderr_timezone():
157157
timezone_name = os.getenv("LOG_TIMEZONE", "UTC")
158158
if timezone_name.lower() == "localtime":
159159
return None # Use system local timezone
@@ -167,7 +167,7 @@ def _get_stderr_timezone():
167167
def write_stderr(msg: str) -> None:
168168
"""Write msg to stderr with optimized timezone handling"""
169169
try:
170-
tz = _get_stderr_timezone()
170+
tz = get_stderr_timezone()
171171
if tz is None:
172172
# Use local timezone
173173
dt = datetime.now()
@@ -206,7 +206,7 @@ def get_log_path(directory: str, filename: str) -> str:
206206

207207

208208
@lru_cache(maxsize=32)
209-
def _get_timezone_offset(timezone_: str) -> str:
209+
def get_timezone_offset(timezone_: str) -> str:
210210
"""Cache timezone offset calculation with fallback for missing timezone data"""
211211
if timezone_.lower() == "localtime":
212212
return time.strftime("%z")
@@ -230,7 +230,7 @@ def get_format(show_location: bool, name: str, timezone_: str) -> str:
230230
if show_location:
231231
_debug_fmt = "[%(filename)s:%(funcName)s:%(lineno)d]:"
232232

233-
utc_offset = _get_timezone_offset(timezone_)
233+
utc_offset = get_timezone_offset(timezone_)
234234
return f"[%(asctime)s.%(msecs)03d{utc_offset}]:[%(levelname)s]:{_logger_name}{_debug_fmt}%(message)s"
235235

236236

pythonLogs/memory_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ def optimize_lru_cache_sizes() -> None:
175175
log_utils.get_timezone_function = lru_cache(maxsize=8)(log_utils.get_timezone_function.__wrapped__)
176176

177177
# Clear and recreate timezone offset cache with smaller size
178-
log_utils._get_timezone_offset.cache_clear()
179-
log_utils._get_timezone_offset = lru_cache(maxsize=8)(log_utils._get_timezone_offset.__wrapped__)
178+
log_utils.get_timezone_offset.cache_clear()
179+
log_utils.get_timezone_offset = lru_cache(maxsize=8)(log_utils.get_timezone_offset.__wrapped__)
180180

181181
# Clear and recreate stderr timezone cache with smaller size
182-
log_utils._get_stderr_timezone.cache_clear()
183-
log_utils._get_stderr_timezone = lru_cache(maxsize=4)(log_utils._get_stderr_timezone.__wrapped__)
182+
log_utils.get_stderr_timezone.cache_clear()
183+
log_utils.get_stderr_timezone = lru_cache(maxsize=4)(log_utils.get_stderr_timezone.__wrapped__)
184184

185185

186186
def force_garbage_collection() -> Dict[str, int]:

tests/context_management/test_resource_management.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_factory_registry_cleanup(self):
6262

6363
# Verify handlers were closed and removed
6464
assert len(logger.handlers) == 0
65+
assert initial_handler_count > 0 # Ensure we actually had handlers to clean up
6566
assert len(LoggerFactory._logger_registry) == 0
6667

6768
def test_shutdown_specific_logger(self):
@@ -236,6 +237,8 @@ def test_memory_usage_after_cleanup(self):
236237

237238
# Logger should still exist due to registry
238239
assert logger_weakref() is not None
240+
# Handlers should also still exist
241+
assert all(ref() is not None for ref in handler_weakrefs)
239242

240243
# Clear registry
241244
clear_logger_registry()
@@ -244,7 +247,7 @@ def test_memory_usage_after_cleanup(self):
244247
gc.collect()
245248

246249
# Logger should be garbage collected
247-
# Note: This test might be flaky depending on Python's garbage collector
250+
# Note: This test might be flaky depending on Python's garbage collector,
248251
# but it helps verify we're not holding unnecessary references
249252
print(f"Logger weakref after cleanup: {logger_weakref()}")
250253

0 commit comments

Comments
 (0)