1- # Copyright 2001-2007 by Vinay Sajip. All Rights Reserved.
1+ # Copyright 2001-2009 by Vinay Sajip. All Rights Reserved.
22#
33# Permission to use, copy, modify, and distribute this software and its
44# documentation for any purpose and without fee is hereby granted,
4141DEFAULT_HTTP_LOGGING_PORT = 9022
4242DEFAULT_SOAP_LOGGING_PORT = 9023
4343SYSLOG_UDP_PORT = 514
44+ SYSLOG_TCP_PORT = 514
4445
4546_MIDNIGHT = 24 * 60 * 60 # number of seconds in a day
4647
@@ -155,7 +156,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
155156 If backupCount is > 0, when rollover is done, no more than backupCount
156157 files are kept - the oldest ones are deleted.
157158 """
158- def __init__ (self , filename , when = 'h' , interval = 1 , backupCount = 0 , encoding = None , delay = 0 , utc = False ):
159+ def __init__ (self , filename , when = 'h' , interval = 1 , backupCount = 0 , encoding = None , delay = False , utc = False ):
159160 BaseRotatingHandler .__init__ (self , filename , 'a' , encoding , delay )
160161 self .when = when .upper ()
161162 self .backupCount = backupCount
@@ -690,7 +691,8 @@ class SysLogHandler(logging.Handler):
690691 "CRITICAL" : "critical"
691692 }
692693
693- def __init__ (self , address = ('localhost' , SYSLOG_UDP_PORT ), facility = LOG_USER ):
694+ def __init__ (self , address = ('localhost' , SYSLOG_UDP_PORT ),
695+ facility = LOG_USER , socktype = socket .SOCK_DGRAM ):
694696 """
695697 Initialize a handler.
696698
@@ -702,13 +704,16 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):
702704
703705 self .address = address
704706 self .facility = facility
707+ self .socktype = socktype
708+
705709 if isinstance (address , str ):
706710 self .unixsocket = 1
707711 self ._connect_unixsocket (address )
708712 else :
709713 self .unixsocket = 0
710- self .socket = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
711-
714+ self .socket = socket .socket (socket .AF_INET , socktype )
715+ if socktype == socket .SOCK_STREAM :
716+ self .socket .connect (address )
712717 self .formatter = None
713718
714719 def _connect_unixsocket (self , address ):
@@ -781,8 +786,10 @@ def emit(self, record):
781786 except socket .error :
782787 self ._connect_unixsocket (self .address )
783788 self .socket .send (msg )
784- else :
789+ elif self . socktype == socket . SOCK_DGRAM :
785790 self .socket .sendto (msg , self .address )
791+ else :
792+ self .socket .sendall (msg )
786793 except (KeyboardInterrupt , SystemExit ):
787794 raise
788795 except :
0 commit comments