Index: MythTV/MythVideo.py
===================================================================
--- MythTV/MythVideo.py	(revision 21647)
+++ MythTV/MythVideo.py	(working copy)
@@ -35,7 +35,6 @@
 		try:
 			cur.execute(u"select * from storagegroup")
 		except MySQLdb.Error, e:
-			log.Msg(INFO, u"! Error: Reading storagegroup MythTV table: %d: %s\n" % (e.args[0], e.args[1]))
 			return None
 
 		videos_dir = []
@@ -102,7 +101,7 @@
 				if os.path.exists(filename): # Handle multiple Videos SGs for one backend
 					break
 			else:
-				log.Msg(INFO, u'%s not exist, removing metadata...', filename)
+				log.info('Videometadata',u'%s not exist, removing metadata...'%  filename)
 				rmMetadata(intid)
 		c.close()
 
@@ -322,7 +321,7 @@
 			c.close()
 			return intid
 		else:
-			log.Msg(DEBUG, 'Updating metadata for %s', id)
+			log.debug('Videometadata', 'Updating metadata for %s' % id)
 			format_string = ', '.join(['%s = %%s' % d for d in data])
 			sql = "UPDATE videometadata SET %s WHERE intid = %%s" % format_string
 			sql_values = data.values()
@@ -341,12 +340,12 @@
 		c = self.db.cursor()
 		if isinstance(video, str):
 			if video[0] !='/' and host == None: # Protect against accidental multiple deletions on SG's
-				log.Msg(WARNING, u"Attempting to delete a video for a storage group when the hostname is not supplied. That could potentially remove the videometadata on multiple backends " +
+				log.warning('Metadata delete', u"Attempting to delete a video for a storage group when the hostname is not supplied. That could potentially remove the videometadata on multiple backends " +
 						u"for videometadata: %s" % video)
 				return
 			intid = self.getMetadataId(video, host)
 			if intid == None:
-				log.Msg(WARNING, u"Attempt to delete a video that does not exist " +
+				log.warning('Metadata delete', u"Attempt to delete a video that does not exist " +
 						u"for videometadata: %s" % video)
 				return
 			c.execute("DELETE FROM videometadata WHERE intid = %s", (intid,))
@@ -354,7 +353,7 @@
 		elif isinstance(video, int) or isinstance(video, long):
 			c.execute("DELETE FROM videometadata WHERE intid = %s", (video,))
 		else:
-			log.Msg(WARNING, "Attempt to delete non-str, non-int item" +
+			log.warning('Metadata delete', "Attempt to delete non-str, non-int item" +
 					"from videometadata: %s" % str(video))
 		# Clean up this video's relationships to Genres, Country and Cast
 		self.cleanGenres(video)
Index: MythTV/MythTV.py
===================================================================
--- MythTV/MythTV.py	(revision 21647)
+++ MythTV/MythTV.py	(working copy)
@@ -20,7 +20,7 @@
 from MythDB import *
 from MythLog import *
 
-log = MythLog(CRITICAL, '#%(levelname)s - %(message)s', 'MythTV')
+log = MythLog(CRITICAL, 'MythTV.py')
 
 RECSTATUS = {
 		'TunerBusy': -8,
@@ -59,10 +59,10 @@
 		self.master_port = int(self.db.getSetting('MasterServerPort'))
 
 		if not self.master_host:
-			log.Msg(CRITICAL, 'Unable to find MasterServerIP in database')
+			log.critical('Settings','Unable to find MasterServerIP in database')
 			sys.exit(1)
 		if not self.master_port:
-			log.Msg(CRITICAL, 'Unable to find MasterServerPort in database')
+			log.critical('Settings','Unable to find MasterServerPort in database')
 			sys.exit(1)
 
 		try:
@@ -71,15 +71,15 @@
 			self.socket.connect((self.master_host, self.master_port))
 			res = self.backendCommand('MYTH_PROTO_VERSION %s' % PROTO_VERSION).split(BACKEND_SEP)
 			if res[0] == 'REJECT':
-				log.Msg(CRITICAL, 'Backend has version %s and we speak version %s', res[1], PROTO_VERSION)
+				log.critical('Protocol Mismatch',"Backend has version %s and we speak version %s" % (res[1], PROTO_VERSION))
 				sys.exit(1)
 			res = self.backendCommand('ANN %s %s 0' % (conn_type, socket.gethostname()))
 			if res != 'OK':
-				log.Msg(CRITICAL, 'Unexpected answer to ANN command: %s', res)
+				log.critical('Protocol Error',"Unexpected answer to ANN command: %s" % res)
 			else:
-				log.Msg(INFO, 'Successfully connected mythbackend at %s:%d', self.master_host, self.master_port)
+				log.info('Info',"Successfully connected mythbackend at %s:%d" % (self.master_host, self.master_port))
 		except socket.error, e:
-			log.Msg(CRITICAL, 'Couldn\'t connect to %s:%d (is the backend running)', self.master_host, self.master_port)
+			log.critical('Protocol Error',"Couldn't connect to %s:%d (is the backend running)" % (self.master_host, self.master_port))
 			sys.exit(1)
 
 	def __del__(self):
@@ -114,7 +114,7 @@
 				return u''.join(data)
 
 		command = u'%-8d%s' % (len(data), data)
-		log.Msg(DEBUG, 'Sending command: %s', command)
+		log.debug('Info','Sending command: %s' % command)
 		self.socket.send(command)
 		return recv()
 
@@ -126,7 +126,7 @@
 		res = self.backendCommand('QUERY_GETALLPENDING').split(BACKEND_SEP)
 		has_conflict = int(res.pop(0))
 		num_progs = int(res.pop(0))
-		log.Msg(DEBUG, '%s pending recordings', num_progs)
+		log.debug('Info','%s pending recordings' % num_progs)
 		for i in range(num_progs):
 			programs.append(Program(res[i * PROGRAM_FIELDS:(i * PROGRAM_FIELDS)
 				+ PROGRAM_FIELDS]))
@@ -139,7 +139,7 @@
 		programs = []
 		res = self.backendCommand('QUERY_GETALLSCHEDULED').split(BACKEND_SEP)
 		num_progs = int(res.pop(0))
-		log.Msg(DEBUG, '%s scheduled recordings', num_progs)
+		log.debug('Info','%s scheduled recordings' % num_progs)
 		for i in range(num_progs):
 			programs.append(Program(res[i * PROGRAM_FIELDS:(i * PROGRAM_FIELDS)
 				+ PROGRAM_FIELDS]))
@@ -247,7 +247,7 @@
 		programs = []
 		res = self.backendCommand('QUERY_RECORDINGS Play').split('[]:[]')
 		num_progs = int(res.pop(0))
-		log.Msg(DEBUG, '%s total recordings', num_progs)
+		log.debug('Info','%s total recordings' % num_progs)
 		for i in range(num_progs):
 			programs.append(Program(res[i * PROGRAM_FIELDS:(i * PROGRAM_FIELDS)
 				+ PROGRAM_FIELDS]))
@@ -414,7 +414,7 @@
 		elif mode == 'w':
 			write = 1
 		else:
-			log.Msg(CRITICAL, 'Invalid FileTransfer mode given')
+			log.critical('Filetransfer', 'Invalid FileTransfer mode given')
 			sys.exit(1)
 		if isinstance(file, Program):
 			match = regex.match(file.filename)
@@ -426,7 +426,7 @@
 				self.port = 6543
 		elif isinstance(file, tuple):
 			if len(file) != 3:
-				log.Msg(CRITICAL, 'Incorrect FileTransfer() input size')
+				log.critical('Filetransfer', 'Incorrect FileTransfer() input size')
 				sys.exit(1)
 			else:
 				self.host = file[0]
@@ -436,7 +436,7 @@
 		elif isinstance(file, str):
 			match = regex.match(file)
 			if match is None:
-				log.Msg(CRITICAL, 'Incorrect FileTransfer() input string: %s' % file)
+				log.critical('Filetransfer', 'Incorrect FileTransfer() input string: %s' % file)
 				sys.exit(1)
 			self.sgroup = match.group('group')
 			self.host = match.group('host')
@@ -447,7 +447,7 @@
 			if self.port is None:
 				self.port = 6543
 		else:
-			log.Msg(CRITICAL, 'Improper input to FileTransfer()')
+			log.critical('Filetransfer', 'Improper input to FileTransfer()')
 			sys.exit(1)
 
 		try:
@@ -456,20 +456,20 @@
 			self.datsock.connect((self.host, self.port))
 			res = self.send('MYTH_PROTO_VERSION %s' % PROTO_VERSION).split(BACKEND_SEP)
 			if res[0] == 'REJECT':
-				log.Msg(CRITICAL, 'Backend has version %s and we speak version %s', res[1], PROTO_VERSION)
+				log.critical('Filetransfer', 'Backend has version %s and we speak version %s' % (res[1], PROTO_VERSION))
 				sys.exit(1)
 			res = self.send('ANN FileTransfer %s %d %d %d%s%s%s%s' % (socket.gethostname(), write, False, -1, BACKEND_SEP, self.filename, BACKEND_SEP, self.sgroup))
 			if res.split(BACKEND_SEP)[0] != 'OK':
-				log.Msg(CRITICAL, 'Unexpected answer to ANN command: %s', res)
+				log.critical('Filetransfer', 'Unexpected answer to ANN command: %s' % res)
 			else:
-				log.Msg(INFO, 'Successfully connected mythbackend at %s:%d', self.host, self.port)
+				log.info('Filetransfer', 'Successfully connected mythbackend at %s:%d' % (self.host, self.port))
 				sp = res.split(BACKEND_SEP)
 				self.sockno = int(sp[1])
 				self.pos = 0
 				self.size = (int(sp[2]) + (int(sp[3])<0))*2**32 + int(sp[3])
 				
 		except socket.error, e:
-			log.Msg(CRITICAL, 'Couldn\'t connect to %s:%d (is the backend running)', self.host, self.port)
+			log.critical('Filetransfer', "Couldn't connect to %s:%d (is the backend running)" % (self.host, self.port))
 			sys.exit(1)
 
 	def __del__(self):
@@ -481,7 +481,7 @@
 
 	def send(self,data):
 		command = '%-8d%s' % (len(data), data)
-		log.Msg(DEBUG, 'Sending command: %s', command)
+		log.debug('Filetransfer', 'Sending command: %s' % command)
 		self.datsock.send(command)
 		return self.recv()
 
@@ -588,7 +588,7 @@
 			if offset < -self.size:
 				offset = -self.size
 		else:
-			log.Msg(CRITICAL, 'Whence can only be 0, 1, or 2')
+			log.critical('Filetransfer', 'Whence can only be 0, 1, or 2')
 
 		curhigh,curlow = self.comsock.splitInt(self.pos)
 		offhigh,offlow = self.comsock.splitInt(offset)
Index: MythTV/MythLog.py
===================================================================
--- MythTV/MythLog.py	(revision 21647)
+++ MythTV/MythLog.py	(working copy)
@@ -2,30 +2,92 @@
 Provides simple logging and exception classes.
 """
 
-import logging
+from MythDB import *
+from socket import gethostname
+from datetime import datetime
+from sys import version_info
 
+db = MythDB()
+
 # Vars to imporove readability
-CRITICAL = logging.CRITICAL
-FATAL = logging.FATAL
-ERROR = logging.ERROR
-WARNING = logging.WARNING
-INFO = logging.INFO
-DEBUG = logging.DEBUG
+ALL = 8
+DEBUG = 7
+INFO = 6
+NOTICE = 5
+WARNING = 4
+ERROR = 3
+CRITICAL = 2
+ALERT = 1
+EMERGENCY = 0
 
 class MythLog:
 	"""
 	A simple logging class
 	"""
-	def __init__(self, level, format, instance):
-		self.log = logging.getLogger(instance)
-		self.log.setLevel(level)
-		self.ch = logging.StreamHandler()
-		self.ch.setFormatter(logging.Formatter(format))
-		self.log.addHandler(self.ch)
 
-	def Msg(self, level, msg, *args, **kwargs):
-		self.log.log(level, msg, *args, **kwargs)
+	priority = WARNING
 
+	def __init__(self, priority=WARNING, module='pythonbindings', mode=3):
+		self.setPriority(priority)
+		if isinstance(module,str):
+			self.mod = module
+		self.host = gethostname()
+		self.mode = mode
+		if db.getSetting('LogEnabled') == 0:
+			self.mode %= 2
+
+	def setPriority(self, priority):
+		if priority in range(0,9):
+			self.priority = priority
+
+	def log(self, priority, message, detail=''):
+		if priority > self.priority:
+			return
+		now = datetime.now()
+		nowstr = None
+		if (version_info[0] > 2) | (version_info[1] > 5):
+			nowstr = now.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
+		else:
+			nowstr = now.strftime('%Y-%m-%d %H:%M:%S.000')
+		if self.mode & 1:
+			if len(detail):
+				print "%s %s: %s -- %s" % (nowstr, self.mod, message, detail)
+			else:
+				print "%s %s: %s" % (nowstr, self.mod, message)
+		if self.mode & 2:
+			cursor = db.cursor()
+			cursor.execute("""INSERT INTO mythlog 
+				(module, priority, logdate, host, message, details)
+				VALUES (%s, %s, %s, %s, %s, %s)""",
+				(self.mod,priority,now,self.host,message,detail))
+
+	def all(self, message, detail=''):
+		self.log(ALL,message,detail)
+
+	def debug(self, message, detail=''):
+		self.log(DEBUG,message,detail)
+
+	def info(self, message, detail=''):
+		self.log(INFO,message,detail)
+
+	def notice(self, message, detail=''):
+		self.log(NOTICE,message,detail)
+
+	def warning(self, message, detail=''):
+		self.log(WARNING,message,detail)
+
+	def error(self, message, detail=''):
+		self.log(ERROR,message,detail)
+
+	def critical(self, message, detail=''):
+		self.log(CRITICAL,message,detail)
+
+	def alert(self, message, detail=''):
+		self.log(ALERT,message,detail)
+
+	def emergency(self, message, detail=''):
+		self.log(EMERGENCY,message,detail)
+
 class MythError:
 	"""
 	A simple exception class
@@ -36,4 +98,5 @@
 	def __repr__(self):
 		print ': ' + self.message
 
+
 # vim: ts=4 sw=4:
Index: MythTV/MythDB.py
===================================================================
--- MythTV/MythDB.py	(revision 21647)
+++ MythTV/MythDB.py	(working copy)
@@ -10,17 +10,11 @@
 import getopt
 from datetime import datetime
 
-from MythLog import *
-
-# create logging object
-log = MythLog(CRITICAL, '#%(levelname)s - %(message)s', 'MythDB')
-
 # check for dependency
 try:
 	import MySQLdb
 except:
-	log.Msg(CRITICAL, "MySQLdb (python-mysqldb) is required but is not found.")
-	sys.exit(1)
+	raise MythError("MySQLdb (python-mysqldb) is required but is not found.")
 
 class MythDB:
 	"""
@@ -73,7 +67,7 @@
 					pass
 
 			if dbconn['host'] != None and dbconn['name'] != None and dbconn['user'] != None and dbconn['pass'] != None:
-				log.Msg(INFO, 'Using config %s', config_file)
+#				log.Msg(INFO, 'Using config %s', config_file)
 				found_config = True
 				break
 
@@ -97,7 +91,7 @@
 
 		try:
 			self.db = MySQLdb.connect(user=dbconn['user'], host=dbconn['host'], passwd=dbconn['pass'], db=dbconn['name'], use_unicode=True, charset='utf8')
-			log.Msg(INFO, 'DB Connection info (host:%s, name:%s, user:%s, pass:%s)', dbconn['host'], dbconn['name'], dbconn['user'], dbconn['pass'])
+#			log.Msg(INFO, 'DB Connection info (host:%s, name:%s, user:%s, pass:%s)', dbconn['host'], dbconn['name'], dbconn['user'], dbconn['pass'])
 		except:
 			raise MythError('Connection failed for \'%s\'@\'%s\' to database %s using password %s' % (dbconn['user'], dbconn['host'], dbconn['name'], dbconn['pass']))
 
@@ -108,7 +102,7 @@
 		Returns None if there are no settings. If multiple rows are
 		found (multiple hostnames), returns the value of the first one.
 		"""
-		log.Msg(DEBUG, 'Retrieving all setting for host %s', hostname)
+#		log.Msg(DEBUG, 'Retrieving all setting for host %s', hostname)
 		c = self.db.cursor()
 		if hostname is None:
 			c.execute("""
@@ -136,7 +130,7 @@
 		Returns None if the setting was not found. If multiple rows are
 		found (multiple hostnames), returns the value of the first one.
 		"""
-		log.Msg(DEBUG, 'Looking for setting %s for host %s', value, hostname)
+#		log.Msg(DEBUG, 'Looking for setting %s for host %s', value, hostname)
 		c = self.db.cursor()
 		if hostname is None:
 			c.execute("""
@@ -162,7 +156,7 @@
 		"""
 		Sets the value for the given MythTV setting.
 		"""
-		log.Msg(DEBUG, 'Setting %s for host %s to %s', value, hostname, data)
+#		log.Msg(DEBUG, 'Setting %s for host %s to %s', value, hostname, data)
 		c = self.db.cursor()
 		ws = None
 		ss = None
