Mercurial > fife-parpg
comparison engine/extensions/fifelog.py @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 6f9c7d0b35d4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 import fife | |
2 | |
3 class LogManager(object): | |
4 ''' | |
5 Log manager provides convenient apis to access engine logging functionality. | |
6 You can set log targets individually (prompt, file). You can also adjust | |
7 things like visible modules through log manager. | |
8 ''' | |
9 | |
10 def __init__(self, engine, promptlog=True, filelog=False): | |
11 ''' | |
12 Constructs new log manager | |
13 @param engine: Engine to hook into | |
14 @param promptlog: If true, logs to prompt | |
15 @param filelog: If true, logs to file (fife.log) | |
16 ''' | |
17 self.engine = engine | |
18 self.lm = engine.getLogManager() | |
19 self.lm.setLogToPrompt(promptlog) | |
20 self.lm.setLogToFile(filelog) | |
21 self.mod2name = {} | |
22 for k, v in fife.__dict__.items(): | |
23 if k.startswith('LM_') and k not in ('LM_CORE', 'LM_MODULE_MAX'): | |
24 self.mod2name[v] = self.lm.getModuleName(v) | |
25 self.name2mod = dict([(v.lower(), k) for k, v in self.mod2name.items()]) | |
26 | |
27 def addVisibleModules(self, *names): | |
28 ''' | |
29 Adds modules that are visible in logs. By default, all modules | |
30 are disabled. Does not remove previously visible modules | |
31 @param names: module names to set visible | |
32 @see modules.h file for available modules in the engine | |
33 ''' | |
34 names = [n.lower() for n in names] | |
35 if 'all' in names: | |
36 for k in self.mod2name.keys(): | |
37 self.lm.addVisibleModule(k) | |
38 else: | |
39 for m in names: | |
40 self.lm.addVisibleModule(self.name2mod[m]) | |
41 | |
42 def removeVisibleModules(self, *names): | |
43 ''' | |
44 Removes modules that are visible in logs. By default, all modules | |
45 are disabled. | |
46 @param names: module names to set invisible | |
47 @see addVisibleModules | |
48 ''' | |
49 names = [n.lower() for n in names] | |
50 if 'all' in names: | |
51 for k in self.mod2name.keys(): | |
52 self.lm.removeVisibleModule(k) | |
53 else: | |
54 for m in names: | |
55 self.lm.removeVisibleModule(self.name2mod[m]) | |
56 | |
57 def getVisibleModules(self): | |
58 ''' | |
59 Gets currently visible modules | |
60 @see addVisibleModules | |
61 ''' | |
62 mods = [] | |
63 for k in self.mod2name.keys(): | |
64 if self.lm.isVisible(k): | |
65 mods.append(self.mod2name[k]) | |
66 | |
67 def setVisibleModules(self, *names): | |
68 ''' | |
69 Sets visible modules. Clears previously set modules. | |
70 @param names: module names to set visible | |
71 @see addVisibleModules | |
72 ''' | |
73 self.lm.clearVisibleModules() | |
74 self.addVisibleModules(*names) | |
75 |