diff --git a/common/python/nomadcore/baseclasses.py b/common/python/nomadcore/baseclasses.py index dd4b58d85fc93d92193bc4237c60313c56fa1c02..2ece8fde70fe1db3fffd552e6fc71b3a62348d33 100644 --- a/common/python/nomadcore/baseclasses.py +++ b/common/python/nomadcore/baseclasses.py @@ -9,7 +9,9 @@ import os import copy import numpy as np import logging +from future.utils import with_metaclass from abc import ABCMeta, abstractmethod + from nomadcore.unit_conversion import unit_conversion from nomadcore.simple_parser import mainFunction from nomadcore.local_backend import LocalBackend @@ -17,9 +19,8 @@ from nomadcore.local_meta_info import load_metainfo from nomadcore.caching_backend import CachingLevel from nomadcore.simple_parser import extractOnCloseTriggers, extractOnOpenTriggers from nomadcore.caching_backend import ActiveBackend -import nomadcore.ActivateLogging -from future.utils import with_metaclass -logger = logging.getLogger("nomad") + +logger = logging.getLogger(__file__) class ParserInterface(with_metaclass(ABCMeta, object)): @@ -43,22 +44,31 @@ class ParserInterface(with_metaclass(ABCMeta, object)): """ metainfo_env = None - def __init__(self, metainfo_to_keep=None, backend=None, default_units=None, metainfo_units=None, debug=False, log_level=logging.ERROR, store=True): + def __init__( + self, metainfo_to_keep=None, backend=None, default_units=None, + metainfo_units=None, debug=False, log_level=logging.ERROR, store=True): """ - Args: - main_file: A special file that can be considered the main file of the - calculation. - metainfo_to_keep: A list of metainfo names. This list is used to - optimize the parsing process as optimally only the information - relevant to these metainfos will be parsed. - backend: An object to which the parser will give all the parsed data. - The backend will then determine where and when to output that data. + Arguments: + metainfo_to_keep: A list of metainfo names. This list is used to + optimize the parsing process as optimally only the information + relevant to these metainfos will be parsed. + backend: An object to which the parser will give all the parsed data. + The backend will then determine where and when to output that data. """ - self.debug = debug - logger.setLevel(log_level) + try: + logger.setLevel(log_level) + except Exception: + # might fail on custom loggers + pass + self.store = store + self.debug = debug self.initialize(metainfo_to_keep, backend, default_units, metainfo_units) + def setup_logger(self, new_logger): + global logger + logger = new_logger + def initialize(self, metainfo_to_keep, backend, default_units, metainfo_units): """Initialize the parser with the given environment. """