Emit a record. Send the record to the web server as a percent-encoded dictionary
(self, record)
| 1273 | return connection |
| 1274 | |
| 1275 | def emit(self, record): |
| 1276 | """ |
| 1277 | Emit a record. |
| 1278 | |
| 1279 | Send the record to the web server as a percent-encoded dictionary |
| 1280 | """ |
| 1281 | try: |
| 1282 | import urllib.parse |
| 1283 | host = self.host |
| 1284 | h = self.getConnection(host, self.secure) |
| 1285 | url = self.url |
| 1286 | data = urllib.parse.urlencode(self.mapLogRecord(record)) |
| 1287 | if self.method == "GET": |
| 1288 | if (url.find('?') >= 0): |
| 1289 | sep = '&' |
| 1290 | else: |
| 1291 | sep = '?' |
| 1292 | url = url + "%c%s" % (sep, data) |
| 1293 | h.putrequest(self.method, url) |
| 1294 | # support multiple hosts on one IP address... |
| 1295 | # need to strip optional :port from host, if present |
| 1296 | i = host.find(":") |
| 1297 | if i >= 0: |
| 1298 | host = host[:i] |
| 1299 | # See issue #30904: putrequest call above already adds this header |
| 1300 | # on Python 3.x. |
| 1301 | # h.putheader("Host", host) |
| 1302 | if self.method == "POST": |
| 1303 | h.putheader("Content-type", |
| 1304 | "application/x-www-form-urlencoded") |
| 1305 | h.putheader("Content-length", str(len(data))) |
| 1306 | if self.credentials: |
| 1307 | import base64 |
| 1308 | s = ('%s:%s' % self.credentials).encode('utf-8') |
| 1309 | s = 'Basic ' + base64.b64encode(s).strip().decode('ascii') |
| 1310 | h.putheader('Authorization', s) |
| 1311 | h.endheaders() |
| 1312 | if self.method == "POST": |
| 1313 | h.send(data.encode('utf-8')) |
| 1314 | h.getresponse() #can't do anything with the result |
| 1315 | except Exception: |
| 1316 | self.handleError(record) |
| 1317 | |
| 1318 | class BufferingHandler(logging.Handler): |
| 1319 | """ |
nothing calls this directly
no test coverage detected