custom-python-logger 4.0.0__tar.gz → 4.0.2__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 (18) hide show
  1. {custom_python_logger-4.0.0/custom_python_logger.egg-info → custom_python_logger-4.0.2}/PKG-INFO +1 -1
  2. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger/consts.py +3 -1
  3. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger/logger.py +14 -3
  4. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2/custom_python_logger.egg-info}/PKG-INFO +1 -1
  5. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/pyproject.toml +1 -1
  6. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/LICENSE +0 -0
  7. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/MANIFEST.in +0 -0
  8. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/README.md +0 -0
  9. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger/__init__.py +0 -0
  10. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger.egg-info/SOURCES.txt +0 -0
  11. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger.egg-info/dependency_links.txt +0 -0
  12. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger.egg-info/requires.txt +0 -0
  13. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/custom_python_logger.egg-info/top_level.txt +0 -0
  14. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/setup.cfg +0 -0
  15. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/tests/test_logger.py +0 -0
  16. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/tests/test_logger_pytest.py +0 -0
  17. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/tests/test_short_path_filter.py +0 -0
  18. {custom_python_logger-4.0.0 → custom_python_logger-4.0.2}/tests/test_usage_example_pytest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: custom-python-logger
3
- Version: 4.0.0
3
+ Version: 4.0.2
4
4
  Summary: A custom logger with color support and additional features.
5
5
  Author: Avi Zaguri
6
6
  License: MIT
@@ -1,6 +1,8 @@
1
1
  from enum import Enum
2
2
 
3
- LOG_FORMAT_FILENAME = "%(asctime)s | %(levelname)-9s | l.%(levelno)s | %(name)s | %(filename)s:%(lineno)s | %(message)s"
3
+ LOG_FORMAT_FILENAME = (
4
+ "%(asctime)s | %(levelname)-9s | l.%(levelno)s | %(name)s | %(filename)s:%(funcName)s:%(lineno)d | %(message)s"
5
+ )
4
6
  LOG_FORMAT_SHORTPATH = (
5
7
  "%(asctime)s | %(levelname)-9s | l.%(levelno)s | %(name)s | %(shortpath)s:%(lineno)s | %(message)s"
6
8
  )
@@ -10,7 +10,7 @@ from typing import Any
10
10
  import yaml
11
11
  from colorlog import ColoredFormatter
12
12
 
13
- from custom_python_logger.consts import LOG_COLORS, LOG_FORMAT_SHORTPATH, CustomLoggerLevel
13
+ from custom_python_logger.consts import LOG_COLORS, LOG_FORMAT_FILENAME, CustomLoggerLevel
14
14
 
15
15
  CUSTOM_LOGGER = "custom_logger"
16
16
 
@@ -64,6 +64,14 @@ class _ShortPathFilter(logging.Filter):
64
64
  return True
65
65
 
66
66
 
67
+ class _StripNamespaceFilter(logging.Filter):
68
+ def filter(self, record: logging.LogRecord) -> bool:
69
+ prefix = CUSTOM_LOGGER + "."
70
+ if record.name.startswith(prefix):
71
+ record.name = record.name[len(prefix) :]
72
+ return True
73
+
74
+
67
75
  class CustomLoggerAdapter(logging.LoggerAdapter):
68
76
  def exception(self, msg: str, *args: Any, **kwargs: Any) -> None:
69
77
  logging.addLevelName(CustomLoggerLevel.EXCEPTION.value, "EXCEPTION")
@@ -121,8 +129,11 @@ def add_console_handler(logger: Logger, log_format: str) -> None:
121
129
 
122
130
  def get_logger(name: str, log_level: int | None = None, extra: dict | None = None) -> CustomLoggerAdapter:
123
131
  custom_logger = logging.getLogger(CUSTOM_LOGGER)
132
+
124
133
  full_name = f"{CUSTOM_LOGGER}.{name}"
125
- new_logger = CustomLoggerAdapter(logging.getLogger(full_name), extra=extra)
134
+ underlying = logging.getLogger(full_name)
135
+ underlying.addFilter(_StripNamespaceFilter())
136
+ new_logger = CustomLoggerAdapter(underlying, extra=extra)
126
137
 
127
138
  if log_level is None:
128
139
  log_level = custom_logger.level
@@ -134,7 +145,7 @@ def get_logger(name: str, log_level: int | None = None, extra: dict | None = Non
134
145
  def build_logger( # pylint: disable=R0913
135
146
  project_name: str,
136
147
  extra: dict[str, Any] | None = None,
137
- log_format: str = LOG_FORMAT_SHORTPATH,
148
+ log_format: str = LOG_FORMAT_FILENAME,
138
149
  log_level: int = logging.DEBUG,
139
150
  log_file: bool = False,
140
151
  log_file_path: str | None = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: custom-python-logger
3
- Version: 4.0.0
3
+ Version: 4.0.2
4
4
  Summary: A custom logger with color support and additional features.
5
5
  Author: Avi Zaguri
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "custom-python-logger"
7
- version = "4.0.0"
7
+ version = "4.0.2"
8
8
  description = "A custom logger with color support and additional features."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"