Repository navigation
Expand file tree
/
Copy pathlogging.py
More file actions
87 lines (64 loc) · 2.63 KB
/
Copy pathlogging.py
File metadata and controls
87 lines (64 loc) · 2.63 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
"""
.. module:: phobos.logging
:platform: Unix, Windows, Mac
:synopsis: TODO: This module offers a simple way to log messages from phobos and uses blender integrated tools
to display them.
.. moduleauthor:: Ole Schwiegert
Copyright 2014, University of Bremen & DFKI GmbH Robotics Innovation Center
This file is part of Phobos, a Blender Add-On to edit robot models.
Phobos is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
Phobos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Phobos. If not, see <http://www.gnu.org/licenses/>.
File logging.py
Created on 05 Dec 2014
"""
levels = {"ALL": True, "ERROR": True, "WARNING": True, "INFO": True}
operator = None
def startLog(pOperator):
"""This function starts logging for a specified operator.
:param pOperator: The operator you want to log for.
:type pOperator: Blender operator.
:return: Nothing.
"""
global operator
operator = pOperator
def endLog():
"""This function ends the logging for a former registered operator.
:return: Nothing.
"""
global operator
operator = None
def adjustLevel(type, isEnabled):
"""This function adjusts the visibility for a certain logging level.
:param type: The log level you want to enable or disable.
:type type: string -- One of ALL, ERROR, WARNING or INFO.
:param isEnabled: Sets whether logs with the specified level are visible or not.
:type isEnabled: bool.
:return: Nothing.
"""
global levels
if type in levels:
levels[type] = isEnabled
def log(msg, logType="WARNING"):
"""Logs a given message and a given log level.
If there is a registered operator its report function is used, else its printed to the console.
:param msg: The message to log.
:type msg: string.
:param logType: The log level you want to log the message with.
:type logType: string -- one of ERROR, WARNING or INFO.
:return: Nothing.
"""
global levels, operator
if levels['ALL'] or logType == "INFO":
if operator != None and (logType in levels) and levels[logType] == True:
operator.report ({logType}, msg)
else:
print ("LOGGER: ", "Log without bound operator: ", msg)