custom-python-logger 2.0.3__py3-none-any.whl → 2.0.4__py3-none-any.whl
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.
- custom_python_logger/logger.py +14 -23
- custom_python_logger/usage_example.py +3 -3
- {custom_python_logger-2.0.3.dist-info → custom_python_logger-2.0.4.dist-info}/METADATA +3 -1
- custom_python_logger-2.0.4.dist-info/RECORD +9 -0
- custom_python_logger-2.0.3.dist-info/RECORD +0 -9
- {custom_python_logger-2.0.3.dist-info → custom_python_logger-2.0.4.dist-info}/WHEEL +0 -0
- {custom_python_logger-2.0.3.dist-info → custom_python_logger-2.0.4.dist-info}/licenses/LICENSE +0 -0
- {custom_python_logger-2.0.3.dist-info → custom_python_logger-2.0.4.dist-info}/top_level.txt +0 -0
custom_python_logger/logger.py
CHANGED
|
@@ -2,9 +2,10 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
import os
|
|
4
4
|
import time
|
|
5
|
+
from collections.abc import Callable
|
|
5
6
|
from logging import Logger
|
|
6
7
|
from pathlib import Path
|
|
7
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
8
9
|
|
|
9
10
|
import yaml
|
|
10
11
|
from colorlog import ColoredFormatter
|
|
@@ -12,21 +13,15 @@ from colorlog import ColoredFormatter
|
|
|
12
13
|
from custom_python_logger.consts import LOG_COLORS, CustomLoggerLevel
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
def json_pretty_format(
|
|
16
|
-
data: Any, indent: int = 4, sort_keys: bool = True, default: Callable = None
|
|
17
|
-
) -> str:
|
|
16
|
+
def json_pretty_format(data: Any, indent: int = 4, sort_keys: bool = True, default: Callable = None) -> str:
|
|
18
17
|
return json.dumps(data, indent=indent, sort_keys=sort_keys, default=default)
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
def yaml_pretty_format(
|
|
22
|
-
data
|
|
23
|
-
) -> str:
|
|
24
|
-
return yaml.dump(
|
|
25
|
-
data, sort_keys=sort_keys, indent=indent, allow_unicode=allow_unicode
|
|
26
|
-
)
|
|
20
|
+
def yaml_pretty_format(data: Any, indent: int = 4, sort_keys: bool = False, allow_unicode: bool = True) -> str:
|
|
21
|
+
return yaml.dump(data, sort_keys=sort_keys, indent=indent, allow_unicode=allow_unicode)
|
|
27
22
|
|
|
28
23
|
|
|
29
|
-
def get_project_path_by_file(markers:
|
|
24
|
+
def get_project_path_by_file(markers: list[str] | None = None) -> Path:
|
|
30
25
|
if not markers:
|
|
31
26
|
markers = ["pyproject.toml", "setup.py", ".git", "requirements.txt", ".gitignore", ".github", ".gitlab"]
|
|
32
27
|
path = Path(__file__).resolve() if "__file__" in globals() else Path.cwd().resolve()
|
|
@@ -53,12 +48,12 @@ def print_before_logger(project_name: str) -> None:
|
|
|
53
48
|
|
|
54
49
|
|
|
55
50
|
class CustomLoggerAdapter(logging.LoggerAdapter):
|
|
56
|
-
def exception(self, msg: str, *args, **kwargs):
|
|
51
|
+
def exception(self, msg: str, *args: Any, **kwargs: Any) -> None:
|
|
57
52
|
logging.addLevelName(CustomLoggerLevel.EXCEPTION.value, "EXCEPTION")
|
|
58
53
|
kwargs.setdefault("stacklevel", 2)
|
|
59
54
|
self.log(CustomLoggerLevel.EXCEPTION.value, msg, *args, exc_info=True, **kwargs)
|
|
60
55
|
|
|
61
|
-
def step(self, msg: str, *args, **kwargs):
|
|
56
|
+
def step(self, msg: str, *args: Any, **kwargs: Any) -> None:
|
|
62
57
|
logging.addLevelName(CustomLoggerLevel.STEP.value, "STEP")
|
|
63
58
|
kwargs.setdefault("stacklevel", 2)
|
|
64
59
|
self.log(CustomLoggerLevel.STEP.value, msg, *args, exc_info=False, **kwargs)
|
|
@@ -72,7 +67,7 @@ def clear_existing_handlers(logger: Logger) -> None:
|
|
|
72
67
|
def add_file_handler_if_specified(
|
|
73
68
|
logger: Logger,
|
|
74
69
|
log_file: bool,
|
|
75
|
-
log_file_path:
|
|
70
|
+
log_file_path: str | None,
|
|
76
71
|
log_format: str,
|
|
77
72
|
) -> None:
|
|
78
73
|
if log_file and log_file_path is not None:
|
|
@@ -89,11 +84,7 @@ def add_file_handler_if_specified(
|
|
|
89
84
|
logger.addHandler(file_handler)
|
|
90
85
|
|
|
91
86
|
|
|
92
|
-
def add_console_handler_if_specified(
|
|
93
|
-
logger: Logger,
|
|
94
|
-
console_output: bool,
|
|
95
|
-
log_format: str
|
|
96
|
-
):
|
|
87
|
+
def add_console_handler_if_specified(logger: Logger, console_output: bool, log_format: str) -> None:
|
|
97
88
|
if console_output:
|
|
98
89
|
log_console_formatter = ColoredFormatter(
|
|
99
90
|
"%(log_color)s " + log_format,
|
|
@@ -110,7 +101,7 @@ def configure_logging(
|
|
|
110
101
|
utc: bool,
|
|
111
102
|
log_level: int = logging.INFO,
|
|
112
103
|
log_file: bool = False,
|
|
113
|
-
log_file_path:
|
|
104
|
+
log_file_path: str | None = None,
|
|
114
105
|
console_output: bool = True,
|
|
115
106
|
) -> None:
|
|
116
107
|
"""
|
|
@@ -148,8 +139,8 @@ def configure_logging(
|
|
|
148
139
|
|
|
149
140
|
def build_logger(
|
|
150
141
|
project_name: str,
|
|
151
|
-
extra:
|
|
152
|
-
log_format: str = "%(asctime)s | %(levelname)-9s | l.%(levelno)s | %(name)s | %(filename)s:%(lineno)s | %(message)s",
|
|
142
|
+
extra: dict[str, Any] | None = None,
|
|
143
|
+
log_format: str = "%(asctime)s | %(levelname)-9s | l.%(levelno)s | %(name)s | %(filename)s:%(lineno)s | %(message)s", # pylint: disable=C0301
|
|
153
144
|
log_level: int = logging.INFO,
|
|
154
145
|
log_file: bool = False,
|
|
155
146
|
log_file_path: str = None,
|
|
@@ -192,5 +183,5 @@ def build_logger(
|
|
|
192
183
|
return CustomLoggerAdapter(logger, extra)
|
|
193
184
|
|
|
194
185
|
|
|
195
|
-
def get_logger(name: str, extra:
|
|
186
|
+
def get_logger(name: str, extra: dict | None = None) -> CustomLoggerAdapter:
|
|
196
187
|
return CustomLoggerAdapter(logging.getLogger(name), extra=extra)
|
|
@@ -4,16 +4,16 @@ from custom_python_logger import build_logger, get_logger
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class LoggerTest:
|
|
7
|
-
def __init__(self):
|
|
7
|
+
def __init__(self) -> None:
|
|
8
8
|
self.logger = get_logger(self.__class__.__name__, extra={"class": self.__class__.__name__})
|
|
9
9
|
|
|
10
|
-
def main(self):
|
|
10
|
+
def main(self) -> None:
|
|
11
11
|
self.logger.debug("Hello World")
|
|
12
12
|
self.logger.info("Hello World")
|
|
13
13
|
self.logger.step("Hello World")
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
def main():
|
|
16
|
+
def main() -> None:
|
|
17
17
|
logger = build_logger(
|
|
18
18
|
project_name="Logger Project Test",
|
|
19
19
|
log_level=logging.DEBUG,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: custom-python-logger
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.4
|
|
4
4
|
Summary: A custom logger with color support and additional features.
|
|
5
5
|
Home-page: https://github.com/aviz92/custom-python-logger
|
|
6
6
|
Author: Avi Zaguri
|
|
@@ -12,6 +12,8 @@ License-File: LICENSE
|
|
|
12
12
|
Requires-Dist: setuptools
|
|
13
13
|
Requires-Dist: wheel
|
|
14
14
|
Requires-Dist: colorlog
|
|
15
|
+
Requires-Dist: python-dotenv
|
|
16
|
+
Requires-Dist: pre-commit
|
|
15
17
|
Requires-Dist: pytest
|
|
16
18
|
Requires-Dist: pathlib
|
|
17
19
|
Requires-Dist: PyYAML
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
custom_python_logger/__init__.py,sha256=ZikWW8-tWv5bbK5_DCeoemAQVg6yTEOTQu6SVZHait8,283
|
|
2
|
+
custom_python_logger/consts.py,sha256=Vut58yw0VkNTNiZ74qgar_nI2WHouwX3CiCAcOuUhrc,286
|
|
3
|
+
custom_python_logger/logger.py,sha256=lZOsLpO79C7_LjJVshze7O8fCtK4PnLItgQaGZnlBuk,6045
|
|
4
|
+
custom_python_logger/usage_example.py,sha256=A_QExIoDWhLI6d3BENzYLjhahOVtgVYyXsFZOBXbrss,1014
|
|
5
|
+
custom_python_logger-2.0.4.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
|
|
6
|
+
custom_python_logger-2.0.4.dist-info/METADATA,sha256=uk6XNMTAX7BRFLMDTQN0j6_bsEfkdUS0diAg8NSTnM8,4040
|
|
7
|
+
custom_python_logger-2.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
custom_python_logger-2.0.4.dist-info/top_level.txt,sha256=lMihLuDQUTn0aSzzzbv9LZZTWTAap0IKpKabUHwOgks,21
|
|
9
|
+
custom_python_logger-2.0.4.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
custom_python_logger/__init__.py,sha256=ZikWW8-tWv5bbK5_DCeoemAQVg6yTEOTQu6SVZHait8,283
|
|
2
|
-
custom_python_logger/consts.py,sha256=Vut58yw0VkNTNiZ74qgar_nI2WHouwX3CiCAcOuUhrc,286
|
|
3
|
-
custom_python_logger/logger.py,sha256=HNgV1QVLf07nemsHhWqhBh8yvgR3G-OINrp7d0cphB4,6006
|
|
4
|
-
custom_python_logger/usage_example.py,sha256=_-xur33-LXr2A91vkKNLrv0ON4k4uEsiZQK5-JxGIH4,990
|
|
5
|
-
custom_python_logger-2.0.3.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
|
|
6
|
-
custom_python_logger-2.0.3.dist-info/METADATA,sha256=n4solp9EervNNvcJRtE03XTvfKd0Tqj0M0cwz0RT7WU,3985
|
|
7
|
-
custom_python_logger-2.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
custom_python_logger-2.0.3.dist-info/top_level.txt,sha256=lMihLuDQUTn0aSzzzbv9LZZTWTAap0IKpKabUHwOgks,21
|
|
9
|
-
custom_python_logger-2.0.3.dist-info/RECORD,,
|
|
File without changes
|
{custom_python_logger-2.0.3.dist-info → custom_python_logger-2.0.4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|