[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/Logger - FileLogger.py:1.1.2.2 ILogger.py:1.1.2.2 MultiLogger.py:1.1.2.2 ResolvingLogger.py:1.1.2.2 RotatingFileLogger.py:1.1.2.2 SocketLogger.py:1.1.2.2 SyslogLogger.py:1.1.2.2 TailLogger.py:1.1.2.2 UnresolvingLogger.py:1.1.2.2 __init__.py:1.1.2.2 m_syslog.py:1.1.2.2
Shane Hathaway
shane@cvs.zope.org
Thu, 4 Apr 2002 13:46:28 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/Logger
In directory cvs.zope.org:/tmp/cvs-serv17993/Logger
Modified Files:
Tag: Zope3-Server-Branch
FileLogger.py ILogger.py MultiLogger.py ResolvingLogger.py
RotatingFileLogger.py SocketLogger.py SyslogLogger.py
TailLogger.py UnresolvingLogger.py __init__.py m_syslog.py
Log Message:
Just fixed line endings. No carriage returns.
=== Zope3/lib/python/Zope/Server/Logger/FileLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -25,10 +25,10 @@
"""
__implements__ = ILogger
-
+
def __init__ (self, file, flush=1, mode='a'):
- """pass this either a path or a file object."""
+ """pass this either a path or a file object."""
if type(file) is StringType:
if (file == '-'):
import sys
@@ -38,36 +38,36 @@
else:
self.file = file
self.do_flush = flush
-
+
def __repr__ (self):
return '<file logger: %s>' % self.file
-
+
def write (self, data):
self.file.write (data)
self.maybe_flush()
-
+
def writeline (self, line):
self.file.writeline (line)
self.maybe_flush()
-
+
def writelines (self, lines):
self.file.writelines (lines)
self.maybe_flush()
-
+
def maybe_flush (self):
if self.do_flush:
self.file.flush()
-
+
def flush (self):
self.file.flush()
-
+
def softspace (self, *args):
pass
=== Zope3/lib/python/Zope/Server/Logger/ILogger.py 1.1.2.1 => 1.1.2.2 ===
-#
-# 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$
-"""
-
-from Interface import Interface
-
-
-class ILogger(Interface):
- """This interface describes the methods any Logging object has to
- implement.
- """
-
- def log(message):
- """Logs the passed message at the appropriate place."""
+##############################################################################
+#
+# 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$
+"""
+
+from Interface import Interface
+
+
+class ILogger(Interface):
+ """This interface describes the methods any Logging object has to
+ implement.
+ """
+
+ def log(message):
+ """Logs the passed message at the appropriate place."""
=== Zope3/lib/python/Zope/Server/Logger/MultiLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -27,40 +27,40 @@
class MultiLogger:
"""Log to multiple places."""
-
+
def __init__ (self, loggers):
self.loggers = loggers
-
+
def __repr__ (self):
return '<multi logger: %s>' % (repr(self.loggers))
-
+
def log (self, message):
for logger in self.loggers:
logger.log (message)
-
+
class ResolvingLogger:
"""Feed (ip, message) combinations into this logger to get a
resolved hostname in front of the message. The message will not
be logged until the PTR request finishes (or fails)."""
-
+
def __init__ (self, resolver, logger):
self.resolver = resolver
self.logger = logger
-
+
class logger_thunk:
def __init__ (self, message, logger):
self.message = message
self.logger = logger
-
+
def __call__ (self, host, ttl, answer):
if not answer:
answer = host
self.logger.log ('%s%s' % (answer, self.message))
-
+
def log (self, ip, message):
self.resolver.resolve_ptr (
ip,
@@ -71,29 +71,29 @@
)
-
+
class UnresolvingLogger:
"""Just in case you don't want to resolve"""
def __init__ (self, logger):
self.logger = logger
-
+
def log (self, ip, message):
self.logger.log ('%s%s' % (ip, message))
-
-
+
+
def strip_eol (line):
while line and line[-1] in '\r\n':
line = line[:-1]
return line
-
+
class TailLogger:
"""Keep track of the last <size> log messages"""
def __init__ (self, logger, size=500):
self.size = size
self.logger = logger
self.messages = []
-
+
def log (self, message):
self.messages.append (strip_eol (message))
if len (self.messages) > self.size:
=== Zope3/lib/python/Zope/Server/Logger/ResolvingLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -17,7 +17,7 @@
"""
from ILogger import ILogger
-
+
class ResolvingLogger:
"""Feed (ip, message) combinations into this logger to get a
resolved hostname in front of the message. The message will not
@@ -29,12 +29,12 @@
self.resolver = resolver
self.logger = logger
-
+
class logger_thunk:
def __init__ (self, message, logger):
self.message = message
self.logger = logger
-
+
def __call__ (self, host, ttl, answer):
if not answer:
answer = host
=== Zope3/lib/python/Zope/Server/Logger/RotatingFileLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -17,11 +17,11 @@
"""
import time
-import os
+import os
import stat
from FileLogger import FileLogger
-
+
class RotatingFileLogger(FileLogger):
""" If freq is non-None we back up 'daily', 'weekly', or
'monthly'. Else if maxsize is non-None we back up whenever
@@ -35,7 +35,7 @@
"""
__implements__ = FileLogger.__implements__
-
+
def __init__ (self, file, freq=None, maxsize=None, flush=1, mode='a'):
self.filename = file
@@ -46,11 +46,11 @@
self.rotate_when = self.next_backup(self.freq)
self.do_flush = flush
-
+
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):
(yr, mo, day, hr, min, sec, wd, jday, dst) = \
@@ -59,19 +59,19 @@
return time.mktime((yr,mo,day+1, 0,0,0, 0,0,-1))
elif freq == 'weekly':
# wd(monday)==0
- return time.mktime((yr,mo,day-wd+7, 0,0,0, 0,0,-1))
+ return time.mktime((yr,mo,day-wd+7, 0,0,0, 0,0,-1))
elif freq == 'monthly':
return time.mktime((yr,mo+1,1, 0,0,0, 0,0,-1))
else:
return None # not a date-based backup
-
+
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):
if self.freq and time.time() > self.rotate_when:
self.rotate()
@@ -83,7 +83,7 @@
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())
=== Zope3/lib/python/Zope/Server/Logger/SocketLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -23,21 +23,21 @@
class SocketLogger (asynchat.async_chat):
- """Log to a stream socket, asynchronously."""
+ """Log to a stream socket, asynchronously."""
__implements__ = ILogger
def __init__ (self, address):
-
+
if type(address) == type(''):
self.create_socket (socket.AF_UNIX, socket.SOCK_STREAM)
else:
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
-
+
self.connect (address)
self.address = address
-
+
def __repr__ (self):
return '<socket logger: address=%s>' % (self.address)
=== Zope3/lib/python/Zope/Server/Logger/SyslogLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -35,7 +35,7 @@
"""
__implements__ = ILogger
-
+
svc_name = 'zope'
pid_str = str(os.getpid())
@@ -44,11 +44,11 @@
self.facility = m_syslog.facility_names[facility]
self.address=address
-
+
def __repr__ (self):
return '<syslog logger address=%s>' % (repr(self.address))
-
+
############################################################
# Implementation methods for interface
# Zope.Server.Logger.ILogger
=== Zope3/lib/python/Zope/Server/Logger/TailLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -18,7 +18,7 @@
from ILogger import ILogger
-
+
class TailLogger:
"""Keep track of the last <size> log messages"""
=== Zope3/lib/python/Zope/Server/Logger/UnresolvingLogger.py 1.1.2.1 => 1.1.2.2 ===
# 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.
-#
+#
##############################################################################
"""
@@ -17,7 +17,7 @@
"""
from ILogger import ILogger
-
+
class UnresolvingLogger:
"""Just in case you don't want to resolve"""
@@ -26,7 +26,7 @@
def __init__ (self, logger):
self.logger = logger
-
+
############################################################
# Implementation methods for interface
# Zope.Server.Logger.ILogger
=== Zope3/lib/python/Zope/Server/Logger/__init__.py 1.1.2.1 => 1.1.2.2 ===
-#
-# 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$
-"""
+##############################################################################
+#
+# 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$
+"""
=== Zope3/lib/python/Zope/Server/Logger/m_syslog.py 1.1.2.1 => 1.1.2.2 ===
# ======================================================================
# Copyright 1997 by Sam Rushing
-#
+#
# All Rights Reserved
-#
+#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
@@ -13,7 +13,7 @@
# Rushing not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
-#
+#
# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
@@ -65,73 +65,73 @@
#
# priorities (these are ordered)
-LOG_EMERG = 0 # system is unusable
-LOG_ALERT = 1 # action must be taken immediately
-LOG_CRIT = 2 # critical conditions
-LOG_ERR = 3 # error conditions
-LOG_WARNING = 4 # warning conditions
-LOG_NOTICE = 5 # normal but significant condition
-LOG_INFO = 6 # informational
-LOG_DEBUG = 7 # debug-level messages
-
-# facility codes
-LOG_KERN = 0 # kernel messages
-LOG_USER = 1 # random user-level messages
-LOG_MAIL = 2 # mail system
-LOG_DAEMON = 3 # system daemons
-LOG_AUTH = 4 # security/authorization messages
-LOG_SYSLOG = 5 # messages generated internally by syslogd
-LOG_LPR = 6 # line printer subsystem
-LOG_NEWS = 7 # network news subsystem
-LOG_UUCP = 8 # UUCP subsystem
-LOG_CRON = 9 # clock daemon
-LOG_AUTHPRIV = 10 # security/authorization messages (private)
-
-# other codes through 15 reserved for system use
-LOG_LOCAL0 = 16 # reserved for local use
-LOG_LOCAL1 = 17 # reserved for local use
-LOG_LOCAL2 = 18 # reserved for local use
-LOG_LOCAL3 = 19 # reserved for local use
-LOG_LOCAL4 = 20 # reserved for local use
-LOG_LOCAL5 = 21 # reserved for local use
-LOG_LOCAL6 = 22 # reserved for local use
-LOG_LOCAL7 = 23 # reserved for local use
+LOG_EMERG = 0 # system is unusable
+LOG_ALERT = 1 # action must be taken immediately
+LOG_CRIT = 2 # critical conditions
+LOG_ERR = 3 # error conditions
+LOG_WARNING = 4 # warning conditions
+LOG_NOTICE = 5 # normal but significant condition
+LOG_INFO = 6 # informational
+LOG_DEBUG = 7 # debug-level messages
+
+# facility codes
+LOG_KERN = 0 # kernel messages
+LOG_USER = 1 # random user-level messages
+LOG_MAIL = 2 # mail system
+LOG_DAEMON = 3 # system daemons
+LOG_AUTH = 4 # security/authorization messages
+LOG_SYSLOG = 5 # messages generated internally by syslogd
+LOG_LPR = 6 # line printer subsystem
+LOG_NEWS = 7 # network news subsystem
+LOG_UUCP = 8 # UUCP subsystem
+LOG_CRON = 9 # clock daemon
+LOG_AUTHPRIV = 10 # security/authorization messages (private)
+
+# other codes through 15 reserved for system use
+LOG_LOCAL0 = 16 # reserved for local use
+LOG_LOCAL1 = 17 # reserved for local use
+LOG_LOCAL2 = 18 # reserved for local use
+LOG_LOCAL3 = 19 # reserved for local use
+LOG_LOCAL4 = 20 # reserved for local use
+LOG_LOCAL5 = 21 # reserved for local use
+LOG_LOCAL6 = 22 # reserved for local use
+LOG_LOCAL7 = 23 # reserved for local use
priority_names = {
- "alert": LOG_ALERT,
- "crit": LOG_CRIT,
- "debug": LOG_DEBUG,
- "emerg": LOG_EMERG,
- "err": LOG_ERR,
- "error": LOG_ERR, # DEPRECATED
- "info": LOG_INFO,
- "notice": LOG_NOTICE,
- "panic": LOG_EMERG, # DEPRECATED
- "warn": LOG_WARNING, # DEPRECATED
- "warning": LOG_WARNING,
+ "alert": LOG_ALERT,
+ "crit": LOG_CRIT,
+ "debug": LOG_DEBUG,
+ "emerg": LOG_EMERG,
+ "err": LOG_ERR,
+ "error": LOG_ERR, # DEPRECATED
+ "info": LOG_INFO,
+ "notice": LOG_NOTICE,
+ "panic": LOG_EMERG, # DEPRECATED
+ "warn": LOG_WARNING, # DEPRECATED
+ "warning": LOG_WARNING,
}
facility_names = {
- "auth": LOG_AUTH,
- "authpriv": LOG_AUTHPRIV,
- "cron": LOG_CRON,
- "daemon": LOG_DAEMON,
- "kern": LOG_KERN,
- "lpr": LOG_LPR,
- "mail": LOG_MAIL,
- "news": LOG_NEWS,
- "security": LOG_AUTH, # DEPRECATED
- "syslog": LOG_SYSLOG,
- "user": LOG_USER,
- "uucp": LOG_UUCP,
- "local0": LOG_LOCAL0,
- "local1": LOG_LOCAL1,
- "local2": LOG_LOCAL2,
- "local3": LOG_LOCAL3,
- "local4": LOG_LOCAL4,
- "local5": LOG_LOCAL5,
- "local6": LOG_LOCAL6,
- "local7": LOG_LOCAL7,
+ "auth": LOG_AUTH,
+ "authpriv": LOG_AUTHPRIV,
+ "cron": LOG_CRON,
+ "daemon": LOG_DAEMON,
+ "kern": LOG_KERN,
+ "lpr": LOG_LPR,
+ "mail": LOG_MAIL,
+ "news": LOG_NEWS,
+ "security": LOG_AUTH, # DEPRECATED
+ "syslog": LOG_SYSLOG,
+ "user": LOG_USER,
+ "uucp": LOG_UUCP,
+ "local0": LOG_LOCAL0,
+ "local1": LOG_LOCAL1,
+ "local2": LOG_LOCAL2,
+ "local3": LOG_LOCAL3,
+ "local4": LOG_LOCAL4,
+ "local5": LOG_LOCAL5,
+ "local6": LOG_LOCAL6,
+ "local7": LOG_LOCAL7,
}
import socket
@@ -155,9 +155,9 @@
, socket.SOCK_DGRAM)
self.unix = 0
-
+
log_format_string = '<%d>%s\000'
-
+
def log (self, message, facility=LOG_USER, priority=LOG_INFO):
message = self.log_format_string % (
self.encode_priority (facility, priority),
@@ -167,15 +167,15 @@
self.socket.send (message)
else:
self.socket.sendto (message, self.address)
-
+
def encode_priority (self, facility, priority):
if type(facility) == type(''):
facility = facility_names[facility]
if type(priority) == type(''):
- priority = priority_names[priority]
+ priority = priority_names[priority]
return (facility<<3) | priority
-
+
def close (self):
if self.unix:
self.socket.close()
-
+