custom-python-logger 2.0.5__tar.gz → 2.0.7__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.
Files changed (20) hide show
  1. {custom_python_logger-2.0.5/custom_python_logger.egg-info → custom_python_logger-2.0.7}/PKG-INFO +1 -1
  2. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger/__init__.py +2 -0
  3. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger/consts.py +7 -0
  4. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger/logger.py +30 -14
  5. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7/custom_python_logger.egg-info}/PKG-INFO +1 -1
  6. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger.egg-info/SOURCES.txt +0 -1
  7. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/setup.py +1 -1
  8. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/tests/test_usage_example_pytest.py +1 -1
  9. custom_python_logger-2.0.5/custom_python_logger/usage_example.py +0 -42
  10. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/LICENSE +0 -0
  11. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/MANIFEST.in +0 -0
  12. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/README.md +0 -0
  13. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger.egg-info/dependency_links.txt +0 -0
  14. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger.egg-info/requires.txt +0 -0
  15. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/custom_python_logger.egg-info/top_level.txt +0 -0
  16. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/pyproject.toml +0 -0
  17. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/requirements.txt +0 -0
  18. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/setup.cfg +0 -0
  19. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/tests/test_logger.py +0 -0
  20. {custom_python_logger-2.0.5 → custom_python_logger-2.0.7}/tests/test_logger_pytest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: custom-python-logger
3
- Version: 2.0.5
3
+ Version: 2.0.7
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
@@ -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",
@@ -8,9 +8,16 @@ LOG_COLORS = {
8
8
  "ERROR": "red,bold",
9
9
  "EXCEPTION": "light_red,bold",
10
10
  "CRITICAL": "red,bg_white",
11
+ "SUCCESS": "bold_green",
12
+ "FATAL": "red,bg_white",
13
+ "ALERT": "bold_yellow",
14
+ "TRACE": "bold_cyan",
11
15
  }
12
16
 
13
17
 
14
18
  class CustomLoggerLevel(Enum):
15
19
  EXCEPTION = 45
16
20
  STEP = 25
21
+ SUCCESS = 26
22
+ ALERT = 35
23
+ TRACE = 15
@@ -12,7 +12,7 @@ from colorlog import ColoredFormatter
12
12
 
13
13
  from custom_python_logger.consts import LOG_COLORS, CustomLoggerLevel
14
14
 
15
- CHILD_LOGGER = "child_logger"
15
+ CUSTOM_LOGGER = "custom_logger"
16
16
 
17
17
 
18
18
  def json_pretty_format(data: Any, indent: int = 4, sort_keys: bool = True, default: Callable = None) -> str:
@@ -60,6 +60,21 @@ class CustomLoggerAdapter(logging.LoggerAdapter):
60
60
  kwargs.setdefault("stacklevel", 2)
61
61
  self.log(CustomLoggerLevel.STEP.value, msg, *args, exc_info=False, **kwargs)
62
62
 
63
+ def success(self, msg: str, *args, **kwargs) -> None:
64
+ logging.addLevelName(CustomLoggerLevel.SUCCESS.value, "SUCCESS")
65
+ kwargs.setdefault("stacklevel", 2)
66
+ self.log(CustomLoggerLevel.SUCCESS.value, msg, *args, **kwargs)
67
+
68
+ def alert(self, msg: str, *args, **kwargs) -> None:
69
+ logging.addLevelName(CustomLoggerLevel.ALERT.value, "ALERT")
70
+ kwargs.setdefault("stacklevel", 2)
71
+ self.log(CustomLoggerLevel.ALERT.value, msg, *args, **kwargs)
72
+
73
+ def trace(self, msg: str, *args, **kwargs) -> None:
74
+ logging.addLevelName(CustomLoggerLevel.TRACE.value, "TRACE")
75
+ kwargs.setdefault("stacklevel", 2)
76
+ self.log(CustomLoggerLevel.TRACE.value, msg, *args, **kwargs)
77
+
63
78
 
64
79
  def clear_existing_handlers(logger: Logger) -> None:
65
80
  for handler in logger.handlers[:]:
@@ -136,6 +151,18 @@ def configure_logging(
136
151
  )
137
152
 
138
153
 
154
+ def get_logger(name: str, log_level: int | None = None, extra: dict | None = None) -> CustomLoggerAdapter:
155
+ custom_logger = logging.getLogger(CUSTOM_LOGGER)
156
+ full_name = f"{CUSTOM_LOGGER}.{name}"
157
+ new_logger = CustomLoggerAdapter(logging.getLogger(full_name), extra=extra)
158
+
159
+ if not log_level:
160
+ log_level = custom_logger.level
161
+ new_logger.setLevel(log_level)
162
+
163
+ return new_logger
164
+
165
+
139
166
  def build_logger(
140
167
  project_name: str,
141
168
  extra: dict[str, Any] | None = None,
@@ -172,18 +199,7 @@ def build_logger(
172
199
  console_output=console_output,
173
200
  utc=utc,
174
201
  )
175
- logger = CustomLoggerAdapter(logging.getLogger(CHILD_LOGGER), extra)
202
+ logger = CustomLoggerAdapter(logging.getLogger(CUSTOM_LOGGER), extra)
176
203
  logger.setLevel(log_level)
177
204
 
178
- return logger
179
-
180
-
181
- def get_logger(name: str, log_level: int | None = None, extra: dict | None = None) -> CustomLoggerAdapter:
182
- child_logger = logging.getLogger(CHILD_LOGGER)
183
- new_logger = CustomLoggerAdapter(logging.getLogger(name), extra=extra)
184
-
185
- if not log_level:
186
- log_level = child_logger.level
187
- new_logger.setLevel(log_level)
188
-
189
- return new_logger
205
+ return get_logger(project_name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: custom-python-logger
3
- Version: 2.0.5
3
+ Version: 2.0.7
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
@@ -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,6 +1,6 @@
1
1
  from setuptools import find_packages, setup
2
2
 
3
- package_version = "2.0.5"
3
+ package_version = "2.0.7"
4
4
 
5
5
  package_name = "custom-python-logger"
6
6
  package_description = "A custom logger with color support and additional features."
@@ -1,4 +1,4 @@
1
- from custom_python_logger.usage_example import main
1
+ from usage_example.example_1 import main
2
2
 
3
3
 
4
4
  def test_usage_example_runs(monkeypatch):
@@ -1,42 +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
- print()
10
-
11
- def main(self) -> None:
12
- self.logger.debug("Hello World")
13
- self.logger.info("Hello World")
14
- self.logger.step("Hello World")
15
-
16
-
17
- def main() -> None:
18
- logger = build_logger(
19
- project_name="Logger Project Test",
20
- log_level=logging.DEBUG,
21
- log_file=True,
22
- # extra={'user': 'test_user'}
23
- )
24
-
25
- logger.debug("This is a debug message.")
26
- logger.info("This is an info message.")
27
- logger.step("This is a step message.")
28
- logger.warning("This is a warning message.")
29
-
30
- try:
31
- _ = 1 / 0
32
- except ZeroDivisionError:
33
- logger.exception("This is an exception message.")
34
-
35
- logger.critical("This is a critical message.")
36
-
37
- logger_test = LoggerTest()
38
- logger_test.main()
39
-
40
-
41
- if __name__ == "__main__":
42
- main()