@@ -977,7 +977,7 @@ class HTTPHandler(logging.Handler):
977977 A class which sends records to a Web server, using either GET or
978978 POST semantics.
979979 """
980- def __init__ (self , host , url , method = "GET" ):
980+ def __init__ (self , host , url , method = "GET" , secure = False , credentials = None ):
981981 """
982982 Initialize the instance with the host, the request URL, and the method
983983 ("GET" or "POST")
@@ -989,12 +989,14 @@ def __init__(self, host, url, method="GET"):
989989 self .host = host
990990 self .url = url
991991 self .method = method
992+ self .secure = secure
993+ self .credentials = credentials
992994
993995 def mapLogRecord (self , record ):
994996 """
995997 Default implementation of mapping the log record into a dict
996998 that is sent as the CGI data. Overwrite in your class.
997- Contributed by Franz Glasner.
999+ Contributed by Franz Glasner.
9981000 """
9991001 return record .__dict__
10001002
@@ -1007,7 +1009,10 @@ def emit(self, record):
10071009 try :
10081010 import http .client , urllib .parse
10091011 host = self .host
1010- h = http .client .HTTP (host )
1012+ if self .secure :
1013+ h = http .client .HTTPSConnection (host )
1014+ else :
1015+ h = http .client .HTTPConnection (host )
10111016 url = self .url
10121017 data = urllib .parse .urlencode (self .mapLogRecord (record ))
10131018 if self .method == "GET" :
@@ -1027,8 +1032,13 @@ def emit(self, record):
10271032 h .putheader ("Content-type" ,
10281033 "application/x-www-form-urlencoded" )
10291034 h .putheader ("Content-length" , str (len (data )))
1035+ if self .credentials :
1036+ import base64
1037+ s = ('u%s:%s' % self .credentials ).encode ('utf-8' )
1038+ s = 'Basic ' + base64 .b64encode (s ).strip ()
1039+ h .putheader ('Authorization' , s )
10301040 h .endheaders (data if self .method == "POST" else None )
1031- h .getreply () #can't do anything with the result
1041+ h .getresponse () #can't do anything with the result
10321042 except (KeyboardInterrupt , SystemExit ):
10331043 raise
10341044 except :
0 commit comments