From 1ce229399bfbf8d58e1697ea0eafda69f952f153 Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Mon, 18 Oct 2021 20:36:45 -0600 Subject: [PATCH] Fix logging --- flask/explorer.py | 8 +++++++- flask/utils.py | 11 ++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/flask/explorer.py b/flask/explorer.py index 3bd950d..7401d7e 100644 --- a/flask/explorer.py +++ b/flask/explorer.py @@ -3,6 +3,7 @@ from flask import Flask, request, jsonify, abort from werkzeug.exceptions import HTTPException +import os import traceback import logging import cluster @@ -11,7 +12,6 @@ import search import utils import query -import sequencesearch import threading import time @@ -44,6 +44,12 @@ def auto_update_index(): update_thread = threading.Thread(target=auto_update_index, daemon=True) update_thread.start() + if os.path.exists('log.txt') and os.path.getsize('log.txt') > 20000000: # Delete the log if it is > 20 MB + os.remove('log.txt') + + if os.path.exists('indexing_log.txt') and os.path.getsize('indexing_log.txt') > 20000000: # Delete the log if it is > 20 MB + os.remove('indexing_log.txt') + utils.log('SBOLExplorer started :)') try: diff --git a/flask/utils.py b/flask/utils.py index fa8d81b..db0efc8 100644 --- a/flask/utils.py +++ b/flask/utils.py @@ -3,7 +3,6 @@ import pickle import requests import datetime -import subprocess import os config = None @@ -121,22 +120,16 @@ def log(message): Returns: """ - log_message = '[' + str(datetime.datetime.now()) + '] ' + message + '\n' + log_message = '[' + str(datetime.datetime.now()) + '] ' + str(message) + '\n' print(log_message) - if os.path.exists('log.txt') and os.path.getsize('log.txt') > 20000000: # Delete the log if it is > 20 MB - os.remove('log.txt') - with open('log.txt', 'a+') as f: f.write(log_message) def log_indexing(message): - log_message = '[' + str(datetime.datetime.now()) + '] ' + message + '\n' + log_message = '[' + str(datetime.datetime.now()) + '] ' + str(message) + '\n' print(log_message) - if os.path.exists('indexing_log.txt') and os.path.getsize('indexing_log.txt') > 20000000: # Delete the log if it is > 20 MB - os.remove('indexing_log.txt') - with open('indexing_log.txt', 'a+') as f: f.write(log_message)