pipu-cli 0.1.dev0__py3-none-any.whl

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.
pipu_cli/__init__.py ADDED
@@ -0,0 +1,49 @@
1
+ import logging
2
+ from .config import LOG_LEVEL
3
+
4
+ __version__ = '0.1.dev0'
5
+
6
+
7
+ # Configure logging
8
+ log = logging.getLogger("pipu")
9
+
10
+
11
+ class LevelSpecificFormatter(logging.Formatter):
12
+ """
13
+ A logging formatter that prefexes every level but INFO
14
+ """
15
+ NORMAL_FORMAT = "%(message)s"
16
+ LEVEL_SPECIFIC_FORMAT = "%(levelname)s: %(message)s"
17
+
18
+ def __init__(self):
19
+ super().__init__(fmt=self.NORMAL_FORMAT, datefmt=None, style='%')
20
+
21
+ def format(self, record: logging.LogRecord) -> str:
22
+ """
23
+ Format a log record based on the log level.
24
+
25
+ :param record: Record to format
26
+ :returns: Formatted record string
27
+ """
28
+ if record.levelno == logging.INFO:
29
+ self._style._fmt = self.NORMAL_FORMAT
30
+ else:
31
+ self._style._fmt = self.LEVEL_SPECIFIC_FORMAT
32
+
33
+ # Call the original formatter class to do the grunt work
34
+ result = logging.Formatter.format(self, record)
35
+
36
+ return result
37
+
38
+
39
+ ############################
40
+ # Configure the logger
41
+ ############################
42
+
43
+ ch = logging.StreamHandler()
44
+ ch.setLevel(LOG_LEVEL)
45
+
46
+ ch.setFormatter(LevelSpecificFormatter())
47
+ log.addHandler(ch)
48
+
49
+ log.setLevel(LOG_LEVEL)