diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-10-10 20:32:36 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-10-10 20:32:36 (GMT) |
commit | cbabd7ec3aa589bda8f636f4b23c294604d07c63 (patch) | |
tree | 9e0eee5ad8d7a80d86c16c3258f983f7b774aa4e /Lib/logging | |
parent | bec4d57a392179e23d2eec51db4bdc0806d692ee (diff) | |
download | cpython-cbabd7ec3aa589bda8f636f4b23c294604d07c63.zip cpython-cbabd7ec3aa589bda8f636f4b23c294604d07c63.tar.gz cpython-cbabd7ec3aa589bda8f636f4b23c294604d07c63.tar.bz2 |
Issue #7086: Added TCP support to SysLogHandler and tidied up some anachronisms in the code.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 4 | ||||
-rw-r--r-- | Lib/logging/config.py | 2 | ||||
-rw-r--r-- | Lib/logging/handlers.py | 19 |
3 files changed, 16 insertions, 9 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 8af9e0f..033fecd 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -46,8 +46,8 @@ except ImportError: __author__ = "Vinay Sajip <vinay_sajip@red-dove.com>" __status__ = "production" -__version__ = "0.5.0.7" -__date__ = "20 January 2009" +__version__ = "0.5.0.9" +__date__ = "09 October 2009" #--------------------------------------------------------------------------- # Miscellaneous module data diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 07574d3..d5b82b7 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -19,7 +19,7 @@ Configuration functions for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. -Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! """ diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 31352ad..2d71470 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -1,4 +1,4 @@ -# Copyright 2001-2007 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -41,6 +41,7 @@ DEFAULT_UDP_LOGGING_PORT = 9021 DEFAULT_HTTP_LOGGING_PORT = 9022 DEFAULT_SOAP_LOGGING_PORT = 9023 SYSLOG_UDP_PORT = 514 +SYSLOG_TCP_PORT = 514 _MIDNIGHT = 24 * 60 * 60 # number of seconds in a day @@ -155,7 +156,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler): If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted. """ - def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=0, utc=False): + def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False): BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay) self.when = when.upper() self.backupCount = backupCount @@ -690,7 +691,8 @@ class SysLogHandler(logging.Handler): "CRITICAL" : "critical" } - def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER): + def __init__(self, address=('localhost', SYSLOG_UDP_PORT), + facility=LOG_USER, socktype=socket.SOCK_DGRAM): """ Initialize a handler. @@ -702,13 +704,16 @@ class SysLogHandler(logging.Handler): self.address = address self.facility = facility + self.socktype = socktype + if isinstance(address, str): self.unixsocket = 1 self._connect_unixsocket(address) else: self.unixsocket = 0 - self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - + self.socket = socket.socket(socket.AF_INET, socktype) + if socktype == socket.SOCK_STREAM: + self.socket.connect(address) self.formatter = None def _connect_unixsocket(self, address): @@ -781,8 +786,10 @@ class SysLogHandler(logging.Handler): except socket.error: self._connect_unixsocket(self.address) self.socket.send(msg) - else: + elif self.socktype == socket.SOCK_DGRAM: self.socket.sendto(msg, self.address) + else: + self.socket.sendall(msg) except (KeyboardInterrupt, SystemExit): raise except: |