Skip to content

Commit

Permalink
Make loggers module-specific
Browse files Browse the repository at this point in the history
Matplolib sometimes logs verbosely to info, so this stops using the root logger
  • Loading branch information
kclem committed Oct 20, 2021
1 parent 8196b6a commit c2bdd96
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 51 deletions.
15 changes: 9 additions & 6 deletions CRISPResso2/CRISPRessoAggregateCORE.py
Expand Up @@ -21,16 +21,19 @@


import logging
logging.basicConfig(level=logging.INFO,
logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info

_ROOT = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -77,7 +80,7 @@ def main():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename=_jp('CRISPRessoAggregate_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

with open(log_filename, 'w+') as outfile:
outfile.write('[Command used]:\n%s\n\n[Execution log]:\n' % ' '.join(sys.argv))
Expand Down
15 changes: 9 additions & 6 deletions CRISPResso2/CRISPRessoBatchCORE.py
Expand Up @@ -16,16 +16,19 @@
from CRISPResso2 import CRISPRessoReport

import logging
logging.basicConfig(level=logging.INFO,
logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info

_ROOT = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -134,7 +137,7 @@ def main():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename=_jp('CRISPRessoBatch_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

with open(log_filename, 'w+') as outfile:
outfile.write('[Command used]:\n%s\n\n[Execution log]:\n' % ' '.join(sys.argv))
Expand Down
18 changes: 11 additions & 7 deletions CRISPResso2/CRISPRessoCORE.py
Expand Up @@ -41,17 +41,21 @@
# sys.exit(1)

import logging
#from test._mock_backport import inplace
logging.basicConfig(level=logging.INFO,

logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info

####Support functions###

Expand Down Expand Up @@ -855,7 +859,7 @@ def print_stacktrace_if_debug():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

finally:
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

with open(log_filename, 'w+') as outfile:
outfile.write('CRISPResso version %s\n[Command used]:\n%s\n\n[Execution log]:\n' %(CRISPRessoShared.__version__, crispresso_cmd_to_write))
Expand Down
14 changes: 8 additions & 6 deletions CRISPResso2/CRISPRessoCompareCORE.py
Expand Up @@ -14,16 +14,18 @@
from CRISPResso2 import CRISPRessoReport

import logging
logging.basicConfig(level=logging.INFO,
logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info


def check_library(library_name):
Expand Down Expand Up @@ -141,7 +143,7 @@ def main():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename=_jp('CRISPRessoCompare_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

with open(log_filename, 'w+') as outfile:
outfile.write('[Command used]:\nCRISPRessoCompare %s\n\n[Execution log]:\n' % ' '.join(sys.argv))
Expand Down
15 changes: 9 additions & 6 deletions CRISPResso2/CRISPRessoMetaCORE.py
Expand Up @@ -19,16 +19,19 @@


import logging
logging.basicConfig(level=logging.INFO,
logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info

_ROOT = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -228,7 +231,7 @@ def main():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename=_jp('CRISPRessoMeta_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

with open(log_filename, 'w+') as outfile:
outfile.write('[Command used]:\n%s\n\n[Execution log]:\n' % ' '.join(sys.argv))
Expand Down
16 changes: 8 additions & 8 deletions CRISPResso2/CRISPRessoPooledCORE.py
Expand Up @@ -24,18 +24,18 @@
import traceback

import logging
logging.basicConfig(level=logging.INFO,
logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info


logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info

_ROOT = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -396,7 +396,7 @@ def main():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename=_jp('CRISPRessoPooled_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

crispresso2_info_file = os.path.join(
OUTPUT_DIRECTORY, 'CRISPResso2Pooled_info.json',
Expand Down
13 changes: 7 additions & 6 deletions CRISPResso2/CRISPRessoPooledWGSCompareCORE.py
Expand Up @@ -17,16 +17,17 @@

import logging
logging.basicConfig(
level=logging.INFO,
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info


def check_library(library_name):
Expand Down Expand Up @@ -216,7 +217,7 @@ def main():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename = _jp('CRISPRessoPooledWGSCompare_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

with open(log_filename, 'w+') as outfile:
outfile.write(
Expand Down
14 changes: 8 additions & 6 deletions CRISPResso2/CRISPRessoWGSCORE.py
Expand Up @@ -24,16 +24,18 @@


import logging
logging.basicConfig(level=logging.INFO,
logging.basicConfig(
format='%(levelname)-5s @ %(asctime)s:\n\t %(message)s \n',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
error = logging.critical
warn = logging.warning
debug = logging.debug
info = logging.info
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
error = logger.critical
warn = logger.warning
debug = logger.debug
info = logger.info


_ROOT = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -350,7 +352,7 @@ def print_stacktrace_if_debug():
warn('Folder %s already exists.' % OUTPUT_DIRECTORY)

log_filename=_jp('CRISPRessoWGS_RUNNING_LOG.txt')
logging.getLogger().addHandler(logging.FileHandler(log_filename))
logger.addHandler(logging.FileHandler(log_filename))

crispresso2_info_file = os.path.join(OUTPUT_DIRECTORY, 'CRISPResso2WGS_info.json')
crispresso2_info = {'running_info': {}, 'results': {'alignment_stats': {}, 'general_plots': {}}} #keep track of all information for this run to be pickled and saved at the end of the run
Expand Down

0 comments on commit c2bdd96

Please sign in to comment.