Skip to content

Commit 707d98f

Browse files
authored
V6.0.1 (#24)
* V6.0.1 * V6.0.1 --------- Co-authored-by: ddc <ddc@users.noreply.github.com>
1 parent ec66a12 commit 707d98f

24 files changed

+365
-145
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- [Context Manager Support](#context-manager-support)
3939
- [Using With Multiple Log Levels and Files](#using-with-multiple-log-levels-and-files)
4040
- [Environment Variables](#env-variables-optional)
41+
- [Settings Cache Management](#settings-cache-management)
4142
- [Flexible Configuration Options](#flexible-configuration-options)
4243
- [Development](#development)
4344
- [Create DEV Environment, Running Tests and Building Wheel](#create-dev-environment-running-tests-and-building-wheel)
@@ -285,6 +286,25 @@ LOG_ROTATE_AT_UTC=True
285286
LOG_ROTATE_FILE_SUFIX="%Y%m%d"
286287
```
287288

289+
## Settings Cache Management
290+
291+
Use `get_log_settings()` to inspect current configuration and `clear_settings_cache()` to reload configuration from environment variables:
292+
293+
```python
294+
from pythonLogs import get_log_settings, clear_settings_cache
295+
296+
# Inspect current settings
297+
settings = get_log_settings()
298+
print(settings.level) # Current log level
299+
print(settings.timezone) # Current timezone
300+
301+
# Clear cache and reload .env on next access (default)
302+
clear_settings_cache()
303+
304+
# Clear cache but keep current .env values
305+
clear_settings_cache(reload_env=False)
306+
```
307+
288308

289309

290310

pyproject.toml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "pythonLogs"
7-
version = "6.0.0"
7+
version = "6.0.1"
88
description = "High-performance Python logging library with file rotation and optimized caching for better performance"
99
license = {text = "MIT"}
1010
readme = "README.md"
@@ -30,7 +30,7 @@ classifiers = [
3030
]
3131
requires-python = ">=3.12"
3232
dependencies = [
33-
"pydantic-settings>=2.12.0",
33+
"pydantic-settings>=2.11.0",
3434
]
3535

3636
[project.urls]
@@ -40,7 +40,7 @@ Repository = "https://github.com/ddc/pythonLogs"
4040
[project.optional-dependencies]
4141
test = [
4242
"poethepoet>=0.40.0",
43-
"psutil>=7.2.1",
43+
"psutil>=7.2.2",
4444
"pytest>=9.0.2",
4545
"pytest-cov>=7.0.0",
4646
]
@@ -54,7 +54,7 @@ packages = ["pythonLogs"]
5454
[tool.poe.tasks]
5555
build = "uv build --wheel"
5656
updatedev.shell = "uv lock && uv sync --no-install-project --all-extras"
57-
linter.shell = "uv run ruff check --fix --select I . && uv run black ."
57+
linter.shell = "uv run ruff check --fix . && uv run black ."
5858
profile = "uv run python -m cProfile -o cprofile.prof -m pytest"
5959
test = "uv run pytest"
6060

@@ -97,9 +97,20 @@ skip-string-normalization = true
9797
line-length = 120
9898

9999
[tool.ruff.lint]
100-
select = ["I"]
100+
# I - Import sorting and organization
101+
# F401 - Detect and remove unused imports
102+
select = ["I", "F401"]
101103

102104
[tool.ruff.lint.isort]
103105
known-first-party = ["pythonLogs"]
104-
force-sort-within-sections = true
106+
force-sort-within-sections = false
107+
from-first = false
105108
no-sections = true
109+
110+
[tool.ruff.lint.per-file-ignores]
111+
# S101 Use of `assert` detected
112+
# S105 Possible hardcoded password assigned to variable
113+
# S106 Possible hardcoded password assigned to argument
114+
# S311 Standard pseudo-random generators are not suitable for cryptographic purposes
115+
# SLF001 Private member accessed
116+
"tests/**/*.py" = ["S101", "S105", "S106", "S311", "SLF001"]

pythonLogs/__init__.py

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,24 @@
1-
from importlib.metadata import version
21
import logging
2+
from importlib.metadata import version
33
from pythonLogs.core.constants import LogLevel, RotateWhen
44
from pythonLogs.core.factory import BasicLog, SizeRotatingLog, TimedRotatingLog
5-
from typing import Literal, NamedTuple
5+
from pythonLogs.core.settings import clear_settings_cache, get_log_settings
66

77
__all__ = (
88
"BasicLog",
99
"SizeRotatingLog",
1010
"TimedRotatingLog",
1111
"LogLevel",
1212
"RotateWhen",
13+
"clear_settings_cache",
14+
"get_log_settings",
1315
)
1416

1517
__title__ = "pythonLogs"
1618
__author__ = "Daniel Costa"
17-
__email__ = "danieldcsta@gmail.com>"
19+
__email__ = "danieldcsta@gmail.com"
1820
__license__ = "MIT"
1921
__copyright__ = "Copyright 2024-present DDC Softwares"
20-
_req_python_version = (3, 12, 0)
21-
22-
23-
try:
24-
_version = tuple(int(x) for x in version(__title__).split("."))
25-
except ModuleNotFoundError:
26-
_version = (0, 0, 0)
27-
28-
29-
class VersionInfo(NamedTuple):
30-
major: int
31-
minor: int
32-
micro: int
33-
releaselevel: Literal["alpha", "beta", "candidate", "final"]
34-
serial: int
35-
36-
37-
__version__ = _version
38-
__version_info__: VersionInfo = VersionInfo(
39-
major=__version__[0],
40-
minor=__version__[1],
41-
micro=__version__[2],
42-
releaselevel="final",
43-
serial=0,
44-
)
45-
__req_python_version__: VersionInfo = VersionInfo(
46-
major=_req_python_version[0],
47-
minor=_req_python_version[1],
48-
micro=_req_python_version[2],
49-
releaselevel="final",
50-
serial=0,
51-
)
22+
__version__ = version(__title__)
5223

5324
logging.getLogger(__name__).addHandler(logging.NullHandler())
54-
55-
del (
56-
logging,
57-
NamedTuple,
58-
Literal,
59-
VersionInfo,
60-
version,
61-
_version,
62-
_req_python_version,
63-
)

pythonLogs/core/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from enum import Enum
21
import logging
2+
from enum import Enum
33

44
# File and Directory Constants
55
MB_TO_BYTES = 1024 * 1024

pythonLogs/core/factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import atexit
2+
import logging
3+
import threading
4+
import time
25
from dataclasses import dataclass
36
from enum import Enum
4-
import logging
57
from pythonLogs.basic_log import BasicLog as _BasicLogImpl
68
from pythonLogs.core.constants import LogLevel, RotateWhen
79
from pythonLogs.core.log_utils import cleanup_logger_handlers
810
from pythonLogs.core.settings import get_log_settings
911
from pythonLogs.size_rotating import SizeRotatingLog as _SizeRotatingLogImpl
1012
from pythonLogs.timed_rotating import TimedRotatingLog as _TimedRotatingLogImpl
11-
import threading
12-
import time
1313
from typing import Dict, Optional, Tuple, Union, assert_never
1414

1515

pythonLogs/core/log_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
from datetime import datetime, timedelta
2-
from datetime import timezone as dttz
31
import errno
4-
from functools import lru_cache
52
import gzip
63
import logging
74
import logging.handlers
85
import os
9-
from pathlib import Path
10-
from pythonLogs.core.constants import DEFAULT_FILE_MODE, LEVEL_MAP
116
import shutil
127
import sys
138
import threading
149
import time
10+
from datetime import datetime, timedelta
11+
from datetime import timezone as dttz
12+
from functools import lru_cache
13+
from pathlib import Path
14+
from pythonLogs.core.constants import DEFAULT_FILE_MODE, LEVEL_MAP
1515
from typing import Callable, Optional, Set
1616
from zoneinfo import ZoneInfo
1717

pythonLogs/core/memory_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from . import log_utils
2-
from functools import lru_cache
31
import logging
42
import threading
5-
from typing import Any, Dict, Optional, Set
63
import weakref
4+
from . import log_utils
5+
from functools import lru_cache
6+
from typing import Any, Dict, Optional, Set
77

88
# Formatter cache to reduce memory usage for identical formatters
99
_formatter_cache: Dict[str, logging.Formatter] = {}

pythonLogs/core/settings.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
_dotenv_loaded = False
1717

1818

19+
def _ensure_dotenv_loaded() -> None:
20+
"""Ensure dotenv is loaded only once."""
21+
global _dotenv_loaded
22+
if not _dotenv_loaded:
23+
load_dotenv()
24+
_dotenv_loaded = True
25+
26+
1927
class LogSettings(BaseSettings):
2028
"""If any ENV variable is omitted, it falls back to default values here"""
2129

@@ -95,9 +103,18 @@ class LogSettings(BaseSettings):
95103

96104
@lru_cache(maxsize=1)
97105
def get_log_settings() -> LogSettings:
98-
"""Get cached log settings instance to avoid repeated instantiation"""
99-
global _dotenv_loaded
100-
if not _dotenv_loaded:
101-
load_dotenv()
102-
_dotenv_loaded = True
106+
"""Get cached log settings instance to avoid repeated instantiation."""
107+
_ensure_dotenv_loaded()
103108
return LogSettings()
109+
110+
111+
def clear_settings_cache(reload_env: bool = True) -> None:
112+
"""Clear log settings cache. Next call to get_log_settings() will create fresh instance.
113+
114+
Args:
115+
reload_env: If True, also reset dotenv loaded flag to reload .env on next access
116+
"""
117+
global _dotenv_loaded
118+
get_log_settings.cache_clear()
119+
if reload_env:
120+
_dotenv_loaded = False

pythonLogs/size_rotating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging.handlers
22
import os
3+
import re
34
from pathlib import Path
45
from pythonLogs.core.constants import MB_TO_BYTES
56
from pythonLogs.core.log_utils import (
@@ -17,7 +18,6 @@
1718
from pythonLogs.core.memory_utils import register_logger_weakref
1819
from pythonLogs.core.settings import get_log_settings
1920
from pythonLogs.core.thread_safety import auto_thread_safe
20-
import re
2121

2222

2323
@auto_thread_safe(['init'])

tests/context_management/test_resource_management.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
import pytest
1414
from pythonLogs import (
15-
BasicLog,
1615
LogLevel,
17-
SizeRotatingLog,
1816
)
1917
from pythonLogs.basic_log import BasicLog as BasicLogImpl
2018
from pythonLogs.core.factory import (

0 commit comments

Comments
 (0)