custom-python-logger 2.0.4__tar.gz → 2.0.5__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.4/custom_python_logger.egg-info → custom_python_logger-2.0.5}/PKG-INFO +1 -1
  2. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger/logger.py +14 -12
  3. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger/usage_example.py +1 -0
  4. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5/custom_python_logger.egg-info}/PKG-INFO +1 -1
  5. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/setup.py +1 -1
  6. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/LICENSE +0 -0
  7. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/MANIFEST.in +0 -0
  8. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/README.md +0 -0
  9. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger/__init__.py +0 -0
  10. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger/consts.py +0 -0
  11. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger.egg-info/SOURCES.txt +0 -0
  12. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger.egg-info/dependency_links.txt +0 -0
  13. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger.egg-info/requires.txt +0 -0
  14. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/custom_python_logger.egg-info/top_level.txt +0 -0
  15. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/pyproject.toml +0 -0
  16. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/requirements.txt +0 -0
  17. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/setup.cfg +0 -0
  18. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/tests/test_logger.py +0 -0
  19. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/tests/test_logger_pytest.py +0 -0
  20. {custom_python_logger-2.0.4 → custom_python_logger-2.0.5}/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: 2.0.4
3
+ Version: 2.0.5
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 @@ 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
 
@@ -141,7 +140,7 @@ def build_logger(
141
140
  project_name: str,
142
141
  extra: dict[str, Any] | None = None,
143
142
  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.INFO,
143
+ log_level: int = logging.DEBUG,
145
144
  log_file: bool = False,
146
145
  log_file_path: str = None,
147
146
  console_output: bool = True,
@@ -167,21 +166,24 @@ def build_logger(
167
166
  log_file_path = log_file_path.lower().replace(" ", "_")
168
167
 
169
168
  configure_logging(
170
- log_level=logging.DEBUG,
171
169
  log_format=log_format,
172
170
  log_file=log_file,
173
171
  log_file_path=log_file_path,
174
172
  console_output=console_output,
175
173
  utc=utc,
176
174
  )
175
+ logger = CustomLoggerAdapter(logging.getLogger(CHILD_LOGGER), extra)
176
+ logger.setLevel(log_level)
177
177
 
178
- logger = logging.getLogger(project_name)
178
+ return logger
179
179
 
180
- if log_level is not None:
181
- logger.setLevel(log_level)
182
180
 
183
- return CustomLoggerAdapter(logger, extra)
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
184
 
185
+ if not log_level:
186
+ log_level = child_logger.level
187
+ new_logger.setLevel(log_level)
185
188
 
186
- def get_logger(name: str, extra: dict | None = None) -> CustomLoggerAdapter:
187
- return CustomLoggerAdapter(logging.getLogger(name), extra=extra)
189
+ return new_logger
@@ -6,6 +6,7 @@ from custom_python_logger import build_logger, get_logger
6
6
  class LoggerTest:
7
7
  def __init__(self) -> None:
8
8
  self.logger = get_logger(self.__class__.__name__, extra={"class": self.__class__.__name__})
9
+ print()
9
10
 
10
11
  def main(self) -> None:
11
12
  self.logger.debug("Hello World")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: custom-python-logger
3
- Version: 2.0.4
3
+ Version: 2.0.5
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,6 +1,6 @@
1
1
  from setuptools import find_packages, setup
2
2
 
3
- package_version = "2.0.4"
3
+ package_version = "2.0.5"
4
4
 
5
5
  package_name = "custom-python-logger"
6
6
  package_description = "A custom logger with color support and additional features."