Skip to content
Snippets Groups Projects
Commit 4371e71e authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Allow for infrastructure to set logger on parsers.

parent 5a690dd1
No related branches found
No related tags found
No related merge requests found
......@@ -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.
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
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.
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment