From fd89e342264bafd4f9dd1fb432bfda3c5195e0a9 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 26 Nov 2003 00:02:43 +0000 Subject: [PATCH] Logger plugin is now available ! --- common/thread.py | 3 ++ core/core.py | 12 +++++- doc/gajimrc | 7 ++++ plugins/__init__.py | 1 + plugins/logger.py | 93 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 plugins/logger.py diff --git a/common/thread.py b/common/thread.py index c296c41f1..e90ec1f2f 100644 --- a/common/thread.py +++ b/common/thread.py @@ -34,7 +34,10 @@ class GajimThread(threading.Thread): # END __init__ def run(self): + #This is VERY bad if self.getName() == 'gtkgui': plugins.gtkgui.plugin(self.queueIn, self.queueOut) + elif self.getName() == 'logger': + plugins.logger.plugin(self.queueIn, self.queueOut) # END run # END GajimThread diff --git a/core/core.py b/core/core.py index 10a0b6543..18b8e04f2 100644 --- a/core/core.py +++ b/core/core.py @@ -121,6 +121,7 @@ class GajimCore: if ev[0] == 'QUIT': if self.connected == 1: self.con.disconnect() + self.hub.sendPlugin('QUIT', ()) return #('STATUS', status) elif ev[0] == 'STATUS': @@ -138,6 +139,7 @@ class GajimCore: msg = common.jabber.Message(ev[1][0], ev[1][1]) msg.setType('chat') self.con.send(msg) + self.hub.sendPlugin('MSGSENT', ev[1]) #('SUB', (jid, txt)) elif ev[0] == 'SUB': log.debug('subscription request for %s' % ev[1][0]) @@ -180,7 +182,7 @@ class GajimCore: def start(): gc = GajimCore() - guiPl = gc.hub.newPlugin ('gtkgui') + guiPl = gc.hub.newPlugin('gtkgui') gc.hub.register('gtkgui', 'ROSTER') gc.hub.register('gtkgui', 'NOTIFY') gc.hub.register('gtkgui', 'MSG') @@ -188,5 +190,11 @@ def start(): gc.hub.register('gtkgui', 'SUBSCRIBE') gc.hub.register('gtkgui', 'AGENTS') gc.hub.register('gtkgui', 'AGENT_INFO') - guiPl.load () + guiPl.load() + logPl = gc.hub.newPlugin('logger') + gc.hub.register('logger', 'MSG') + gc.hub.register('logger', 'MSGSENT') + gc.hub.register('logger', 'NOTIFY') + gc.hub.register('logger', 'QUIT') + logPl.load() gc.mainLoop() diff --git a/doc/gajimrc b/doc/gajimrc index 4ae85bc86..bef91d383 100644 --- a/doc/gajimrc +++ b/doc/gajimrc @@ -21,3 +21,10 @@ inmsgcolor = red outmsgcolor = blue iconstyle = sun autopopup = 0 + +[Logger] + +#Log notify messages in a separate file (notify.log) +lognotsep = 1 +#Log notify messages in user log file +lognotusr = 1 diff --git a/plugins/__init__.py b/plugins/__init__.py index c6905daec..bf20e5702 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -1 +1,2 @@ import gtkgui +import logger diff --git a/plugins/logger.py b/plugins/logger.py new file mode 100644 index 000000000..202c741f2 --- /dev/null +++ b/plugins/logger.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +## plugins/logger.py +## +## Gajim Team: +## - Yann Le Boulanger +## - Vincent Hanquez +## - David Ferlier +## +## Copyright (C) 2003 Gajim Team +## +## 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; version 2 only. +## +## 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. +## + +import os +import string +import time +import common.optparser +CONFPATH = "~/.gajimrc" +LOGPATH = os.path.expanduser("~/.gajim/logs/") + +class plugin: + def read_queue(self): + while 1: + while self.queueIN.empty() == 0: + lognotsep = self.cfgParser.Logger_lognotsep + if lognotsep: + lognotsep = string.atoi(lognotsep) + else: + #default + lognotsep = 1 + lognotusr = self.cfgParser.Logger_lognotusr + if lognotusr: + lognotusr = string.atoi(lognotusr) + else: + #default + lognotusr = 1 + ev = self.queueIN.get() + if ev[0] == 'QUIT': + return + elif ev[0] == 'NOTIFY': + status = ev[1][2] + if not status: + status = "" + if lognotsep == 1: + fic = open(LOGPATH + "notify.log", "a") + fic.write("%d:%s:%s:%s\n" % (time.time(), ev[1][0], \ + ev[1][1], status)) + fic.close() + if lognotusr == 1: + fic = open(LOGPATH + ev[1][0], "a") + fic.write("%d:%s:%s:%s\n" % (time.time(), ev[1][0], \ + ev[1][1], status)) + fic.close() + elif ev[0] == 'MSG': + fic = open(LOGPATH + ev[1][0], "a") + fic.write("%d:recv:%s\n" % (time.time(), ev[1][1])) + fic.close() + elif ev[0] == 'MSGSENT': + fic = open(LOGPATH + ev[1][0], "a") + fic.write("%d:sent:%s\n" % (time.time(), ev[1][1])) + fic.close() + time.sleep(0.5) + + def __init__(self, quIN, quOUT): + self.cfgParser = common.optparser.OptionsParser(CONFPATH) + self.cfgParser.parseCfgFile() + self.queueIN = quIN + self.queueOUT = quOUT + #create ~/.gajim/logs if it doesn't exist + try: + os.stat(os.path.expanduser("~/.gajim")) + except OSError: + os.mkdir(os.path.expanduser("~/.gajim")) + print "creating ~/.gajim/" + try: + os.stat(LOGPATH) + except OSError: + os.mkdir(LOGPATH) + print "creating ~/.gajim/logs/" + self.read_queue() + + +if __name__ == "__main__": + plugin(None, None) + +print "plugin logger loaded"