pythonLogs 6.0.0__tar.gz → 6.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/PKG-INFO +23 -3
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/README.md +20 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pyproject.toml +17 -6
- pythonlogs-6.0.1/pythonLogs/__init__.py +24 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/settings.py +22 -5
- pythonlogs-6.0.0/pythonLogs/__init__.py +0 -63
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/.gitignore +0 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/LICENSE +0 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/.env.example +0 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/basic_log.py +0 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/__init__.py +0 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/constants.py +1 -1
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/factory.py +3 -3
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/log_utils.py +5 -5
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/memory_utils.py +3 -3
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/core/thread_safety.py +0 -0
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/size_rotating.py +1 -1
- {pythonlogs-6.0.0 → pythonlogs-6.0.1}/pythonLogs/timed_rotating.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pythonLogs
|
|
3
|
-
Version: 6.0.
|
|
3
|
+
Version: 6.0.1
|
|
4
4
|
Summary: High-performance Python logging library with file rotation and optimized caching for better performance
|
|
5
5
|
Project-URL: Homepage, https://pypi.org/project/pythonLogs
|
|
6
6
|
Project-URL: Repository, https://github.com/ddc/pythonLogs
|
|
@@ -21,10 +21,10 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.14
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
23
|
Requires-Python: >=3.12
|
|
24
|
-
Requires-Dist: pydantic-settings>=2.
|
|
24
|
+
Requires-Dist: pydantic-settings>=2.11.0
|
|
25
25
|
Provides-Extra: test
|
|
26
26
|
Requires-Dist: poethepoet>=0.40.0; extra == 'test'
|
|
27
|
-
Requires-Dist: psutil>=7.2.
|
|
27
|
+
Requires-Dist: psutil>=7.2.2; extra == 'test'
|
|
28
28
|
Requires-Dist: pytest-cov>=7.0.0; extra == 'test'
|
|
29
29
|
Requires-Dist: pytest>=9.0.2; extra == 'test'
|
|
30
30
|
Description-Content-Type: text/markdown
|
|
@@ -69,6 +69,7 @@ Description-Content-Type: text/markdown
|
|
|
69
69
|
- [Context Manager Support](#context-manager-support)
|
|
70
70
|
- [Using With Multiple Log Levels and Files](#using-with-multiple-log-levels-and-files)
|
|
71
71
|
- [Environment Variables](#env-variables-optional)
|
|
72
|
+
- [Settings Cache Management](#settings-cache-management)
|
|
72
73
|
- [Flexible Configuration Options](#flexible-configuration-options)
|
|
73
74
|
- [Development](#development)
|
|
74
75
|
- [Create DEV Environment, Running Tests and Building Wheel](#create-dev-environment-running-tests-and-building-wheel)
|
|
@@ -316,6 +317,25 @@ LOG_ROTATE_AT_UTC=True
|
|
|
316
317
|
LOG_ROTATE_FILE_SUFIX="%Y%m%d"
|
|
317
318
|
```
|
|
318
319
|
|
|
320
|
+
## Settings Cache Management
|
|
321
|
+
|
|
322
|
+
Use `get_log_settings()` to inspect current configuration and `clear_settings_cache()` to reload configuration from environment variables:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
from pythonLogs import get_log_settings, clear_settings_cache
|
|
326
|
+
|
|
327
|
+
# Inspect current settings
|
|
328
|
+
settings = get_log_settings()
|
|
329
|
+
print(settings.level) # Current log level
|
|
330
|
+
print(settings.timezone) # Current timezone
|
|
331
|
+
|
|
332
|
+
# Clear cache and reload .env on next access (default)
|
|
333
|
+
clear_settings_cache()
|
|
334
|
+
|
|
335
|
+
# Clear cache but keep current .env values
|
|
336
|
+
clear_settings_cache(reload_env=False)
|
|
337
|
+
```
|
|
338
|
+
|
|
319
339
|
|
|
320
340
|
|
|
321
341
|
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
- [Context Manager Support](#context-manager-support)
|
|
39
39
|
- [Using With Multiple Log Levels and Files](#using-with-multiple-log-levels-and-files)
|
|
40
40
|
- [Environment Variables](#env-variables-optional)
|
|
41
|
+
- [Settings Cache Management](#settings-cache-management)
|
|
41
42
|
- [Flexible Configuration Options](#flexible-configuration-options)
|
|
42
43
|
- [Development](#development)
|
|
43
44
|
- [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
|
|
|
285
286
|
LOG_ROTATE_FILE_SUFIX="%Y%m%d"
|
|
286
287
|
```
|
|
287
288
|
|
|
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
|
+
|
|
288
308
|
|
|
289
309
|
|
|
290
310
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pythonLogs"
|
|
7
|
-
version = "6.0.
|
|
7
|
+
version = "6.0.1"
|
|
8
8
|
description = "High-performance Python logging library with file rotation and optimized caching for better performance"
|
|
9
9
|
license = {text = "MIT"}
|
|
10
10
|
readme = "README.md"
|
|
@@ -30,7 +30,7 @@ classifiers = [
|
|
|
30
30
|
]
|
|
31
31
|
requires-python = ">=3.12"
|
|
32
32
|
dependencies = [
|
|
33
|
-
"pydantic-settings>=2.
|
|
33
|
+
"pydantic-settings>=2.11.0",
|
|
34
34
|
]
|
|
35
35
|
|
|
36
36
|
[project.urls]
|
|
@@ -40,7 +40,7 @@ Repository = "https://github.com/ddc/pythonLogs"
|
|
|
40
40
|
[project.optional-dependencies]
|
|
41
41
|
test = [
|
|
42
42
|
"poethepoet>=0.40.0",
|
|
43
|
-
"psutil>=7.2.
|
|
43
|
+
"psutil>=7.2.2",
|
|
44
44
|
"pytest>=9.0.2",
|
|
45
45
|
"pytest-cov>=7.0.0",
|
|
46
46
|
]
|
|
@@ -54,7 +54,7 @@ packages = ["pythonLogs"]
|
|
|
54
54
|
[tool.poe.tasks]
|
|
55
55
|
build = "uv build --wheel"
|
|
56
56
|
updatedev.shell = "uv lock && uv sync --no-install-project --all-extras"
|
|
57
|
-
linter.shell = "uv run ruff check --fix
|
|
57
|
+
linter.shell = "uv run ruff check --fix . && uv run black ."
|
|
58
58
|
profile = "uv run python -m cProfile -o cprofile.prof -m pytest"
|
|
59
59
|
test = "uv run pytest"
|
|
60
60
|
|
|
@@ -97,9 +97,20 @@ skip-string-normalization = true
|
|
|
97
97
|
line-length = 120
|
|
98
98
|
|
|
99
99
|
[tool.ruff.lint]
|
|
100
|
-
|
|
100
|
+
# I - Import sorting and organization
|
|
101
|
+
# F401 - Detect and remove unused imports
|
|
102
|
+
select = ["I", "F401"]
|
|
101
103
|
|
|
102
104
|
[tool.ruff.lint.isort]
|
|
103
105
|
known-first-party = ["pythonLogs"]
|
|
104
|
-
force-sort-within-sections =
|
|
106
|
+
force-sort-within-sections = false
|
|
107
|
+
from-first = false
|
|
105
108
|
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"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from importlib.metadata import version
|
|
3
|
+
from pythonLogs.core.constants import LogLevel, RotateWhen
|
|
4
|
+
from pythonLogs.core.factory import BasicLog, SizeRotatingLog, TimedRotatingLog
|
|
5
|
+
from pythonLogs.core.settings import clear_settings_cache, get_log_settings
|
|
6
|
+
|
|
7
|
+
__all__ = (
|
|
8
|
+
"BasicLog",
|
|
9
|
+
"SizeRotatingLog",
|
|
10
|
+
"TimedRotatingLog",
|
|
11
|
+
"LogLevel",
|
|
12
|
+
"RotateWhen",
|
|
13
|
+
"clear_settings_cache",
|
|
14
|
+
"get_log_settings",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__title__ = "pythonLogs"
|
|
18
|
+
__author__ = "Daniel Costa"
|
|
19
|
+
__email__ = "danieldcsta@gmail.com"
|
|
20
|
+
__license__ = "MIT"
|
|
21
|
+
__copyright__ = "Copyright 2024-present DDC Softwares"
|
|
22
|
+
__version__ = version(__title__)
|
|
23
|
+
|
|
24
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
@@ -16,6 +16,14 @@ from pythonLogs.core.constants import (
|
|
|
16
16
|
_dotenv_loaded = False
|
|
17
17
|
|
|
18
18
|
|
|
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
|
+
|
|
19
27
|
class LogSettings(BaseSettings):
|
|
20
28
|
"""If any ENV variable is omitted, it falls back to default values here"""
|
|
21
29
|
|
|
@@ -95,9 +103,18 @@ class LogSettings(BaseSettings):
|
|
|
95
103
|
|
|
96
104
|
@lru_cache(maxsize=1)
|
|
97
105
|
def get_log_settings() -> LogSettings:
|
|
98
|
-
"""Get cached log settings instance to avoid repeated instantiation"""
|
|
99
|
-
|
|
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()
|
|
103
108
|
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
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
from importlib.metadata import version
|
|
2
|
-
import logging
|
|
3
|
-
from pythonLogs.core.constants import LogLevel, RotateWhen
|
|
4
|
-
from pythonLogs.core.factory import BasicLog, SizeRotatingLog, TimedRotatingLog
|
|
5
|
-
from typing import Literal, NamedTuple
|
|
6
|
-
|
|
7
|
-
__all__ = (
|
|
8
|
-
"BasicLog",
|
|
9
|
-
"SizeRotatingLog",
|
|
10
|
-
"TimedRotatingLog",
|
|
11
|
-
"LogLevel",
|
|
12
|
-
"RotateWhen",
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
__title__ = "pythonLogs"
|
|
16
|
-
__author__ = "Daniel Costa"
|
|
17
|
-
__email__ = "danieldcsta@gmail.com>"
|
|
18
|
-
__license__ = "MIT"
|
|
19
|
-
__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
|
-
)
|
|
52
|
-
|
|
53
|
-
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
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import atexit
|
|
2
|
+
import logging
|
|
3
|
+
import threading
|
|
4
|
+
import time
|
|
2
5
|
from dataclasses import dataclass
|
|
3
6
|
from enum import Enum
|
|
4
|
-
import logging
|
|
5
7
|
from pythonLogs.basic_log import BasicLog as _BasicLogImpl
|
|
6
8
|
from pythonLogs.core.constants import LogLevel, RotateWhen
|
|
7
9
|
from pythonLogs.core.log_utils import cleanup_logger_handlers
|
|
8
10
|
from pythonLogs.core.settings import get_log_settings
|
|
9
11
|
from pythonLogs.size_rotating import SizeRotatingLog as _SizeRotatingLogImpl
|
|
10
12
|
from pythonLogs.timed_rotating import TimedRotatingLog as _TimedRotatingLogImpl
|
|
11
|
-
import threading
|
|
12
|
-
import time
|
|
13
13
|
from typing import Dict, Optional, Tuple, Union, assert_never
|
|
14
14
|
|
|
15
15
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
from datetime import datetime, timedelta
|
|
2
|
-
from datetime import timezone as dttz
|
|
3
1
|
import errno
|
|
4
|
-
from functools import lru_cache
|
|
5
2
|
import gzip
|
|
6
3
|
import logging
|
|
7
4
|
import logging.handlers
|
|
8
5
|
import os
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from pythonLogs.core.constants import DEFAULT_FILE_MODE, LEVEL_MAP
|
|
11
6
|
import shutil
|
|
12
7
|
import sys
|
|
13
8
|
import threading
|
|
14
9
|
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
|
|
15
15
|
from typing import Callable, Optional, Set
|
|
16
16
|
from zoneinfo import ZoneInfo
|
|
17
17
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from . import log_utils
|
|
2
|
-
from functools import lru_cache
|
|
3
1
|
import logging
|
|
4
2
|
import threading
|
|
5
|
-
from typing import Any, Dict, Optional, Set
|
|
6
3
|
import weakref
|
|
4
|
+
from . import log_utils
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
from typing import Any, Dict, Optional, Set
|
|
7
7
|
|
|
8
8
|
# Formatter cache to reduce memory usage for identical formatters
|
|
9
9
|
_formatter_cache: Dict[str, logging.Formatter] = {}
|
|
File without changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import logging.handlers
|
|
2
2
|
import os
|
|
3
|
+
import re
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
from pythonLogs.core.constants import MB_TO_BYTES
|
|
5
6
|
from pythonLogs.core.log_utils import (
|
|
@@ -17,7 +18,6 @@ from pythonLogs.core.log_utils import (
|
|
|
17
18
|
from pythonLogs.core.memory_utils import register_logger_weakref
|
|
18
19
|
from pythonLogs.core.settings import get_log_settings
|
|
19
20
|
from pythonLogs.core.thread_safety import auto_thread_safe
|
|
20
|
-
import re
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
@auto_thread_safe(['init'])
|
|
File without changes
|