Skip to content

Commit 3bbbee2

Browse files
committed
use IGNORE_FORMATTER as a flag
1 parent dc5c96c commit 3bbbee2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ As soon as your handler was attached, the log records will be catched within a b
7676
| `LEVEL_COLORS` | `dict` | A dictionary with corresponding colors to the defined `LOG_LEVELS`. Expects RGB values from 0-255 and an optional alpha value from 0-100. default: ` "debug": (255, 255, 255, 100), "info": (204, 236, 242, 100), "warning": (152, 210, 217, 100), "error": (223, 57, 57, 100), "critical": (182, 60, 66, 100)}`
7777
| `INITIAL_FILTER_REGEX` | `str` | A regular expression that will be used when launching the logbook.
7878
| `INITIAL_COLORING` | `bool` | If `True` coloring mode will be enabled by default when launching the logbook.
79-
| `IGNORE_FORMATTER` | `bool` | If a formatter was set to the handler, it can be explicitly ignored by setting this to `True`. This means, the formatter will not be considered as the recorditem's text. Instead it will only use the `LogRecord.msg` directly.
8079
| `EXCEPTION_FORMATTER` | `logging.Formatter` | A formatter instance that will be used to format the `exc_info` tuple that will be dispayed inside the ToolTips of recorditems.
8180

8281
| Flag | Description
8382
|:--------------------------|:-----------
8483
| `COLORING_TEXT` | When given the item's foreground color will be set instead of the background color.
84+
| `IGNORE_FORMATTER` | If a formatter was set to the handler, it can be explicitly ignored by setting using this. It means, the formatter will not be considered as the recorditem's text. Instead it will only use the `LogRecord.getMessage()` directly.
8585
| `INITIAL_COLORING` | When given the `Coloring` option will be checked by default when launching the logbook.
8686
| `READABLE_TEXT_COLOR` | When given and `COLORING_TEXT` is NOT set it sets an automatic item foreground color based on the background color for better readability.
87-
| `RE_IGNORE_CASE` | When given the `Ignore Case` option will be checked by default when launching the logbook.
87+
| `RE_IGNORE_CASE` | When given the `Ignore Case` option will be checked by default when launching the logbook.
8888

8989
This examples activates coloring of item's foreground color instead of background color.
9090
```python
@@ -94,7 +94,7 @@ LogbookWidget.FLAGS = LogbookWidget.Flags.INITIAL_COLORING | LogbookWidget.Flags
9494
<img src="https://github.com/rkoschmitzky/logbook/blob/master/.graphics/text_coloring.gif" width="400">
9595

9696
#### Recorditems Formatting
97-
By default the logbook handlers doesn't use a formatting. It will use the `LogRecord.msg` attribute as the recorditem's text.
97+
By default, the logbook handlers doesn't use a formatter. It will use the `LogRecord.getMessage()` attribute as the recorditem's text.
9898
A formatter can be set easily by using the `handler` property on the logbook instance.
9999

100100
```python

widget.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,18 @@ class LogbookWidget(QtWidgets.QWidget):
9494
""" A simple widget that makes log reading more pleasant. """
9595

9696
class Flags:
97+
# sets the `Coloring` checkbox on launch
9798
INITIAL_COLORING = 2**1
99+
# defines whether background color or foreground color (text) of an item will be set
98100
COLORING_TEXT = 2**2
101+
# if background color will be set this automatically sets a foreground color for better readability
99102
READABLE_TEXT_COLOR = 2**3
103+
# sets the `Ignore Case` checkbox on launch
100104
RE_IGNORE_CASE = 2**4
105+
# If a formatter was set to the handler, it can be explicitly ignored.
106+
# This means, the formatter will not be considered as the recorditem's text.
107+
# Instead it will only use the LogRecord.getMessage() directly.
108+
IGNORE_FORMATTER = 2**5
101109

102110
FLAGS = 0
103111
LABEL_WIDTH = 70
@@ -125,7 +133,6 @@ class Flags:
125133
LOG_LEVELS[4]: (182, 60, 66, 100)
126134
}
127135
INITIAL_FILTER_REGEX = r""
128-
IGNORE_FORMATTER = False
129136
EXCEPTION_FORMATTER = logging.Formatter()
130137

131138
_handler = LogbookHandler()
@@ -170,6 +177,10 @@ def _use_readable_text_coloring(self):
170177
def _use_re_ignore_case(self):
171178
return (self.FLAGS & self.Flags.RE_IGNORE_CASE) > 0
172179

180+
@property
181+
def _ignore_formatter(self):
182+
return (self.FLAGS & self.Flags.IGNORE_FORMATTER) > 0
183+
173184
@classmethod
174185
def _validate_levels(cls):
175186
""" ensure we allow flexible level addition but give proper guidance """
@@ -432,7 +443,7 @@ def add_record(self, log_record):
432443

433444
def _add_item():
434445

435-
if self.IGNORE_FORMATTER:
446+
if self._ignore_formatter:
436447
formatter = None
437448
else:
438449
formatter = self.handler.formatter

0 commit comments

Comments
 (0)