--- a/iro/anbieter/sipgate.py Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/anbieter/sipgate.py Fri Nov 27 01:14:51 2009 +0100
@@ -17,6 +17,8 @@
import ConfigParser
import xmlrpclib
import base64
+import logging
+logger=logging.getLogger("sipgate")
class NoValidStatusCode(Exception):
pass
@@ -41,8 +43,7 @@
def sendSMS(self,sms,recipients):
"""send SMS with $sms to $recipients"""
- import logging
- logging.debug('sipgate.sendSMS(%s,%s)'%(sms, str(recipients)))
+ logger.debug('sipgate.sendSMS(%s,%s)'%(sms, str(recipients)))
args={
"TOS" : "text",
"Content" : sms.content
@@ -51,8 +52,7 @@
def sendFAX(self,fax,recipients):
"""send the PDF file $fax to $recipients"""
- import logging
- logging.debug('sipgate.sendFAX(%s,%s)'%(fax, str(recipients)))
+ logger.debug('sipgate.sendFAX(%s,%s)'%(fax, str(recipients)))
pdf=open(fax.attachments[0],"rb")
args={
"TOS" : "fax",
--- a/iro/anbieter/smstrade.py Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/anbieter/smstrade.py Fri Nov 27 01:14:51 2009 +0100
@@ -21,6 +21,9 @@
import gsm0338
import urllib, httplib
+import logging
+logger=logging.getLogger("smstrade")
+
class UnknownStatusCode(Exception):
def __init__(self,code):
self.code=code
@@ -88,13 +91,10 @@
def sendSMS(self,sms,recipients):
"""send SMS with $sms to $recipients"""
- import logging
- logging.debug('smstrade.sendSMS(%s,%s)'%(sms, str(recipients)))
+ logger.debug('smstrade.sendSMS(%s,%s)'%(sms, str(recipients)))
sended = []
- key = self.key
route = unicode(self.route)
message = sms.content
- from_ = unicode(self.from_)
timestamp = None
for recipient in recipients:
try:
@@ -107,7 +107,8 @@
route=unicode("basic")
else:
route=unicode("economy")
- smsSendStatus = self.__send(key, route, to, message, from_, timestamp)
+ smsSendStatus = self.__send(route, to, message, timestamp)
+ logger.debug('smstrade._send(...)=%i(%s)'%(int(smsSendStatus),str(smsSendStatus)))
if int(smsSendStatus) in(100, 999):
self.updateStatus(arranged=recipient)
else:
@@ -115,13 +116,12 @@
except (NotATelNumber,NoValidStatusCode,InternetConnectionError):
self.updateStatus(failed=recipient)
- def __send(self, key, route, to, message, from_=None, timestamp=None):
+ def __send(self, route, to, message, timestamp=None):
""" This function is the main part of the request to the sms service.
The function has to return a unicode formated string that will represent the answer of the sms service
to the request."""
- import logging
- logging.debug('smstrade._send(%s,%s,%s,%s,%s,%s)'%( key, route, to, message, from_, timestamp))
- parameters= {"key": key,
+ logger.debug('smstrade._send(%s,%s,%s,%s)'%( route, to, message, timestamp))
+ parameters= {"key": self.key,
"route": route,
"to": to,
"message": message,
@@ -129,15 +129,15 @@
"debug": self.debug,
}
- if from_ is not None:
- parameters["from"] = from_
+ if self.from_ is not None:
+ parameters["from"] = self.from_
if timestamp is not None:
parameters["senddate"] = unicode(timestamp)
parameters["concat_sms"] = "1" if len(message) > 160 else "0"
params = "&".join( ["%s=%s" % (urllib.quote(k),urllib.quote(v.encode("utf-8"))) for (k, v) in parameters.items()])
- logging.debug('smstrade._send-parameters:%s\n\t->%s'%(str(parameters), str(params)) )
+ logger.debug('smstrade._send-parameters:%s\n\t->%s'%(str(parameters), str(params)) )
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPConnection("%s:%i" % (self.gateway, self.gatewayPort))
--- a/iro/anbieter/smtp.py Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/anbieter/smtp.py Fri Nov 27 01:14:51 2009 +0100
@@ -15,6 +15,8 @@
default_conf = '' # override this
import smtplib
import ConfigParser
+import logging
+logger=logging.getLogger("SMTP")
class SMTP():
def __init__(self,config_filename=None,section="smtp"):
@@ -65,8 +67,7 @@
self.bStart=True
def sendMail(self,mail,recipients):
- import logging
- logging.debug('SMTP.sendMail(%s,%s)'%(mail, str(recipients)))
+ logger.debug('SMTP.sendMail(%s,%s)'%(mail, str(recipients)))
if not self.bStart:
self.prepareSMTP()
@@ -75,7 +76,7 @@
while len(recipients) > 0:
tmp_recipients=recipients[:self.max_recipients]
mail.content['To']=", ".join(tmp_recipients)
- logging.debug('self.smtp.sendmail(%s,%s,%s)'%(self.send_from, str(tmp_recipients), mail.as_string()))
+ logger.debug('self.smtp.sendmail(%s,%s,%s)'%(self.send_from, str(tmp_recipients), mail.as_string()))
self.smtp.sendmail(self.send_from, tmp_recipients, mail.as_string())
self.updateStatus( arranged=tmp_recipients)
recipients = recipients[self.max_recipients:]
--- a/iro/iro.py Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/iro.py Fri Nov 27 01:14:51 2009 +0100
@@ -11,9 +11,10 @@
#You should have received a copy of the GNU General Public License
#along with this program; if not, see <http://www.gnu.org/licenses/>.
-import multiprocessing, logging
+import logging,multiprocessing
#logging anfangen
-logging.basicConfig(level=logging.DEBUG, format='%(levelname)s-[%(asctime)s %(processName)s (%(threadName)s)]%(message)s')
+logger=logging.getLogger("iro")
+logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s(%(processName)s)-%(levelname)s: %(message)s')
# Server code
@@ -142,15 +143,15 @@
certificate=cert,privatekey=key)
server.relam="xmlrpc"
- logging.info('Server gestartet...')
+ logger.info('Server gestartet...')
try:
server.serve_forever()
except KeyboardInterrupt:
pass
except:
- logging.exception('Äh, ein Fehler ist aufgetreten')
+ logger.exception('Äh, ein Fehler ist aufgetreten')
finally:
- logging.info('Server wird beendet...')
+ logger.info('Server wird beendet...')
queue.close()
worker.terminate()
--- a/iro/job.py Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/job.py Fri Nov 27 01:14:51 2009 +0100
@@ -11,6 +11,8 @@
#You should have received a copy of the GNU General Public License
#along with this program; if not, see <http://www.gnu.org/licenses/>.
+import logging
+logger=logging.getLogger("job")
class Job(object):
'''
@@ -42,16 +44,14 @@
return None
def addGood(self, good):
- import logging
- logging.debug('Job(%d)-send to %s'%(self.id, str(good)))
+ logger.debug('Job(%d)-send to %s'%(self.id, str(good)))
if type(good) == list:
self.dStatus['good']=self.dStatus['good']+good
else:
self.dStatus['good'].append(good)
def addFailed(self, failed):
- import logging
- logging.debug('Job(%d)-faild to send to %s'%(self.id, str(failed)))
+ logger.debug('Job(%d)-faild to send to %s'%(self.id, str(failed)))
if type(failed) == list:
self.dStatus['failed']=self.dStatus['failed']+failed
else:
--- a/iro/worker.py Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/worker.py Fri Nov 27 01:14:51 2009 +0100
@@ -3,6 +3,7 @@
from multiprocessing import Process
import logging
+logger = logging.getLogger("iro.worker")
import time
class Worker(Process):
@@ -11,16 +12,16 @@
self.queue=queue
def run(self):
- logging.info('Worker thread läuft nun...')
+ logger.info('Worker thread läuft nun...')
id=0
while 1:
job=self.queue.get()
if job is None:
break # reached end of queue
id+=1
- logging.info('ein neuer Job(%d)' %(id))
+ logger.info('ein neuer Job(%d)' %(id))
try:
job.start(id)
- logging.info('Job(%d) fertig ;)'%(id))
+ logger.info('Job(%d) fertig ;)'%(id))
except:
- logging.exception('Job(%d) fehlgeschlagen :('%(id))
+ logger.exception('Job(%d) fehlgeschlagen :('%(id))