[Syncropated-commits] r158 - trunk/src

zimmerle at garage.maemo.org zimmerle at garage.maemo.org
Tue Jan 30 00:12:38 EET 2007


Author: zimmerle
Date: 2007-01-30 00:12:37 +0200 (Tue, 30 Jan 2007)
New Revision: 158

Added:
   trunk/src/Logger.py
Log:
First Logger.py import

Added: trunk/src/Logger.py
===================================================================
--- trunk/src/Logger.py	2007-01-29 22:05:10 UTC (rev 157)
+++ trunk/src/Logger.py	2007-01-29 22:12:37 UTC (rev 158)
@@ -0,0 +1,117 @@
+# Debug.py
+#
+#  Copyright (c) 2006 INdT (Instituto Nokia de Technologia)
+#
+#  Author: Felipe Zimmerle <felipe at zimmerle.org>
+#	   Kenneth Rohde Christiansen <kenneth.christiansen at gmail.com>
+#
+#  This program is free software; you can redistribute it and/or 
+#  modify it under the terms of the GNU General Public License as 
+#  published by the Free Software Foundation; either version 2 of the
+#  License, or (at your option) any later version.
+#
+#  This program 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 General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+#  USA
+
+
+import time
+import logging
+
+class Logger(object):
+
+	__inst = None
+	__level_str = None
+
+	def __new__(cls, output='dummy', level='dummy'):
+		"""
+		This class is a Singleton. 
+
+		"""
+		if cls.__inst == None:
+			cls.__inst = super(cls, Logger).__new__(cls)
+
+		return cls.__inst
+
+
+	def __init__(self, output='log.txt', level='warning'):
+		"""
+		Default output is log.txt and default level is warning.
+	
+		"""
+		self.__output = output
+		self.__level = level
+
+		logging.basicConfig(level=self.getLoggingLevel(level),
+							format='%(asctime)s ' + 
+							'%(levelname)s %(message)s',
+							filename=self.__output,
+							filemode='w')
+		self.__log = logging.getLogger('syncropated')
+
+
+	def __repr__(self):
+		return "<Logger singleton at: %s>" % (hex(id(self)))
+
+
+	def info(self, string):
+		"""
+		Handle string in info level
+
+		"""
+		self.__log.info(string)
+
+
+	def warning(self, string):
+		"""
+		Handle string in warning level
+
+		"""
+		self.__log.warning(string)
+
+
+	def debug(self, string):
+		"""
+		Handle string in debug level
+
+		"""
+		self.__log.debug(string)
+
+
+	def setLevel(self, level):
+		"""
+		Set the debug level.
+
+		"""
+		self.__log.setLevel(self.__get_logging_level_obj(level))
+		self.__log.debug('Logger :: ' + level + " Logging mode activeded")
+		self.__level_str = level
+
+
+	def getLevel(self):
+		"""
+		Return the debug level.
+
+		"""
+
+		return self.__level_str
+
+
+	def __get_logging_level_obj(self, level):
+
+		if level == 'debug':
+			logging_level = logging.DEBUG
+		if level == 'warning':
+			logging_level = logging.WARNING
+		if level == 'info':
+			logging_level = logging.INFO
+
+		return logging_level
+
+



More information about the Syncropated-commits mailing list