Skip to content

Commit a4b7777

Browse files
add TypeHint
1 parent 032bd5b commit a4b7777

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

mct_quantizers/logger.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
from datetime import datetime
2020
from pathlib import Path
21+
from typing import Optional
2122

2223
LOGGER_NAME = 'MCT Quantizers'
2324

@@ -32,7 +33,7 @@ class Logger:
3233
CRITICAL = logging.CRITICAL
3334

3435
@staticmethod
35-
def __check_path_create_dir(log_path: str):
36+
def __check_path_create_dir(log_path: str) -> None:
3637
"""
3738
Create a path if not exist. Otherwise, do nothing.
3839
@@ -44,7 +45,7 @@ def __check_path_create_dir(log_path: str):
4445
Path(log_path).mkdir(parents=True, exist_ok=True)
4546

4647
@staticmethod
47-
def set_logger_level(log_level=logging.INFO):
48+
def set_logger_level(log_level: int = logging.INFO) -> None:
4849
"""
4950
Set log level to determine the logger verbosity.
5051
@@ -56,7 +57,7 @@ def set_logger_level(log_level=logging.INFO):
5657
logger.setLevel(log_level)
5758

5859
@staticmethod
59-
def set_handler_level(log_level=logging.INFO):
60+
def set_handler_level(log_level: int = logging.INFO) -> None:
6061
"""
6162
Set log level for all handlers attached to the logger.
6263
@@ -69,14 +70,14 @@ def set_handler_level(log_level=logging.INFO):
6970
handler.setLevel(log_level)
7071

7172
@staticmethod
72-
def get_logger():
73+
def get_logger() -> logging.Logger:
7374
"""
7475
Returns: An instance of the logger.
7576
"""
7677
return logging.getLogger(LOGGER_NAME)
7778

7879
@staticmethod
79-
def set_stream_handler():
80+
def set_stream_handler() -> None:
8081
"""
8182
Add a StreamHandler to output logs to the console (stdout).
8283
"""
@@ -92,7 +93,7 @@ def set_stream_handler():
9293
logger.addHandler(sh)
9394

9495
@staticmethod
95-
def set_log_file(log_folder: str = None):
96+
def set_log_file(log_folder: Optional[str] = None) -> None:
9697
"""
9798
Setting the logger log file path. The method gets the folder for the log file.
9899
In that folder, it creates a log file according to the timestamp.
@@ -119,7 +120,7 @@ def set_log_file(log_folder: str = None):
119120
print(f'log file is in {log_name}')
120121

121122
@staticmethod
122-
def shutdown():
123+
def shutdown() -> None:
123124
"""
124125
An orderly command to shutdown by flushing and closing all logging handlers.
125126
"""
@@ -131,7 +132,7 @@ def shutdown():
131132
########################################
132133

133134
@staticmethod
134-
def critical(msg: str):
135+
def critical(msg: str) -> None:
135136
"""
136137
Log a message at 'critical' severity and raise an exception.
137138
@@ -142,7 +143,7 @@ def critical(msg: str):
142143
raise Exception(msg)
143144

144145
@staticmethod
145-
def exception(msg: str):
146+
def exception(msg: str) -> None:
146147
"""
147148
Log a message at 'exception' severity and raise an exception.
148149
@@ -153,7 +154,7 @@ def exception(msg: str):
153154
raise Exception(msg)
154155

155156
@staticmethod
156-
def debug(msg: str):
157+
def debug(msg: str) -> None:
157158
"""
158159
Log a message at 'debug' severity.
159160
@@ -163,7 +164,7 @@ def debug(msg: str):
163164
Logger.get_logger().debug(msg)
164165

165166
@staticmethod
166-
def info(msg: str):
167+
def info(msg: str) -> None:
167168
"""
168169
Log a message at 'info' severity.
169170
@@ -173,7 +174,7 @@ def info(msg: str):
173174
Logger.get_logger().info(msg)
174175

175176
@staticmethod
176-
def warning(msg: str):
177+
def warning(msg: str) -> None:
177178
"""
178179
Log a message at 'warning' severity.
179180
@@ -183,7 +184,7 @@ def warning(msg: str):
183184
Logger.get_logger().warning(msg)
184185

185186
@staticmethod
186-
def error(msg: str):
187+
def error(msg: str) -> None:
187188
"""
188189
Log a message at 'error' severity and raise an exception.
189190
@@ -193,7 +194,7 @@ def error(msg: str):
193194
Logger.get_logger().error(msg)
194195

195196

196-
def set_log_folder(folder: str, level: int = logging.INFO):
197+
def set_log_folder(folder: str, level: int = logging.INFO) -> None:
197198
"""
198199
Set a directory path for saving a log file.
199200

0 commit comments

Comments
 (0)