comparison engine/python/fife/extensions/fifelog.py @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children ae9f5383f5b1
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 # -*- coding: utf-8 -*-
2
3 # ####################################################################
4 # Copyright (C) 2005-2009 by the FIFE team
5 # http://www.fifengine.de
6 # This file is part of FIFE.
7 #
8 # FIFE is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # ####################################################################
23
24 from fife import fife
25
26 class LogManager(object):
27 '''
28 Log manager provides convenient apis to access engine logging functionality.
29 You can set log targets individually (prompt, file). You can also adjust
30 things like visible modules through log manager.
31 '''
32
33 def __init__(self, engine, promptlog=True, filelog=False):
34 '''
35 Constructs new log manager
36 @param engine: Engine to hook into
37 @param promptlog: If true, logs to prompt
38 @param filelog: If true, logs to file (fife.log)
39 '''
40 self.engine = engine
41 self.lm = engine.getLogManager()
42 self.lm.setLogToPrompt(promptlog)
43 self.lm.setLogToFile(filelog)
44 self.mod2name = {}
45 for k, v in fife.__dict__.items():
46 if k.startswith('LM_') and k not in ('LM_CORE', 'LM_MODULE_MAX'):
47 self.mod2name[v] = self.lm.getModuleName(v)
48 self.name2mod = dict([(v.lower(), k) for k, v in self.mod2name.items()])
49
50 def addVisibleModules(self, *names):
51 '''
52 Adds modules that are visible in logs. By default, all modules
53 are disabled. Does not remove previously visible modules
54 @param names: module names to set visible
55 @see modules.h file for available modules in the engine
56 '''
57 names = [n.lower() for n in names]
58 if 'all' in names:
59 for k in self.mod2name.keys():
60 self.lm.addVisibleModule(k)
61 else:
62 for m in names:
63 try:
64 self.lm.addVisibleModule(self.name2mod[m])
65 except KeyError:
66 print 'Tried to enable non-existing log module "%s"' % m
67
68 def removeVisibleModules(self, *names):
69 '''
70 Removes modules that are visible in logs. By default, all modules
71 are disabled.
72 @param names: module names to set invisible
73 @see addVisibleModules
74 '''
75 names = [n.lower() for n in names]
76 if 'all' in names:
77 for k in self.mod2name.keys():
78 self.lm.removeVisibleModule(k)
79 else:
80 for m in names:
81 self.lm.removeVisibleModule(self.name2mod[m])
82
83 def getVisibleModules(self):
84 '''
85 Gets currently visible modules
86 @see addVisibleModules
87 '''
88 mods = []
89 for k in self.mod2name.keys():
90 if self.lm.isVisible(k):
91 mods.append(self.mod2name[k])
92
93 def setVisibleModules(self, *names):
94 '''
95 Sets visible modules. Clears previously set modules.
96 @param names: module names to set visible
97 @see addVisibleModules
98 '''
99 self.lm.clearVisibleModules()
100 self.addVisibleModules(*names)