Skip to content

Commit

Permalink
Fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-eric committed Oct 19, 2021
1 parent 661c606 commit 1ce2293
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 7 additions & 1 deletion flask/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask import Flask, request, jsonify, abort
from werkzeug.exceptions import HTTPException

import os
import traceback
import logging
import cluster
Expand All @@ -11,7 +12,6 @@
import search
import utils
import query
import sequencesearch

import threading
import time
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 2 additions & 9 deletions flask/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pickle
import requests
import datetime
import subprocess
import os

config = None
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1ce2293

Please sign in to comment.