@property
def log_url(self):
- return self.backend.path_to_url(self.log_path)
+ """
+ Creates the URL to the log file without the compression extension.
+ """
+ log_path, extension = os.path.splitext(self.log_path)
+
+ return self.backend.path_to_url(log_path)
# Log Path
# Open Log
- async def open_log(self, decode=True):
+ async def open_log(self):
"""
Opens the log file, and returns an open file handle
"""
if not self.has_log():
raise FileNotFoundError
- return await asyncio.to_thread(self._open_log, self.log_path, decode=decode)
+ return await asyncio.to_thread(self._open_log, self.log_path)
- def _open_log(self, path, decode=True):
- if decode:
- # Open gzip-compressed files
- if path.endswith(".gz"):
- return gzip.open(path)
+ def _open_log(self, path):
+ # Open gzip-compressed files
+ if path.endswith(".gz"):
+ return gzip.open(path)
# Open uncompressed files
return open(path, "rb")
tail = self.get_argument_int("tail", None)
# Should we tail the log, or stream the entire file?
- try:
- if tail:
+ if tail:
+ try:
log = await job.tail_log(tail)
# Since we are processing this line-based,
# Done!
return
- # Automatically decompress the log
- decode = True
-
- if self.client_accepts_encoding("gzip"):
- decode = False
-
- # Tell the client we are sending this compressed
- self.set_header("Content-Encoding", "gzip")
-
- # If we are sending the entire file we won't split it by line before
- log = await job.open_log(decode=decode)
-
- while True:
- chunk = log.read(65536)
- if not chunk:
- break
-
- self.write(chunk)
+ # Send 404 if there is no log file
+ except FileNotFoundError as e:
+ raise tornado.web.HTTPError(404, "Could not find log for %s" % job) from e
- # Send 404 if there is no log file
- except FileNotFoundError as e:
- raise tornado.web.HTTPError(404, "Could not find log for %s" % job) from e
+ # Redirect the client
+ self.redirect(job.log_url, status=307)
class AbortHandler(base.BaseHandler):