Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask import request
- from flask import Response
- app = Flask(__name__)
- def tail(file, n=1, bs=1024):
- f = open(file)
- f.seek(0,2)
- l = 1-f.read(1).count('n')
- B = f.tell()
- while n >= l and B > 0:
- block = min(bs, B)
- B -= block
- f.seek(B, 0)
- l += f.read(block).count('n')
- f.seek(B, 0)
- l = min(l,n)
- lines = f.readlines()[-l:]
- f.close()
- return lines
- @app.route('/logs', methods = ['GET'])
- def print_logs():
- if request.method == 'GET':
- file_path = "Logs.txt"
- data = tail(file_path, 100)
- return Response(data, mimetype='text/plain')
- if __name__ == "__main__":
- app.run(host="localhost", port=80, debug=True, threaded=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement