Skip to content
Snippets Groups Projects
Commit 283d4177 authored by Amandine  PERRIN's avatar Amandine PERRIN
Browse files

Update verbosity

Update logger creation (with a name!)
parent a92e9d8c
No related branches found
No related tags found
No related merge requests found
...@@ -43,10 +43,11 @@ def main(cmd, NCBI_species, NCBI_taxid, outdir, threads, no_refseq, only_mash, l ...@@ -43,10 +43,11 @@ def main(cmd, NCBI_species, NCBI_taxid, outdir, threads, no_refseq, only_mash, l
Main method, constructing the draft dataset for the given species Main method, constructing the draft dataset for the given species
verbosity: verbosity:
- defaut 0 : stdout contains INFO, stderr contains ERROR. - defaut 0 : stdout contains INFO, stderr contains ERROR, .log contains INFO and more, .log.err contains warning and more
- 1: stdout contains INFO, stderr contains WARNING and ERROR - 1: same as 0 + WARNING in stderr
- 2: stdout contains (DEBUG), DETAIL and INFO, stderr contains WARNING and ERROR - 2: same as 1 + DETAILS in stdout + DETAILS in .log.details
- >=15: Add DEBUG in stdout - >=15: same as 2 + Add DEBUG in stdout + create .log.debug with everything from info to debug
Parameters Parameters
---------- ----------
...@@ -74,10 +75,10 @@ def main(cmd, NCBI_species, NCBI_taxid, outdir, threads, no_refseq, only_mash, l ...@@ -74,10 +75,10 @@ def main(cmd, NCBI_species, NCBI_taxid, outdir, threads, no_refseq, only_mash, l
lower limit of distance between 2 genomes to keep them lower limit of distance between 2 genomes to keep them
verbose : int verbose : int
verbosity: verbosity:
default (0): info in stdout, error and more in stderr - defaut 0 : stdout contains INFO, stderr contains ERROR, .log contains INFO and more, .log.err contains warning and more
1 = add warnings in stderr - 1: same as 0 + WARNING in stderr
2 = like 1 + add DETAIL to stdout (by default only INFO) - 2: same as 1 + DETAILS in stdout + DETAILS in .log.details
>15: add debug to stdout - >=15: same as 2 + Add DEBUG in stdout + create .log.debug with everything from info to debug
quiet : bool quiet : bool
True if nothing must be sent to stdout/stderr, False otherwise True if nothing must be sent to stdout/stderr, False otherwise
...@@ -113,10 +114,8 @@ def main(cmd, NCBI_species, NCBI_taxid, outdir, threads, no_refseq, only_mash, l ...@@ -113,10 +114,8 @@ def main(cmd, NCBI_species, NCBI_taxid, outdir, threads, no_refseq, only_mash, l
if verbose >= 15: if verbose >= 15:
level = logging.DEBUG level = logging.DEBUG
logfile_base = os.path.join(outdir, "PanACoTA_prepare_{}").format(species_linked) logfile_base = os.path.join(outdir, "PanACoTA_prepare_{}").format(species_linked)
logfile_base = utils.init_logger(logfile_base, level, name='', details=True, logfile_base, logger = utils.init_logger(logfile_base, level, 'prepare', details=True,
verbose=verbose, quiet=quiet) verbose=verbose, quiet=quiet)
logger = logging.getLogger('')
keyargs = {'section': 'refseq', 'file_format': 'fasta', 'output': '/Users/aperrin/Softwares/gem-hub_src/PanACoTA/104099-out', 'parallel': 1, 'group': 'bacteria', 'species_taxid': '104099'}
logger.info("Command used\n \t > " + cmd) logger.info("Command used\n \t > " + cmd)
message = f"'PanACoTA prepare' will run on {threads} " message = f"'PanACoTA prepare' will run on {threads} "
...@@ -235,7 +234,7 @@ def build_parser(parser): ...@@ -235,7 +234,7 @@ def build_parser(parser):
"of 'N' stretches, put this value to this option.")) "of 'N' stretches, put this value to this option."))
helper = parser.add_argument_group('Others') helper = parser.add_argument_group('Others')
helper.add_argument("-v", "--verbose", dest="verbose", action="count", default=0, helper.add_argument("-v", "--verbose", dest="verbose", action="count", default=0,
help="Increase verbosity in stdout/stderr.") help="Increase verbosity in stdout/stderr and log files.")
helper.add_argument("-q", "--quiet", dest="quiet", action="store_true", default=False, helper.add_argument("-q", "--quiet", dest="quiet", action="store_true", default=False,
help=("Do not display anything to stdout/stderr. log files will " help=("Do not display anything to stdout/stderr. log files will "
"still be created.")) "still be created."))
...@@ -310,7 +309,7 @@ def check_args(parser, args): ...@@ -310,7 +309,7 @@ def check_args(parser, args):
if args.cutn == 0 or args.cutn == 5: if args.cutn == 0 or args.cutn == 5:
message = (" !! Your genomes will be split when sequence contains at " message = (" !! Your genomes will be split when sequence contains at "
"least {}'N' at a stretch. If you want to change this threshold, use " "least {}'N' at a stretch. If you want to change this threshold, use "
"'--cutn' option (0 if you do not want to cut)").format(args.cutn) "'--cutn n' option (n=0 if you do not want to cut)").format(args.cutn)
print(colored(message, "yellow")) print(colored(message, "yellow"))
# Warn user about selection of genomes thresholds # Warn user about selection of genomes thresholds
......
...@@ -56,10 +56,11 @@ def init_logger(logfile_base, level, name, details=False, verbose=0, quiet=False ...@@ -56,10 +56,11 @@ def init_logger(logfile_base, level, name, details=False, verbose=0, quiet=False
if we need to name the logger (used for tests) if we need to name the logger (used for tests)
verbose : int verbose : int
be more verbose: be more verbose:
default (0): info in stdout, error and more in stderr default (0): info in stdout, error and more in stderr ;
info and more in *.log ; warning and more in *.log.err
1 = add warnings in stderr 1 = add warnings in stderr
2 = like 1 + add DETAIL to stdout (by default only INFO) 2 = like 1 + add details to stdout (by default only INFO) + add details to *.log.details
>15: add debug to stdout >15: add debug to stdout and create *.log.debug with all levels
quiet : bool quiet : bool
True if nothing must be sent to stdout/stderr, False otherwise True if nothing must be sent to stdout/stderr, False otherwise
""" """
...@@ -171,7 +172,7 @@ def init_logger(logfile_base, level, name, details=False, verbose=0, quiet=False ...@@ -171,7 +172,7 @@ def init_logger(logfile_base, level, name, details=False, verbose=0, quiet=False
err_handler.setLevel(logging.ERROR) # write all messages >= ERROR err_handler.setLevel(logging.ERROR) # write all messages >= ERROR
err_handler.setFormatter(formatter_stream) err_handler.setFormatter(formatter_stream)
logger.addHandler(err_handler) # add handler to logger logger.addHandler(err_handler) # add handler to logger
return logfile return logfile, logger
class LessThanFilter(logging.Filter): class LessThanFilter(logging.Filter):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment