custom-python-logger 2.0.4__tar.gz → 2.0.6__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.
- {custom_python_logger-2.0.4/custom_python_logger.egg-info → custom_python_logger-2.0.6}/PKG-INFO +1 -1
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger/__init__.py +2 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger/logger.py +18 -16
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6/custom_python_logger.egg-info}/PKG-INFO +1 -1
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger.egg-info/SOURCES.txt +0 -1
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/setup.py +1 -1
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/tests/test_usage_example_pytest.py +1 -1
- custom_python_logger-2.0.4/custom_python_logger/usage_example.py +0 -41
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/LICENSE +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/MANIFEST.in +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/README.md +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger/consts.py +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger.egg-info/dependency_links.txt +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger.egg-info/requires.txt +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger.egg-info/top_level.txt +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/pyproject.toml +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/requirements.txt +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/setup.cfg +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/tests/test_logger.py +0 -0
- {custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/tests/test_logger_pytest.py +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from custom_python_logger.logger import (
|
|
2
2
|
CustomLoggerAdapter,
|
|
3
|
+
CustomLoggerLevel,
|
|
3
4
|
build_logger,
|
|
4
5
|
get_logger,
|
|
5
6
|
json_pretty_format,
|
|
@@ -8,6 +9,7 @@ from custom_python_logger.logger import (
|
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
10
11
|
"CustomLoggerAdapter",
|
|
12
|
+
"CustomLoggerLevel",
|
|
11
13
|
"build_logger",
|
|
12
14
|
"get_logger",
|
|
13
15
|
"json_pretty_format",
|
|
@@ -12,6 +12,8 @@ from colorlog import ColoredFormatter
|
|
|
12
12
|
|
|
13
13
|
from custom_python_logger.consts import LOG_COLORS, CustomLoggerLevel
|
|
14
14
|
|
|
15
|
+
CHILD_LOGGER = "child_logger"
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
def json_pretty_format(data: Any, indent: int = 4, sort_keys: bool = True, default: Callable = None) -> str:
|
|
17
19
|
return json.dumps(data, indent=indent, sort_keys=sort_keys, default=default)
|
|
@@ -99,7 +101,6 @@ def add_console_handler_if_specified(logger: Logger, console_output: bool, log_f
|
|
|
99
101
|
def configure_logging(
|
|
100
102
|
log_format: str,
|
|
101
103
|
utc: bool,
|
|
102
|
-
log_level: int = logging.INFO,
|
|
103
104
|
log_file: bool = False,
|
|
104
105
|
log_file_path: str | None = None,
|
|
105
106
|
console_output: bool = True,
|
|
@@ -108,18 +109,16 @@ def configure_logging(
|
|
|
108
109
|
Configure global logging settings.
|
|
109
110
|
|
|
110
111
|
Args:
|
|
111
|
-
log_level: Logging level (default: INFO)
|
|
112
112
|
log_format: Format string for log messages
|
|
113
|
+
utc: Whether to use UTC time for log timestamps
|
|
113
114
|
log_file: Whether to log to a file
|
|
114
115
|
log_file_path: Path to log file (if None, no file logging)
|
|
115
116
|
console_output: Whether to output logs to console
|
|
116
|
-
utc: Whether to use UTC time for log timestamps
|
|
117
117
|
"""
|
|
118
118
|
if utc:
|
|
119
119
|
logging.Formatter.converter = time.gmtime
|
|
120
120
|
|
|
121
121
|
root_logger = logging.getLogger()
|
|
122
|
-
root_logger.setLevel(log_level)
|
|
123
122
|
|
|
124
123
|
clear_existing_handlers(logger=root_logger)
|
|
125
124
|
|
|
@@ -137,11 +136,22 @@ def configure_logging(
|
|
|
137
136
|
)
|
|
138
137
|
|
|
139
138
|
|
|
139
|
+
def get_logger(name: str, log_level: int | None = None, extra: dict | None = None) -> CustomLoggerAdapter:
|
|
140
|
+
child_logger = logging.getLogger(CHILD_LOGGER)
|
|
141
|
+
new_logger = CustomLoggerAdapter(logging.getLogger(name), extra=extra)
|
|
142
|
+
|
|
143
|
+
if not log_level:
|
|
144
|
+
log_level = child_logger.level
|
|
145
|
+
new_logger.setLevel(log_level)
|
|
146
|
+
|
|
147
|
+
return new_logger
|
|
148
|
+
|
|
149
|
+
|
|
140
150
|
def build_logger(
|
|
141
151
|
project_name: str,
|
|
142
152
|
extra: dict[str, Any] | None = None,
|
|
143
153
|
log_format: str = "%(asctime)s | %(levelname)-9s | l.%(levelno)s | %(name)s | %(filename)s:%(lineno)s | %(message)s", # pylint: disable=C0301
|
|
144
|
-
log_level: int = logging.
|
|
154
|
+
log_level: int = logging.DEBUG,
|
|
145
155
|
log_file: bool = False,
|
|
146
156
|
log_file_path: str = None,
|
|
147
157
|
console_output: bool = True,
|
|
@@ -167,21 +177,13 @@ def build_logger(
|
|
|
167
177
|
log_file_path = log_file_path.lower().replace(" ", "_")
|
|
168
178
|
|
|
169
179
|
configure_logging(
|
|
170
|
-
log_level=logging.DEBUG,
|
|
171
180
|
log_format=log_format,
|
|
172
181
|
log_file=log_file,
|
|
173
182
|
log_file_path=log_file_path,
|
|
174
183
|
console_output=console_output,
|
|
175
184
|
utc=utc,
|
|
176
185
|
)
|
|
186
|
+
logger = CustomLoggerAdapter(logging.getLogger(CHILD_LOGGER), extra)
|
|
187
|
+
logger.setLevel(log_level)
|
|
177
188
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if log_level is not None:
|
|
181
|
-
logger.setLevel(log_level)
|
|
182
|
-
|
|
183
|
-
return CustomLoggerAdapter(logger, extra)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
def get_logger(name: str, extra: dict | None = None) -> CustomLoggerAdapter:
|
|
187
|
-
return CustomLoggerAdapter(logging.getLogger(name), extra=extra)
|
|
189
|
+
return get_logger(project_name)
|
{custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger.egg-info/SOURCES.txt
RENAMED
|
@@ -7,7 +7,6 @@ setup.py
|
|
|
7
7
|
custom_python_logger/__init__.py
|
|
8
8
|
custom_python_logger/consts.py
|
|
9
9
|
custom_python_logger/logger.py
|
|
10
|
-
custom_python_logger/usage_example.py
|
|
11
10
|
custom_python_logger.egg-info/PKG-INFO
|
|
12
11
|
custom_python_logger.egg-info/SOURCES.txt
|
|
13
12
|
custom_python_logger.egg-info/dependency_links.txt
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
|
|
3
|
-
from custom_python_logger import build_logger, get_logger
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class LoggerTest:
|
|
7
|
-
def __init__(self) -> None:
|
|
8
|
-
self.logger = get_logger(self.__class__.__name__, extra={"class": self.__class__.__name__})
|
|
9
|
-
|
|
10
|
-
def main(self) -> None:
|
|
11
|
-
self.logger.debug("Hello World")
|
|
12
|
-
self.logger.info("Hello World")
|
|
13
|
-
self.logger.step("Hello World")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def main() -> None:
|
|
17
|
-
logger = build_logger(
|
|
18
|
-
project_name="Logger Project Test",
|
|
19
|
-
log_level=logging.DEBUG,
|
|
20
|
-
log_file=True,
|
|
21
|
-
# extra={'user': 'test_user'}
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
logger.debug("This is a debug message.")
|
|
25
|
-
logger.info("This is an info message.")
|
|
26
|
-
logger.step("This is a step message.")
|
|
27
|
-
logger.warning("This is a warning message.")
|
|
28
|
-
|
|
29
|
-
try:
|
|
30
|
-
_ = 1 / 0
|
|
31
|
-
except ZeroDivisionError:
|
|
32
|
-
logger.exception("This is an exception message.")
|
|
33
|
-
|
|
34
|
-
logger.critical("This is a critical message.")
|
|
35
|
-
|
|
36
|
-
logger_test = LoggerTest()
|
|
37
|
-
logger_test.main()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if __name__ == "__main__":
|
|
41
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{custom_python_logger-2.0.4 → custom_python_logger-2.0.6}/custom_python_logger.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|