def getLog(self, bytes, log, params): path = girder.getLogPaths()[log] filesize = os.path.getsize(path) length = bytes or filesize def stream(): yield '=== Last %d bytes of %s: ===\n\n' % (min(length, filesize), path) with open(path, 'rb') as f: if length < filesize: f.seek(-length, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data return stream
def getLog(self, params): self.requireParams(['log', 'bytes'], params) if params['log'] not in ('error', 'info'): raise RestException('Log should be "error" or "info".') path = girder.getLogPaths()[params['log']] filesize = os.path.getsize(path) length = int(params['bytes']) or filesize def stream(): yield '=== Last %d bytes of %s: ===\n\n' % ( min(length, filesize), path ) with open(path, 'rb') as f: if length < filesize: f.seek(-length, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data return stream
def getLog(self, params): self.requireParams(['log', 'bytes'], params) if params['log'] not in ('error', 'info'): raise RestException('Log should be "error" or "info".') path = girder.getLogPaths()[params['log']] filesize = os.path.getsize(path) length = int(params['bytes']) or filesize def stream(): yield '=== Last %d bytes of %s: ===\n\n' % (min(length, filesize), path) with open(path, 'rb') as f: if length < filesize: f.seek(-length, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data return stream
def getLog(self, bytes, log): path = girder.getLogPaths()[log] filesize = os.path.getsize(path) length = int(bytes) or filesize filesize1 = 0 if length > filesize: path1 = path + '.1' if os.path.exists(path1): filesize1 = os.path.getsize(path1) def stream(): yield '=== Last %d bytes of %s: ===\n\n' % (min( length, filesize + filesize1), path) readlength = length if readlength > filesize and filesize1: readlength = length - filesize with open(path1, 'rb') as f: if readlength < filesize1: f.seek(-readlength, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data readlength = filesize with open(path, 'rb') as f: if readlength < filesize: f.seek(-readlength, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data return stream
def getLog(self, bytes, log): path = girder.getLogPaths()[log] filesize = os.path.getsize(path) length = int(bytes) or filesize filesize1 = 0 if length > filesize: path1 = path + '.1' if os.path.exists(path1): filesize1 = os.path.getsize(path1) def stream(): yield '=== Last %d bytes of %s: ===\n\n' % ( min(length, filesize + filesize1), path ) readlength = length if readlength > filesize and filesize1: readlength = length - filesize with open(path1, 'rb') as f: if readlength < filesize1: f.seek(-readlength, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data readlength = filesize with open(path, 'rb') as f: if readlength < filesize: f.seek(-readlength, os.SEEK_END) while True: data = f.read(LOG_BUF_SIZE) if not data: break yield data return stream