Ejemplo n.º 1
0
def main(config_filename, gui_config, gui_job, override_csv_file_name,
         override_log_file_name, interrupted_ref):
    """
    This function initialize the data logger and starts the logging process
    """
    config = None
    gui_start = False

    if config_filename != None:  # started via console
        config = load_and_validate_config(config_filename)

        if config == None:
            return None
    else:  # started via GUI
        config = gui_config
        gui_start = True

    if override_csv_file_name != None:
        config['data']['csv']['file_name'] = override_csv_file_name

    if override_log_file_name != None:
        config['debug']['log']['file_name'] = override_log_file_name

    try:
        if config['debug']['log']['enabled']:
            EventLogger.add_logger(
                FileLogger(
                    'FileLogger',
                    log_level_name_to_id(config['debug']['log']['level']),
                    config['debug']['log']['file_name']))

        data_logger = DataLogger(config, gui_job)

        if data_logger.ipcon is not None:
            data_logger.run()

            if not gui_start:
                while not interrupted_ref[0]:
                    try:
                        time.sleep(0.25)
                    except:
                        pass

                data_logger.stop()
                sys.exit(0)
        else:
            raise DataLoggerException(
                DataLoggerException.DL_CRITICAL_ERROR,
                "DataLogger did not start logging process! Please check for errors."
            )

    except Exception as exc:
        EventLogger.critical(str(exc))
        if gui_start:
            return None
        else:
            sys.exit(DataLoggerException.DL_CRITICAL_ERROR)

    return data_logger
Ejemplo n.º 2
0
def main(config_filename, gui_config, gui_job):
    """
    This function initialize the data logger and starts the logging process
    """
    config = None
    gui_start = False

    if config_filename != None:  # started via console
        config = load_and_validate_config(config_filename)

        if config == None:
            return None
    else:  # started via GUI
        config = gui_config
        gui_start = True

    if config['debug']['log']['enabled']:
        EventLogger.add_logger(
            FileLogger('FileLogger',
                       log_level_name_to_id(config['debug']['log']['level']),
                       config['debug']['log']['file_name']))

    data_logger = None
    try:
        data_logger = DataLogger(config, gui_job)

        if data_logger.ipcon is not None:
            data_logger.run()
            if not gui_start:
                __exit_condition(data_logger)
        else:
            raise DataLoggerException(
                DataLoggerException.DL_CRITICAL_ERROR,
                "DataLogger did not start logging process! Please check for errors."
            )

    except Exception as exc:
        EventLogger.critical(str(exc))
        if gui_start:
            return None
        else:
            sys.exit(DataLoggerException.DL_CRITICAL_ERROR)

    return data_logger