custom-python-logger 2.0.2__tar.gz → 2.0.4__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 (22) hide show
  1. {custom_python_logger-2.0.2/custom_python_logger.egg-info → custom_python_logger-2.0.4}/PKG-INFO +3 -1
  2. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger/logger.py +20 -24
  3. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger/usage_example.py +3 -3
  4. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4/custom_python_logger.egg-info}/PKG-INFO +3 -1
  5. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger.egg-info/requires.txt +2 -0
  6. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/requirements.txt +2 -0
  7. custom_python_logger-2.0.4/setup.py +35 -0
  8. custom_python_logger-2.0.4/tests/test_logger.py +27 -0
  9. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/tests/test_logger_pytest.py +8 -21
  10. custom_python_logger-2.0.2/setup.py +0 -37
  11. custom_python_logger-2.0.2/tests/test_logger.py +0 -26
  12. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/LICENSE +0 -0
  13. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/MANIFEST.in +0 -0
  14. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/README.md +0 -0
  15. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger/__init__.py +0 -0
  16. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger/consts.py +0 -0
  17. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger.egg-info/SOURCES.txt +0 -0
  18. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger.egg-info/dependency_links.txt +0 -0
  19. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/custom_python_logger.egg-info/top_level.txt +0 -0
  20. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/pyproject.toml +0 -0
  21. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/setup.cfg +0 -0
  22. {custom_python_logger-2.0.2 → custom_python_logger-2.0.4}/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.2
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
@@ -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, Callable, Optional
8
+ from typing import Any
8
9
 
9
10
  import yaml
10
11
  from colorlog import ColoredFormatter
@@ -12,24 +13,23 @@ 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: Any, indent: int = 4, sort_keys: bool = False, allow_unicode=True
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: Optional[list[str]] = None) -> Path:
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
- path = Path(__file__).resolve()
27
+ path = Path(__file__).resolve() if "__file__" in globals() else Path.cwd().resolve()
28
+
29
+ for marker in markers:
30
+ if (path / marker).exists():
31
+ return path
32
+
33
33
  for parent in path.parents:
34
34
  for marker in markers:
35
35
  if (parent / marker).exists():
@@ -48,12 +48,12 @@ def print_before_logger(project_name: str) -> None:
48
48
 
49
49
 
50
50
  class CustomLoggerAdapter(logging.LoggerAdapter):
51
- def exception(self, msg: str, *args, **kwargs):
51
+ def exception(self, msg: str, *args: Any, **kwargs: Any) -> None:
52
52
  logging.addLevelName(CustomLoggerLevel.EXCEPTION.value, "EXCEPTION")
53
53
  kwargs.setdefault("stacklevel", 2)
54
54
  self.log(CustomLoggerLevel.EXCEPTION.value, msg, *args, exc_info=True, **kwargs)
55
55
 
56
- def step(self, msg: str, *args, **kwargs):
56
+ def step(self, msg: str, *args: Any, **kwargs: Any) -> None:
57
57
  logging.addLevelName(CustomLoggerLevel.STEP.value, "STEP")
58
58
  kwargs.setdefault("stacklevel", 2)
59
59
  self.log(CustomLoggerLevel.STEP.value, msg, *args, exc_info=False, **kwargs)
@@ -67,7 +67,7 @@ def clear_existing_handlers(logger: Logger) -> None:
67
67
  def add_file_handler_if_specified(
68
68
  logger: Logger,
69
69
  log_file: bool,
70
- log_file_path: Optional[str],
70
+ log_file_path: str | None,
71
71
  log_format: str,
72
72
  ) -> None:
73
73
  if log_file and log_file_path is not None:
@@ -84,11 +84,7 @@ def add_file_handler_if_specified(
84
84
  logger.addHandler(file_handler)
85
85
 
86
86
 
87
- def add_console_handler_if_specified(
88
- logger: Logger,
89
- console_output: bool,
90
- log_format: str
91
- ):
87
+ def add_console_handler_if_specified(logger: Logger, console_output: bool, log_format: str) -> None:
92
88
  if console_output:
93
89
  log_console_formatter = ColoredFormatter(
94
90
  "%(log_color)s " + log_format,
@@ -105,7 +101,7 @@ def configure_logging(
105
101
  utc: bool,
106
102
  log_level: int = logging.INFO,
107
103
  log_file: bool = False,
108
- log_file_path: Optional[str] = None,
104
+ log_file_path: str | None = None,
109
105
  console_output: bool = True,
110
106
  ) -> None:
111
107
  """
@@ -143,8 +139,8 @@ def configure_logging(
143
139
 
144
140
  def build_logger(
145
141
  project_name: str,
146
- extra: Optional[dict[str, Any]] = None,
147
- 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
148
144
  log_level: int = logging.INFO,
149
145
  log_file: bool = False,
150
146
  log_file_path: str = None,
@@ -187,5 +183,5 @@ def build_logger(
187
183
  return CustomLoggerAdapter(logger, extra)
188
184
 
189
185
 
190
- def get_logger(name: str, extra: Optional[dict] = None) -> CustomLoggerAdapter:
186
+ def get_logger(name: str, extra: dict | None = None) -> CustomLoggerAdapter:
191
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.2
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
@@ -1,6 +1,8 @@
1
1
  setuptools
2
2
  wheel
3
3
  colorlog
4
+ python-dotenv
5
+ pre-commit
4
6
  pytest
5
7
  pathlib
6
8
  PyYAML
@@ -1,6 +1,8 @@
1
1
  setuptools
2
2
  wheel
3
3
  colorlog
4
+ python-dotenv
5
+ pre-commit
4
6
  pytest
5
7
  pathlib
6
8
  PyYAML
@@ -0,0 +1,35 @@
1
+ from setuptools import find_packages, setup
2
+
3
+ package_version = "2.0.4"
4
+
5
+ package_name = "custom-python-logger"
6
+ package_description = "A custom logger with color support and additional features."
7
+
8
+ package_name_ = package_name.replace("-", "_")
9
+ package_long_description_content_type = "text/markdown"
10
+ package_url = f"https://github.com/aviz92/{package_name}"
11
+ package_python_requires = ">=3.11"
12
+ package_author = "Avi Zaguri"
13
+
14
+ with open("requirements.txt") as file:
15
+ package_install_requires = [line.strip() for line in file.readlines() if line.strip() and not line.startswith("#")]
16
+
17
+ with open("README.md") as file:
18
+ package_long_description = file.read()
19
+
20
+ setup(
21
+ name=package_name,
22
+ version=package_version,
23
+ packages=find_packages(include=[package_name_, f"{package_name_}.*"]),
24
+ install_requires=package_install_requires,
25
+ author=package_author,
26
+ author_email="",
27
+ description=package_description,
28
+ long_description=package_long_description,
29
+ long_description_content_type=package_long_description_content_type,
30
+ url=package_url,
31
+ project_urls={
32
+ "Repository": package_url,
33
+ },
34
+ python_requires=package_python_requires,
35
+ )
@@ -0,0 +1,27 @@
1
+ import unittest
2
+
3
+ from custom_python_logger import build_logger
4
+
5
+
6
+ class TestLogger(unittest.TestCase):
7
+ def test_logger_creation(self):
8
+ logger = build_logger(project_name="TestProject")
9
+ self.assertIsNotNone(logger)
10
+ self.assertEqual(logger.name, "root")
11
+
12
+ def test_step_log(self):
13
+ logger = build_logger(project_name="TestProject")
14
+ logger.step("Testing step log")
15
+ self.assertTrue(True) # pylint: disable=W1503
16
+
17
+ def test_exception_log(self):
18
+ logger = build_logger(project_name="TestProject")
19
+ try:
20
+ raise ValueError("Test exception")
21
+ except ValueError as e:
22
+ logger.exception(f"Exception occurred: {e}")
23
+ self.assertTrue(True) # pylint: disable=W1503
24
+
25
+
26
+ if __name__ == "__main__":
27
+ unittest.main()
@@ -1,17 +1,12 @@
1
+ import datetime
1
2
  import logging
2
3
  import os
3
4
  import tempfile
4
5
  import time
5
- from datetime import timezone
6
6
 
7
7
  import pytest
8
8
 
9
- from custom_python_logger import (
10
- CustomLoggerAdapter,
11
- build_logger,
12
- json_pretty_format,
13
- yaml_pretty_format,
14
- )
9
+ from custom_python_logger import CustomLoggerAdapter, build_logger, json_pretty_format, yaml_pretty_format
15
10
 
16
11
 
17
12
  @pytest.fixture
@@ -76,10 +71,8 @@ def test_exception_log_2(caplog):
76
71
  assert any("EXCEPTION" in r.levelname for r in caplog.records)
77
72
 
78
73
 
79
- def test_log_to_file(temp_log_file):
80
- logger = build_logger(
81
- project_name="FileTest", log_file=True, log_file_path=temp_log_file
82
- )
74
+ def test_log_to_file(temp_log_file): # pylint: disable=W0621
75
+ logger = build_logger(project_name="FileTest", log_file=True, log_file_path=temp_log_file)
83
76
  logger.info("File log message")
84
77
  time.sleep(0.1)
85
78
  with open(temp_log_file) as f:
@@ -87,26 +80,20 @@ def test_log_to_file(temp_log_file):
87
80
  assert "File log message" in content
88
81
 
89
82
 
90
- def test_utc_logging(temp_log_file):
91
- logger = build_logger(
92
- project_name="UTCTest", log_file=True, log_file_path=temp_log_file, utc=True
93
- )
83
+ def test_utc_logging(temp_log_file): # pylint: disable=W0621
84
+ logger = build_logger(project_name="UTCTest", log_file=True, log_file_path=temp_log_file, utc=True)
94
85
  logger.info("UTC log message")
95
86
  time.sleep(0.1)
96
87
  with open(temp_log_file) as f:
97
88
  content = f.read()
98
89
  assert "UTC log message" in content
99
90
  # Check for a year in UTC (should be close to now)
100
- import datetime
101
-
102
- now_utc = datetime.datetime.now(tz=timezone.utc).strftime("%Y")
91
+ now_utc = datetime.datetime.now(tz=datetime.UTC).strftime("%Y")
103
92
  assert now_utc in content
104
93
 
105
94
 
106
95
  def test_extra_context(caplog):
107
- logger = build_logger(
108
- project_name="ExtraTest", extra={"user": "pytest"}, console_output=False
109
- )
96
+ logger = build_logger(project_name="ExtraTest", extra={"user": "pytest"}, console_output=False)
110
97
  logging.getLogger().addHandler(caplog.handler)
111
98
  with caplog.at_level(logging.INFO):
112
99
  logger.info("With extra")
@@ -1,37 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
- package_version = '2.0.2'
4
-
5
- package_name = 'custom-python-logger'
6
- package_description = 'A custom logger with color support and additional features.'
7
-
8
- package_name_ = package_name.replace('-', '_')
9
- package_long_description_content_type = 'text/markdown'
10
- package_url = f'https://github.com/aviz92/{package_name}'
11
- package_python_requires = '>=3.11'
12
- package_author = 'Avi Zaguri'
13
-
14
- with open('requirements.txt', 'r') as file:
15
- package_install_requires = [
16
- line.strip() for line in file.readlines() if line.strip() and not line.startswith('#')
17
- ]
18
-
19
- with open('README.md', 'r') as file:
20
- package_long_description = file.read()
21
-
22
- setup(
23
- name=package_name,
24
- version=package_version,
25
- packages=find_packages(include=[package_name_, f'{package_name_}.*']),
26
- install_requires=package_install_requires,
27
- author=package_author,
28
- author_email='',
29
- description=package_description,
30
- long_description=package_long_description,
31
- long_description_content_type=package_long_description_content_type,
32
- url=package_url,
33
- project_urls={
34
- 'Repository': package_url,
35
- },
36
- python_requires=package_python_requires,
37
- )
@@ -1,26 +0,0 @@
1
- import unittest
2
- from custom_python_logger import build_logger
3
-
4
-
5
- class TestLogger(unittest.TestCase):
6
- def test_logger_creation(self):
7
- logger = build_logger(project_name='TestProject')
8
- self.assertIsNotNone(logger)
9
- self.assertEqual(logger.name, 'root')
10
-
11
- def test_step_log(self):
12
- logger = build_logger(project_name='TestProject')
13
- logger.step('Testing step log')
14
- self.assertTrue(True) # You can add more specific checks for actual logging output
15
-
16
- def test_exception_log(self):
17
- logger = build_logger(project_name='TestProject')
18
- try:
19
- raise ValueError("Test exception")
20
- except ValueError as e:
21
- logger.exception(f"Exception occurred: {e}")
22
- self.assertTrue(True) # You can add more specific checks for actual logging output
23
-
24
-
25
- if __name__ == '__main__':
26
- unittest.main()