Skip to content

Commit 8dd2b98

Browse files
Add Categories.PRINT and Categories.SAVE
Categories.PRINT replaces the now-deprecated Categories.ENABLED, printing a log entry but not saving it. Categories.SAVE indicates an entry should be saved to the log file but not printed. Categories.ENABLED can still be used but will be removed in later versions. This commit also updates an out-of-date docstring for the Logger class.
1 parent 35a61f6 commit 8dd2b98

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

smooth_logger/Logger.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ class Logger:
1515
"""
1616
Class for controlling the entirety of logging. The logging works on a scope-based system where
1717
(almost) every message has a defined scope, and the scopes are each associated with a specific
18-
category between 0 and 2 inclusive. The meanings of the categories are as follows:
18+
category defined by the smooth_logger.enums.Categories class. The categories' meanings are as
19+
follows:
1920
20-
0: disabled, do not print to console or save to log file
21-
1: enabled, print to console but do not save to log file
22-
2: maximum, print to console and save to log file
21+
Categories.DISABLED: do not print to console or save to log file
22+
Categories.PRINT: print to console but do not save to log file
23+
Categories.SAVE: save to log file but do not print to console
24+
Categories.MAXIMUM: print to console and save to log file
25+
26+
Note that the old Categories.ENABLED category is deprecated and its functionality has been
27+
replaced with Categories.PRINT. It will be removed in a later version.
2328
"""
2429
def __init__(self,
2530
program_name: str,
2631
config_path: str = None,
2732
debug: int = Categories.DISABLED,
2833
error: int = Categories.MAXIMUM,
2934
fatal: int = Categories.MAXIMUM,
30-
info: int = Categories.ENABLED,
35+
info: int = Categories.PRINT,
3136
warning: int = Categories.MAXIMUM) -> None:
3237
self.bar: ProgressBar = ProgressBar()
3338
self.is_empty: bool = True
@@ -110,7 +115,10 @@ def __display_log_entry(self,
110115
:param is_bar: whether the progress bar is active
111116
:param print_to_console: whether the message should be printed to the console
112117
"""
113-
if scope is None or (self._scopes[scope] != Categories.DISABLED and print_to_console):
118+
if scope is None or (
119+
self._scopes[scope] in [Categories.MAXIMUM, Categories.PRINT, Categories.ENABLED]
120+
and print_to_console
121+
):
114122
print(entry.rendered)
115123
if is_bar:
116124
print(self.bar.state, end="\r", flush=True)
@@ -283,7 +291,7 @@ def new(self,
283291
output: bool = (
284292
False
285293
if scope is None else
286-
self._scopes[scope] == Categories.MAXIMUM
294+
self._scopes[scope] in [Categories.MAXIMUM, Categories.SAVE]
287295
)
288296
is_bar: bool = (self.bar is not None) and self.bar.opened
289297

smooth_logger/enums.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
class Categories(Enum):
44
DISABLED = 0 # do not print to console or save to log file
5-
ENABLED = 1 # print to console but do not save to log file
6-
MAXIMUM = 2 # print to console and save to log file
5+
PRINT = 1 # print to console but do not save to log file
6+
SAVE = 2 # save to log file but do not print to console
7+
MAXIMUM = 3 # print to console and save to log file
8+
9+
ENABLED = 4 # DEPRECATED: print to console but do not save to log file

0 commit comments

Comments
 (0)