Skip to content
Browse files

using more logging in jabber daemon

  • Loading branch information...
1 parent 5885209 commit 30343c1d638530b5369a9e3acb4f9d3fe6291dd3 @Apkawa committed Feb 26, 2011
Showing with 27 additions and 37 deletions.
  1. +6 −3 nyasha/jabber_daemon/core.py
  2. +10 −32 nyasha/jabber_daemon/management/commands/runjabber.py
  3. +11 −0 nyasha/settings.py
  4. +0 −2 nyasha/utils/daemon.py
View
9 nyasha/jabber_daemon/core.py
@@ -417,10 +417,13 @@ def run_loop_tasks(self):
-logger = logging.getLogger()
+logger = logging.getLogger('jabber_daemon.core')
logger.addHandler(logging.StreamHandler())
-logger.setLevel(logging.DEBUG) # change to DEBUG for higher verbosity
-#logger.setLevel(logging.INFO) # change to DEBUG for higher verbosity
+#logger.setLevel(logging.DEBUG) # change to DEBUG for higher verbosity
+logger.setLevel(logging.INFO) # change to DEBUG for higher verbosity
+for name in ['pyxmpp.StreamSASLMixIn', 'pyxmpp.StreamTLSMixIn', 'pyxmpp.sasl.DigestMD5ClientAuthenticator']:
+ logging.getLogger(name).setLevel(logging.ERROR)
+
def main():
jid = JID("testnanodesu@jabber.ru")
View
42 nyasha/jabber_daemon/management/commands/runjabber.py
@@ -1,17 +1,20 @@
# -*- coding: utf-8 -*-
import sys
import datetime
+import logging
from django.conf import settings
from optparse import make_option
from django.core.management.base import BaseCommand
from utils.daemon import BaseDaemon, run_pool
from jabber_daemon.core import Client, TimeoutException
+logger = logging.getLogger('jabber_daemon.runjabber')
+
class Command(BaseDaemon):
option_list = BaseDaemon.option_list + (
make_option('-r', '--autoreload', dest='reload', action='store_true',
- help='enable autoreload code')
+ help='enable autoreload code'),
)
def run_jabber_client(self):
@@ -32,12 +35,13 @@ def run_jabber_client(self):
except KeyboardInterrupt:
c.disconnect()
break
+ except Exception, error:
+ logger.exception(error)
+ c.disconnect()
+ c.connect()
+ continue
- def handle(self, *args, **options):
- if options.get('daemon'):
- cbd = JabberDaemon()
- cbd.runserver(*args, **options)
- return
+ def start_server(self, options):
if options.get('reload'):
from utils.autoreload import main
while True:
@@ -51,32 +55,6 @@ def handle(self, *args, **options):
def usage(self, subcommand):
return 'runjabber'
- def start_server(self, options):
- if options['daemon'] and options['user'] and options['group']:
- #ensure the that the daemon runs as specified user
- self.change_uid_gid(options['user'], options['group'])
- jid = settings.JABBER_BOT_SETTINGS['jid']
- password = settings.JABBER_BOT_SETTINGS['password']
- resource = settings.JABBER_BOT_SETTINGS['resource']
- print jid
- c = Client(jid, password, resource)
- c.connect()
- while True:
- try:
- c.loop(1)
- break
- except TimeoutException:
- c.disconnect()
- c.connect()
- continue
- except KeyboardInterrupt:
- c.disconnect()
- break
- except Exception, error:
- #
- c.disconnect()
- c.connect()
- continue
View
11 nyasha/settings.py
@@ -1,9 +1,20 @@
import os
+import logging
+
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
+level = logging.ERROR
+if DEBUG:
+ level = logging.DEBUG
+logging.basicConfig(level=level,
+ format='%(asctime)s %(name)-20s %(levelname)-8s %(message)s',
+ datefmt='%d-%m-%Y %H:%M:%S',
+ filename='/tmp/nyasha.log',
+ filemode='w')
+
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
View
2 nyasha/utils/daemon.py
@@ -117,8 +117,6 @@ class BaseDaemon(BaseCommand):
dest='stop', help='Stop daemond'),
make_option('-d', '--daemon', action='store_true',
dest='daemon', help='Daemonize'),
- make_option('-w', '--workers', dest='workers', type='int',
- help='Number of Workers threads', default=1),
)
def change_uid_gid(self, uid, gid=None):

0 comments on commit 30343c1

Please sign in to comment.
Something went wrong with that request. Please try again.