-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.py
More file actions
57 lines (46 loc) · 1.81 KB
/
Copy pathlogger.py
File metadata and controls
57 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import typing
from datetime import datetime
from config import Config
class Logger:
# The levels of configuration for logging.
logConfig: typing.Dict[str, int] = { "all": 1,
"main": 0,
"min": -1,
"warn": -2,
"err": -3,
"none": -4 }
@staticmethod
def log ( message: str, logger: str = "all" ) -> None:
"""
Prints log statements with a time stamp. Only prints if the logger is less than the log
configuration provided by the user's arguments.
:param message: The message to be printed
:param logger: The verbosity of the log statement.
"""
# If we can log based on the configuration
if Logger.shouldLog ( logger = logger ):
# Then log.
print ( str ( datetime.now () ) + ": " + str ( message ) )
@staticmethod
def shouldLog ( logger: str = "all" ) -> bool:
"""
:param logger: The verbosity of the log.
:return: Whether the log should be printed.
"""
return Logger.logConfig[logger] <= Logger.logConfig[Config.getArgs ().log_config]
@staticmethod
def error ( message: str ) -> None:
"""
Uses the log statement to print an Error message (a log with ERROR: prefixed to the log message.).
Is always printed unless the user sets --log-config to be none.
:param message: The error message to be printed.
"""
Logger.log ( "ERROR: " + str ( message ), logger = "err" )
@staticmethod
def warn ( message: str ) -> None:
"""
Uses the log statement to print a warning message (a log with WARNING: prefixed to the log message).
Is always printed unless the user sets --log-config to none or err
:param message: The warning to be printed.
"""
Logger.log ( "WARNING: " + str ( message ), logger = "warn" )