logger.py
Go to the documentation of this file.00001 import silme.core
00002 """
00003 Basic logger class.
00004 It adds to EntityList, L10nObject and L10nPackage methods:
00005 class.log(type, message, path=None)
00006 class.get_logs()
00007
00008 that allows to store informations about the package or object.
00009 """
00010
00011 class Logger():
00012 @classmethod
00013 def log(cls, type, message, path=None):
00014 """
00015 adds a new log to the object.
00016 """
00017 if hasattr(cls, 'logs'):
00018 cls.logs.append((type, message, path))
00019 else:
00020 cls.logs = [(type, message, path)]
00021 return True
00022
00023 @classmethod
00024 def get_logs(cls):
00025 """
00026 returns list of logs for Logger
00027 """
00028 if hasattr(cls, 'logs'):
00029 return cls.logs
00030 return []
00031
00032 def log(self, type, message, path=None):
00033 """
00034 adds a new log to the object. If self.logs list does not exist its being added
00035 """
00036 if hasattr(self, 'logs'):
00037 self.logs.append((type, message, path))
00038 else:
00039 self.logs = [(type, message, path)]
00040 return True
00041
00042 def get_logs(self):
00043 """
00044 returns list of logs for the object
00045 """
00046 if hasattr(self, 'logs'):
00047 return self.logs
00048 return []
00049
00050 def get_all_logs(self, recursive=False):
00051 """
00052 returns list of logs for the package, optionally can also load
00053 all logs from its objects and sub-packages.
00054 """
00055 if hasattr(self, 'logs'):
00056 logs = self.logs
00057 else:
00058 logs = []
00059 if not recursive:
00060 return logs
00061 for object in self.get_objects():
00062 logs.extend(object.get_logs())
00063 for package in self.get_packages():
00064 logs.extend(package.get_logs(recursive=True))
00065 return logs
00066
00067
00068 silme.core.EntityList.log = log
00069 silme.core.EntityList.get_logs = get_logs
00070
00071 silme.core.L10nObject.log = log
00072 silme.core.L10nObject.get_logs = get_logs
00073
00074 silme.core.L10nPackage.log = log
00075 silme.core.L10nPackage.get_logs = get_all_logs