Commit 456a0d16 authored by Carsten's avatar Carsten
Browse files

Cleaning up logging.

parent 3c13cb81
Pipeline #257489 failed with stages
in 8 minutes and 22 seconds
import logging
import os import os
import rq import rq
from .config import Config from .config import Config
...@@ -8,7 +7,6 @@ from flask_mail import Mail ...@@ -8,7 +7,6 @@ from flask_mail import Mail
from flask_mongoengine import MongoEngine, MongoEngineSessionInterface from flask_mongoengine import MongoEngine, MongoEngineSessionInterface
from redis import Redis from redis import Redis
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__, instance_relative_config=True, static_url_path='/static') app = Flask(__name__, instance_relative_config=True, static_url_path='/static')
upload_dir = os.path.join(app.static_folder, 'uploads') upload_dir = os.path.join(app.static_folder, 'uploads')
......
...@@ -35,21 +35,14 @@ import logging ...@@ -35,21 +35,14 @@ import logging
from Bio import SeqIO from Bio import SeqIO
import datetime import datetime
import logging
logging.basicConfig(level=logging.DEBUG)
def get_logger():
logger = logging.getLogger(__name__)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(module)s: %(message)s')
timestamp = datetime.datetime.now().strftime(format="%Y%m%d-%H%M%S")
handler = logging.FileHandler("/tmp/rarefan_{}.log".format(timestamp))
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
return logger
logger = get_logger() logger = logging.getLogger(__name__)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(module)s: %(message)s')
timestamp = datetime.datetime.now().strftime(format="%Y%m%d-%H%M%S")
handler = logging.FileHandler("/tmp/rarefan.log".format(timestamp))
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
def get_status_code(run_id_path): def get_status_code(run_id_path):
...@@ -69,13 +62,13 @@ def validate_fasta(filename): ...@@ -69,13 +62,13 @@ def validate_fasta(filename):
:param filename: The filename of the file to validate. :param filename: The filename of the file to validate.
""" """
logger.info("Validating fasta file %s.", filename) logging.info("Validating fasta file %s.", filename)
with open(filename, 'r') as fp: with open(filename, 'r') as fp:
fasta = SeqIO.parse(fp, "fasta") fasta = SeqIO.parse(fp, "fasta")
is_fasta = any(fasta) is_fasta = any(fasta)
if not is_fasta: if not is_fasta:
logger.warning("%s is not a valid fasta file.", filename) logging.warning("%s is not a valid fasta file.", filename)
return is_fasta return is_fasta
...@@ -95,7 +88,7 @@ def upload(): ...@@ -95,7 +88,7 @@ def upload():
) )
seqs = [v for k,v in request.files.items() if k.startswith('file')] seqs = [v for k,v in request.files.items() if k.startswith('file')]
logger.info("Uploading %s.", str(seqs)) logging.info("Uploading %s.", str(seqs))
dna_extensions = ['fn', 'fna', 'fastn', 'fas', 'fasta'] dna_extensions = ['fn', 'fna', 'fastn', 'fas', 'fasta']
aa_extensions = ['fa', 'faa'] aa_extensions = ['fa', 'faa']
...@@ -202,12 +195,12 @@ def submit(): ...@@ -202,12 +195,12 @@ def submit():
session['analyse_repins'] = request.form.get('analyse_repins') session['analyse_repins'] = request.form.get('analyse_repins')
session['email'] = request.form.get('email', None) session['email'] = request.form.get('email', None)
logger.info("Session parameters:") logging.info("Session parameters:")
logger.info("tmpdir: %s", session['tmpdir']) logging.info("tmpdir: %s", session['tmpdir'])
logger.info("outdir: %s", session['outdir']) logging.info("outdir: %s", session['outdir'])
logger.info("reference_strain: %s", session['reference_strain']) logging.info("reference_strain: %s", session['reference_strain'])
logger.info("treefile: %s", session['treefile']) logging.info("treefile: %s", session['treefile'])
logger.info("email: %s", session['email']) logging.info("email: %s", session['email'])
# Store session in db. # Store session in db.
run_id = os.path.basename(session['tmpdir']) run_id = os.path.basename(session['tmpdir'])
...@@ -408,7 +401,7 @@ def files(req_path): ...@@ -408,7 +401,7 @@ def files(req_path):
# Remove trailing '/' # Remove trailing '/'
if req_path.endswith('/'): if req_path.endswith('/'):
req_path = req_path[:-1] req_path = req_path[:-1]
logger.warning("Request dir is %s in (%s).", req_path, os.path.dirname(req_path)) logging.warning("Request dir is %s in (%s).", req_path, os.path.dirname(req_path))
# Save the target for the 'back to results' link. # Save the target for the 'back to results' link.
tmp_dir = session.get('tmpdir', None) tmp_dir = session.get('tmpdir', None)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment