python-coloured-logger 1.0.2__tar.gz → 1.0.3__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.
@@ -1,9 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-coloured-logger
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Simple coloured logging for Flask and FastAPI apps
5
5
  Author: Skulldorom
6
6
  License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Skulldorom/python-coloured-logger
8
+ Project-URL: Repository, https://github.com/Skulldorom/python-coloured-logger
9
+ Project-URL: Issues, https://github.com/Skulldorom/python-coloured-logger/issues
7
10
  Keywords: logging,flask,fastapi,color
8
11
  Classifier: Programming Language :: Python :: 3
9
12
  Classifier: Programming Language :: Python :: 3 :: Only
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-coloured-logger"
7
- version = "1.0.2"
7
+ version = "1.0.3"
8
8
  description = "Simple coloured logging for Flask and FastAPI apps"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -18,6 +18,11 @@ classifiers = [
18
18
  "Operating System :: OS Independent",
19
19
  ]
20
20
 
21
+ [project.urls]
22
+ Homepage = "https://github.com/Skulldorom/python-coloured-logger"
23
+ Repository = "https://github.com/Skulldorom/python-coloured-logger"
24
+ Issues = "https://github.com/Skulldorom/python-coloured-logger/issues"
25
+
21
26
  [tool.setuptools]
22
27
  package-dir = { "" = "src" }
23
28
 
@@ -26,3 +31,10 @@ package-dir = { "" = "src" }
26
31
 
27
32
  [tool.setuptools.packages.find]
28
33
  where = ["src"]
34
+
35
+ [tool.mypy]
36
+ strict = true
37
+ python_version = "3.8"
38
+ files = ["src"]
39
+ warn_unused_ignores = true
40
+ warn_redundant_casts = true
@@ -0,0 +1,10 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ from .formatter import ColouredFormatter, SUCCESS_LEVEL, get_logger, log, setup_logging
4
+
5
+ try:
6
+ __version__ = version("python-coloured-logger")
7
+ except PackageNotFoundError:
8
+ __version__ = "unknown"
9
+
10
+ __all__ = ["ColouredFormatter", "SUCCESS_LEVEL", "get_logger", "log", "setup_logging", "__version__"]
@@ -4,6 +4,8 @@ from typing import Optional, TextIO
4
4
 
5
5
  SUCCESS_LEVEL = 25
6
6
 
7
+ _success_level_registered: bool = False
8
+
7
9
 
8
10
  def _env_bool(name: str, default: bool) -> bool:
9
11
  value = os.getenv(name)
@@ -60,6 +62,10 @@ class ColouredFormatter(logging.Formatter):
60
62
 
61
63
 
62
64
  def _ensure_success_level() -> None:
65
+ global _success_level_registered
66
+ if _success_level_registered:
67
+ return
68
+
63
69
  if logging.getLevelName(SUCCESS_LEVEL) != "SUCCESS":
64
70
  logging.addLevelName(SUCCESS_LEVEL, "SUCCESS")
65
71
 
@@ -71,6 +77,7 @@ def _ensure_success_level() -> None:
71
77
  self._log(SUCCESS_LEVEL, msg, args, **kwargs)
72
78
 
73
79
  setattr(logging.Logger, "success", success)
80
+ _success_level_registered = True
74
81
 
75
82
 
76
83
  def setup_logging(
@@ -1,9 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-coloured-logger
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Simple coloured logging for Flask and FastAPI apps
5
5
  Author: Skulldorom
6
6
  License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Skulldorom/python-coloured-logger
8
+ Project-URL: Repository, https://github.com/Skulldorom/python-coloured-logger
9
+ Project-URL: Issues, https://github.com/Skulldorom/python-coloured-logger/issues
7
10
  Keywords: logging,flask,fastapi,color
8
11
  Classifier: Programming Language :: Python :: 3
9
12
  Classifier: Programming Language :: Python :: 3 :: Only
@@ -60,11 +60,16 @@ class ColouredFormatterTests(unittest.TestCase):
60
60
 
61
61
  def test_default_message_format(self):
62
62
  formatter = ColouredFormatter(use_color=False)
63
- self.assertEqual(formatter._fmt, "[%(asctime)s] [%(levelname)s] %(message)s")
63
+ record = logging.LogRecord("test", logging.INFO, __file__, 1, "hello world", (), None)
64
+ output = formatter.format(record)
65
+ self.assertIn("[INFO] hello world", output)
66
+ self.assertNotIn("\033[", output)
64
67
 
65
68
  def test_custom_message_format(self):
66
69
  formatter = ColouredFormatter(fmt="%(levelname)s: %(message)s", use_color=False)
67
- self.assertEqual(formatter._fmt, "%(levelname)s: %(message)s")
70
+ record = logging.LogRecord("test", logging.ERROR, __file__, 1, "oops", (), None)
71
+ output = formatter.format(record)
72
+ self.assertEqual(output, "ERROR: oops")
68
73
 
69
74
 
70
75
  class SetupLoggingTests(unittest.TestCase):
@@ -1,3 +0,0 @@
1
- from .formatter import ColouredFormatter, SUCCESS_LEVEL, get_logger, log, setup_logging
2
-
3
- __all__ = ["ColouredFormatter", "SUCCESS_LEVEL", "get_logger", "log", "setup_logging"]