mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Fix for logging with multiple networks.
This commit is contained in:
parent
1932ed4d02
commit
9c08a192d5
@ -112,11 +112,11 @@ class ChannelLogger(callbacks.Privmsg):
|
|||||||
self.__parent.__init__()
|
self.__parent.__init__()
|
||||||
self.lastMsg = None
|
self.lastMsg = None
|
||||||
self.laststate = None
|
self.laststate = None
|
||||||
self.logs = ircutils.IrcDict()
|
self.logs = {}
|
||||||
world.flushers.append(self.flush)
|
world.flushers.append(self.flush)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
for log in self.logs.itervalues():
|
for log in self._logs():
|
||||||
log.close()
|
log.close()
|
||||||
world.flushers = [x for x in world.flushers
|
world.flushers = [x for x in world.flushers
|
||||||
if hasattr(x, 'im_class') and
|
if hasattr(x, 'im_class') and
|
||||||
@ -124,7 +124,8 @@ class ChannelLogger(callbacks.Privmsg):
|
|||||||
|
|
||||||
def __call__(self, irc, msg):
|
def __call__(self, irc, msg):
|
||||||
try:
|
try:
|
||||||
super(self.__class__, self).__call__(irc, msg)
|
if msg.args and irc.isChannel(msg.args[0]):
|
||||||
|
super(self.__class__, self).__call__(irc, msg)
|
||||||
if self.lastMsg:
|
if self.lastMsg:
|
||||||
self.laststate.addMsg(irc, self.lastMsg)
|
self.laststate.addMsg(irc, self.lastMsg)
|
||||||
else:
|
else:
|
||||||
@ -134,18 +135,23 @@ class ChannelLogger(callbacks.Privmsg):
|
|||||||
self.lastMsg = msg
|
self.lastMsg = msg
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
for log in self.logs.itervalues():
|
for log in self._logs():
|
||||||
log.close()
|
log.close()
|
||||||
self.logs.clear()
|
self.logs.clear()
|
||||||
|
|
||||||
|
def _logs(self):
|
||||||
|
for logs in self.logs.itervalues():
|
||||||
|
for log in logs.itervalues():
|
||||||
|
yield log
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.checkLogNames()
|
self.checkLogNames()
|
||||||
try:
|
for log in self._logs():
|
||||||
for log in self.logs.itervalues():
|
try:
|
||||||
log.flush()
|
log.flush()
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
if e.args[0] != 'I/O operation on a closed file':
|
if e.args[0] != 'I/O operation on a closed file':
|
||||||
self.log.exception('Odd exception:')
|
self.log.exception('Odd exception:')
|
||||||
|
|
||||||
def logNameTimestamp(self, channel):
|
def logNameTimestamp(self, channel):
|
||||||
format = self.registryValue('filenameTimestamp', channel)
|
format = self.registryValue('filenameTimestamp', channel)
|
||||||
@ -174,23 +180,29 @@ class ChannelLogger(callbacks.Privmsg):
|
|||||||
return logDir
|
return logDir
|
||||||
|
|
||||||
def checkLogNames(self):
|
def checkLogNames(self):
|
||||||
for (channel, log) in self.logs.items():
|
for (irc, logs) in self.logs.items():
|
||||||
if self.registryValue('rotateLogs', channel):
|
for (channel, log) in logs.items():
|
||||||
name = self.getLogName(channel)
|
if self.registryValue('rotateLogs', channel):
|
||||||
if name != log.name:
|
name = self.getLogName(channel)
|
||||||
log.close()
|
if name != log.name:
|
||||||
del self.logs[channel]
|
log.close()
|
||||||
|
del logs[channel]
|
||||||
|
|
||||||
def getLog(self, irc, channel):
|
def getLog(self, irc, channel):
|
||||||
self.checkLogNames()
|
self.checkLogNames()
|
||||||
if channel in self.logs:
|
try:
|
||||||
return self.logs[channel]
|
logs = self.logs[irc]
|
||||||
|
except KeyError:
|
||||||
|
logs = ircutils.IrcDict()
|
||||||
|
self.logs[irc] = logs
|
||||||
|
if channel in logs:
|
||||||
|
return logs[channel]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
name = self.getLogName(channel)
|
name = self.getLogName(channel)
|
||||||
logDir = self.getLogDir(irc, channel)
|
logDir = self.getLogDir(irc, channel)
|
||||||
log = file(os.path.join(logDir, name), 'a')
|
log = file(os.path.join(logDir, name), 'a')
|
||||||
self.logs[channel] = log
|
logs[channel] = log
|
||||||
return log
|
return log
|
||||||
except IOError:
|
except IOError:
|
||||||
self.log.exception('Error opening log:')
|
self.log.exception('Error opening log:')
|
||||||
|
Loading…
Reference in New Issue
Block a user