Пример #1
0
 def log_message(cls,
                 node: ASTNode = None,
                 code: MessageCode = None,
                 message: str = None,
                 error_position: ASTSourceLocation = None,
                 log_level: LoggingLevel = None):
     """
     Logs the handed over message on the handed over. If the current logging is appropriate, the
     message is also printed.
     :param node: the node in which the error occurred
     :param code: a single error code
     :param error_position: the position on which the error occurred.
     :param message: a message.
     :param log_level: the corresponding log level.
     """
     if cls.log_frozen:
         return
     if cls.curr_message is None:
         cls.init_logger(LoggingLevel.INFO)
     from pynestml.meta_model.ast_node import ASTNode
     from pynestml.utils.ast_source_location import ASTSourceLocation
     assert (node is None or isinstance(node, ASTNode)), \
         '(PyNestML.Logger) Wrong type of node provided (%s)!' % type(node)
     assert (error_position is None or isinstance(error_position, ASTSourceLocation)), \
         '(PyNestML.Logger) Wrong type of error position provided (%s)!' % type(error_position)
     from pynestml.meta_model.ast_neuron import ASTNeuron
     if isinstance(node, ASTNeuron):
         cls.log[cls.curr_message] = (node.get_artifact_name(), node,
                                      log_level, code, error_position,
                                      message)
     elif cls.current_node is not None:
         cls.log[cls.curr_message] = (cls.current_node.get_artifact_name(),
                                      cls.current_node, log_level, code,
                                      error_position, message)
     cls.curr_message += 1
     if cls.no_print:
         return
     if cls.logging_level.value <= log_level.value:
         to_print = '[' + str(cls.curr_message) + ','
         to_print = (to_print +
                     (node.get_name() + ', '
                      if node is not None else cls.current_node.get_name() +
                      ', ' if cls.current_node is not None else 'GLOBAL, '))
         to_print = to_print + str(log_level.name)
         to_print = to_print + (', ' + str(error_position) if error_position
                                is not None else '') + ']: '
         to_print = to_print + str(message)
         print(to_print)
     return
Пример #2
0
 def get_all_messages_of_node(cls, node: ASTNode) -> List[Tuple[ASTNode, LoggingLevel, str]]:
     """
     Returns all messages which have been reported for a certain node.
     :param node: a single node instance
     :return: a list of messages with their levels.
     :rtype: list((str,Logging_Level)
     """
     if node is None:
         return cls.get_log()
     ret = list()
     for (artifactName, node_i, logLevel, code, errorPosition, message) in cls.log.values():
         if (node_i == node if node is not None else True) and \
                 (node.get_artifact_name() == artifactName if node is not None else True):
             ret.append((node, logLevel, message))
     return ret
Пример #3
0
 def get_all_messages_of_level_and_or_node(
         cls, node: ASTNode,
         level: LoggingLevel) -> List[Tuple[ASTNode, LoggingLevel, str]]:
     """
     Returns all messages which have a certain logging level, or have been reported for a certain node, or
     both.
     :param node: a single node instance
     :param level: a logging level
     :return: a list of messages with their levels.
     """
     if level is None and node is None:
         return cls.get_log()
     ret = list()
     for (artifactName, node_i, logLevel, code, errorPosition,
          message) in cls.log.values():
         if (level == logLevel if level is not None else
                 True) and (node if node is not None else True) and (
                     node.get_artifact_name() == artifactName
                     if node is not None else True):
             ret.append((node, logLevel, message))
     return ret