1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import re
18
19 import libxyz.ui as uilib
20
21 from libxyz.ui import lowui
22 from libxyz.core.plugins import VirtualPlugin
23 from libxyz.core import Queue
24 from libxyz.core.logger.loglevel import LogLevel
25 from libxyz.core.logger.logentry import LogEntry
26
28 """
29 Logger console is used to collect system messages.
30 There are several message levels:
31 PANIC: Critical error.
32 ERROR: Non-critical error.
33 WARNING: Warning.
34 INFO: Informational message.
35 DEBUG: Debug messages.
36 ALL: All of the above.
37 """
38
39 - def __init__(self, xyz, levels, lines=100):
40 """
41 @param xyz: XYZ data
42 @param levels: A list of levels to track
43 @param lines: Max number of lines to be shown in logger console
44 """
45
46 self.xyz = xyz
47
48 try:
49 self.lines = int(lines)
50 except ValueError:
51 pass
52
53 self.loglevel = LogLevel()
54 self.tracked_levels = self._calc_levels(levels)
55
56 self._lines = lines
57 self._data = Queue(self._lines)
58
59 self._set_internal_plugin()
60
61
62
64 """
65 Show logger console
66 """
67
68
69
70 _walker = lowui.SimpleListWalker(list(self._data))
71 _walker.focus = len(_walker) - 1
72
73 _dim = tuple([x - 2 for x in self.xyz.screen.get_cols_rows()])
74
75 uilib.XYZListBox(self.xyz, self.xyz.top, _walker,
76 _(u"Logger console"), _dim).show()
77
78
79
80 - def log(self, msg, level=None):
81 """
82 Add new message to log
83
84 @param msg: Message
85 @param level: Log level
86 @type level: L{LogLevel} attribute
87 """
88
89 if level is None:
90 level = self.loglevel.UNKNOWN
91
92 _sel_attr = self.xyz.skin.attr(uilib.XYZListBox.resolution,
93 u"selected")
94
95 if self.tracked_levels & level:
96 self._data.append(LogEntry(msg, self.loglevel.str_level(level),
97 _sel_attr))
98
99
100
101 panic = lambda self, msg: self.log(msg, level=self.loglevel.PANIC)
102 error = lambda self, msg: self.log(msg, level=self.loglevel.ERROR)
103 warning = lambda self, msg: self.log(msg, level=self.loglevel.WARNING)
104 info = lambda self, msg: self.log(msg, level=self.loglevel.INFO)
105 debug = lambda self, msg: self.log(msg, level=self.loglevel.DEBUG)
106
107
108
110 """
111 Clear log queue
112 """
113
114 self._data.clear()
115
116
117
119 """
120 Parse levels from config
121 """
122
123 _level = self.loglevel.NONE
124
125 for _lvl in level_list:
126 _level |= _lvl
127
128 return _level
129
130
131
150