forked from Sollumz/Sollumz
-
Notifications
You must be signed in to change notification settings - Fork 3
/
logger.py
39 lines (25 loc) · 832 Bytes
/
logger.py
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
"""
Logging module to easily log messages from operators that are extended into many functions.
"""
from bpy.types import Operator
from typing import Optional
_logging_operator: Optional[Operator] = None
_NO_LOGGING_OPERATOR_WARNING = "LOGGER WARNING: No active logging operator has been set!"
def _log(msg: str, level: str):
print(f"{level}: {msg}")
if _logging_operator is None:
print(_NO_LOGGING_OPERATOR_WARNING)
return
try:
_logging_operator.report({level}, msg)
except ReferenceError:
print(_NO_LOGGING_OPERATOR_WARNING)
def set_logging_operator(operator: Operator):
global _logging_operator
_logging_operator = operator
def info(msg: str):
_log(msg, "INFO")
def warning(msg: str):
_log(msg, "WARNING")
def error(msg: str):
_log(msg, "ERROR")