[Zope3-checkins] CVS: Zope3/lib/python/Zope/Server/Logger - IMessageLogger.py:1.1 IRequestLogger.py:1.1 FileLogger.py:1.3 ResolvingLogger.py:1.3 RotatingFileLogger.py:1.3 SocketLogger.py:1.3 SyslogLogger.py:1.3 TailLogger.py:1.3 UnresolvingLogger.py:1.3 ILogger.py:NONE MultiLogger.py:NONE
Steve Alexander
steve@cat-box.net
Fri, 8 Nov 2002 09:34:59 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/Logger
In directory cvs.zope.org:/tmp/cvs-serv31354/lib/python/Zope/Server/Logger
Modified Files:
FileLogger.py ResolvingLogger.py RotatingFileLogger.py
SocketLogger.py SyslogLogger.py TailLogger.py
UnresolvingLogger.py
Added Files:
IMessageLogger.py IRequestLogger.py
Removed Files:
ILogger.py MultiLogger.py
Log Message:
various changes and a small refactoring to the Logger package.
This is the package that logs requests, typically in zope2 to a
Z2.log, and in zope3 by default to stdout.
=== Added File Zope3/lib/python/Zope/Server/Logger/IMessageLogger.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IMessageLogger.py,v 1.1 2002/11/08 14:34:58 stevea Exp $
"""
from Interface import Interface
class IMessageLogger(Interface):
"""This interface describes a message logger, which logs
with the resolution of one message.
"""
def logMessage(message):
"""Logs the message at the appropriate place."""
=== Added File Zope3/lib/python/Zope/Server/Logger/IRequestLogger.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IRequestLogger.py,v 1.1 2002/11/08 14:34:58 stevea Exp $
"""
from Interface import Interface
class IRequestLogger(Interface):
"""This interface describes a requets logger, which logs
ip addresses and messages.
"""
def logRequest(ip, message):
"""Logs the ip address and message at the appropriate place."""
=== Zope3/lib/python/Zope/Server/Logger/FileLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/FileLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/FileLogger.py Fri Nov 8 09:34:58 2002
@@ -17,71 +17,67 @@
"""
from types import StringType
-from ILogger import ILogger
-
+from IMessageLogger import IMessageLogger
class FileLogger:
"""Simple File Logger
"""
- __implements__ = ILogger
-
+ __implements__ = IMessageLogger
- def __init__ (self, file, flush=1, mode='a'):
+ def __init__(self, file, flush=1, mode='a'):
"""pass this either a path or a file object."""
if type(file) is StringType:
if (file == '-'):
import sys
self.file = sys.stdout
else:
- self.file = open (file, mode)
+ self.file = open(file, mode)
else:
self.file = file
self.do_flush = flush
- def __repr__ (self):
+ def __repr__(self):
return '<file logger: %s>' % self.file
- def write (self, data):
- self.file.write (data)
+ def write(self, data):
+ self.file.write(data)
self.maybe_flush()
- def writeline (self, line):
- self.file.writeline (line)
+ def writeline(self, line):
+ self.file.writeline(line)
self.maybe_flush()
- def writelines (self, lines):
- self.file.writelines (lines)
+ def writelines(self, lines):
+ self.file.writelines(lines)
self.maybe_flush()
- def maybe_flush (self):
+ def maybe_flush(self):
if self.do_flush:
self.file.flush()
-
- def flush (self):
+ def flush(self):
self.file.flush()
-
- def softspace (self, *args):
+ def softspace(self, *args):
pass
############################################################
# Implementation methods for interface
- # Zope.Server.Logger.ILogger
+ # Zope.Server.Logger.IMessageLogger
- def log(self, message):
- 'See Zope.Server.Logger.ILogger.ILogger'
+ def logMessage(self, message):
+ 'See Zope.Server.Logger.IMessageLogger.IMessageLogger'
if message[-1] not in ('\r', '\n'):
- self.write (message + '\n')
+ self.write(message + '\n')
else:
- self.write (message)
+ self.write(message)
#
############################################################
=== Zope3/lib/python/Zope/Server/Logger/ResolvingLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/ResolvingLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/ResolvingLogger.py Fri Nov 8 09:34:58 2002
@@ -15,7 +15,7 @@
$Id$
"""
-from ILogger import ILogger
+from IRequestLogger import IRequestLogger
class ResolvingLogger:
@@ -23,33 +23,34 @@
resolved hostname in front of the message. The message will not
be logged until the PTR request finishes (or fails)."""
- __implements__ = ILogger
+ __implements__ = IRequestLogger
- def __init__ (self, resolver, logger):
+ def __init__(self, resolver, logger):
self.resolver = resolver
+ # logger is an IMessageLogger
self.logger = logger
class logger_thunk:
- def __init__ (self, message, logger):
+ def __init__(self, message, logger):
self.message = message
self.logger = logger
- def __call__ (self, host, ttl, answer):
+ def __call__(self, host, ttl, answer):
if not answer:
answer = host
- self.logger.log ('%s: %s' % (answer, self.message))
+ self.logger.logMessage('%s: %s' % (answer, self.message))
############################################################
# Implementation methods for interface
- # Zope.Server.Logger.ILogger
+ # Zope.Server.Logger.IRequestLogger
- def log(self, ip, message):
- 'See Zope.Server.Logger.ILogger.ILogger'
- self.resolver.resolve_ptr (
+ def logRequest(self, ip, message):
+ 'See Zope.Server.Logger.IRequestLogger.IRequestLogger'
+ self.resolver.resolve_ptr(
ip,
- self.logger_thunk (
+ self.logger_thunk(
message,
self.logger
)
=== Zope3/lib/python/Zope/Server/Logger/RotatingFileLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/RotatingFileLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/RotatingFileLogger.py Fri Nov 8 09:34:58 2002
@@ -36,23 +36,20 @@
__implements__ = FileLogger.__implements__
-
- def __init__ (self, file, freq=None, maxsize=None, flush=1, mode='a'):
+ def __init__(self, file, freq=None, maxsize=None, flush=1, mode='a'):
self.filename = file
self.mode = mode
- self.file = open (file, mode)
+ self.file = open(file, mode)
self.freq = freq
self.maxsize = maxsize
self.rotate_when = self.next_backup(self.freq)
self.do_flush = flush
-
- def __repr__ (self):
+ def __repr__(self):
return '<rotating-file logger: %s>' % self.file
-
# We back up at midnight every 1) day, 2) monday, or 3) 1st of month
- def next_backup (self, freq):
+ def next_backup(self, freq):
(yr, mo, day, hr, min, sec, wd, jday, dst) = \
time.localtime(time.time())
if freq == 'daily':
@@ -65,14 +62,12 @@
else:
return None # not a date-based backup
-
- def maybe_flush (self): # rotate first if necessary
+ def maybe_flush(self): # rotate first if necessary
self.maybe_rotate()
if self.do_flush: # from file_logger()
self.file.flush()
-
- def maybe_rotate (self):
+ def maybe_rotate(self):
if self.freq and time.time() > self.rotate_when:
self.rotate()
self.rotate_when = self.next_backup(self.freq)
@@ -83,19 +78,18 @@
except os.error: # file not found, probably
self.rotate() # will create a new file
-
- def rotate (self):
- (yr, mo, day, hr, min, sec, wd, jday, dst) = \
- time.localtime(time.time())
+ def rotate(self):
+ yr, mo, day, hr, min, sec, wd, jday, dst = time.localtime(time.time())
try:
self.file.close()
newname = '%s.ends%04d%02d%02d' % (self.filename, yr, mo, day)
try:
open(newname, "r").close() # check if file exists
newname = newname + "-%02d%02d%02d" % (hr, min, sec)
- except: # YEARMODY is unique
+ except IOError: # concatenation of YEAR MO DY is unique
pass
os.rename(self.filename, newname)
self.file = open(self.filename, self.mode)
- except:
+ except IOError:
pass
+
=== Zope3/lib/python/Zope/Server/Logger/SocketLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/SocketLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/SocketLogger.py Fri Nov 8 09:34:58 2002
@@ -19,39 +19,35 @@
import asynchat
import socket
-from ILogger import ILogger
+from IMessageLogger import IMessageLogger
-
-class SocketLogger (asynchat.async_chat):
+class SocketLogger(asynchat.async_chat):
"""Log to a stream socket, asynchronously."""
- __implements__ = ILogger
-
- def __init__ (self, address):
+ __implements__ = IMessageLogger
+ def __init__(self, address):
if type(address) == type(''):
- self.create_socket (socket.AF_UNIX, socket.SOCK_STREAM)
+ self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
else:
- self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+ self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
- self.connect (address)
+ self.connect(address)
self.address = address
-
- def __repr__ (self):
+ def __repr__(self):
return '<socket logger: address=%s>' % (self.address)
-
############################################################
# Implementation methods for interface
- # Zope.Server.Logger.ILogger
+ # Zope.Server.Logger.IMessageLogger
- def log(self, message):
- 'See Zope.Server.Logger.ILogger.ILogger'
+ def logMessage(self, message):
+ 'See Zope.Server.Logger.IMessageLogger.IMessageLogger'
if message[-2:] != '\r\n':
- self.socket.push (message + '\r\n')
+ self.socket.push(message + '\r\n')
else:
- self.socket.push (message)
+ self.socket.push(message)
#
############################################################
=== Zope3/lib/python/Zope/Server/Logger/SyslogLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/SyslogLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/SyslogLogger.py Fri Nov 8 09:34:58 2002
@@ -19,7 +19,7 @@
import os
import m_syslog
-from ILogger import ILogger
+from IMessageLogger import IMessageLogger
class SyslogLogger(m_syslog.syslog_client):
@@ -34,7 +34,7 @@
blocking send()
"""
- __implements__ = ILogger
+ __implements__ = IMessageLogger
svc_name = 'zope'
pid_str = str(os.getpid())
@@ -51,10 +51,10 @@
############################################################
# Implementation methods for interface
- # Zope.Server.Logger.ILogger
+ # Zope.Server.Logger.IMessageLogger
- def log(self, message):
- 'See Zope.Server.Logger.ILogger.ILogger'
+ def logMessage(self, message):
+ 'See Zope.Server.Logger.IMessageLogger.IMessageLogger'
m_syslog.syslog_client.log (
self,
'%s[%s]: %s' % (self.svc_name, self.pid_str, message),
=== Zope3/lib/python/Zope/Server/Logger/TailLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/TailLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/TailLogger.py Fri Nov 8 09:34:58 2002
@@ -16,15 +16,14 @@
$Id$
"""
-from ILogger import ILogger
-
+from IMessageLogger import IMessageLogger
class TailLogger:
"""Keep track of the last <size> log messages"""
- __implements__ = ILogger
+ __implements__ = IMessageLogger
- def __init__ (self, logger, size=500):
+ def __init__(self, logger, size=500):
self.size = size
self.logger = logger
self.messages = []
@@ -32,20 +31,20 @@
############################################################
# Implementation methods for interface
- # Zope.Server.Logger.ILogger
+ # Zope.Server.Logger.IMessageLogger
- def log(self, message):
- 'See Zope.Server.Logger.ILogger.ILogger'
- self.messages.append (strip_eol (message))
- if len (self.messages) > self.size:
+ def logMessage(self, message):
+ 'See Zope.Server.Logger.IMessageLogger.IMessageLogger'
+ self.messages.append(strip_eol(message))
+ if len(self.messages) > self.size:
del self.messages[0]
- self.logger.log (message)
+ self.logger.logMessage(message)
#
############################################################
-def strip_eol (line):
+def strip_eol(line):
while line and line[-1] in '\r\n':
line = line[:-1]
return line
=== Zope3/lib/python/Zope/Server/Logger/UnresolvingLogger.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/Logger/UnresolvingLogger.py:1.2 Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/Logger/UnresolvingLogger.py Fri Nov 8 09:34:58 2002
@@ -15,25 +15,24 @@
$Id$
"""
-from ILogger import ILogger
-
+from IRequestLogger import IRequestLogger
class UnresolvingLogger:
"""Just in case you don't want to resolve"""
- __implements__ = ILogger
+ __implements__ = IRequestLogger
- def __init__ (self, logger):
+ def __init__(self, logger):
self.logger = logger
############################################################
# Implementation methods for interface
- # Zope.Server.Logger.ILogger
+ # Zope.Server.Logger.IRequestLogger
- def log(self, ip, message):
- 'See Zope.Server.Logger.ILogger.ILogger'
- self.logger.log ('%s: %s' % (ip, message))
+ def logRequest(self, ip, message):
+ 'See Zope.Server.Logger.IRequestLogger.IRequestLogger'
+ self.logger.logMessage('%s: %s' % (ip, message))
#
############################################################
=== Removed File Zope3/lib/python/Zope/Server/Logger/ILogger.py ===
=== Removed File Zope3/lib/python/Zope/Server/Logger/MultiLogger.py ===