Exemple #1
0
    def test_if_dotted_path_is_correct(self):

        # This should not change unless the logger test file is moved or path
        # renamed. VirtualEnv naming on different systems can cause issues, so
        # the expected module should be "in" the reported module
        expected_module_path = 'test.logger.test_logger'

        log_1 = Logger(added_depth=-2)
        reported_module_path = log_1._get_module_name()
        print(f"Module Name: {reported_module_path}")
        assert(expected_module_path in reported_module_path)
Exemple #2
0
def main_test_routine():
    """
    Main test routine.
       * Get args from CLI
       * Setup Logging
       * Execute data generation

    :return:
    """
    args = parse_cli()

    log = Logger(set_root=True,
                 default_level=Logger.DEBUG if args.debug else Logger.INFO)

    log.debug("DEBUG enabled.")

    execute(num_data_sets=args.num_data_sets,
            max_records=args.max_records,
            cfg_file=args.cfg)
Exemple #3
0
    def test_if_all_logging_children_and_levels_are_reported(self):
        # Validate logging children are reported correctly

        log_1_level = Logger.INFO
        root_level = Logger.DEBUG

        # Set up the loggers
        log_1 = Logger(default_level=log_1_level, test_name='log_1')
        log_2 = Logger(test_name='log_2')
        root = Logger(default_level=root_level, set_root=True)

        # Record the expected names and levels
        expected_names = {log_1.name, log_2.name, root.name}
        expected_log_levels = {log_1.name: root_level,
                               log_2.name: root_level,
                               root.name: root_level}

        # Get the actual logger info
        children = root._list_loggers()
        actual_child_names = set([name for name, level in children])
        actual_log_levels = dict([(name, level) for name, level in children])

        # Print state (for debugging on failure)
        print(root.list_loggers())
        print(f"\nACTUAL NAMES: {actual_child_names}")
        print(f"\nEXPECTED NAMES: {expected_names}")
        print(f"\nINTERSECTION: {actual_child_names.intersection(expected_names)}")

        # The length of the set intersection should be the same length as
        # the expected names.
        assert_equals(len(actual_child_names.intersection(expected_names)),
                      len(expected_names))

        # Check the logging level for the actual level matches the
        # expected level.
        for name, actual_level in actual_log_levels.items():
            expected_level = expected_log_levels.get(name, None)

            if expected_level is not None:
                expected_level = Logger.VAL_TO_STR[expected_level].upper()
                print(f"\nName: {name}\nExpected Value: {expected_level}"
                      f"\nActual Value: {actual_level}")

                assert_equals(actual_level, expected_level)
Exemple #4
0
    def configure_logging(cls, app_cfg_obj: PdlConfig) -> Logger:
        """
        Sets up the root logger (format, location) and updates the existing the handlers

        :param app_cfg_obj: (PdlConfig): Contains the required location, etc., for the logger

        :return: Instantiated, updated root logger

        """
        # Set log level (CLI overrides the config file)
        # ---------------------------------------------
        # Get the config-file specified value
        log_level = app_cfg_obj.app_cfg.get(
            AppCfgFileSections.LOGGING,
            AppCfgFileSectionKeys.LOG_LEVEL.lower())

        if app_cfg_obj.cli_args.debug:
            log_level = 'debug'

        # Determine and store the log file name, create directory if needed.
        log_dir = os.path.abspath(
            os.path.sep.join(
                app_cfg_obj.logfile_name.split(os.path.sep)[0:-1]))
        utils.check_if_location_exists(location=log_dir, create_dir=True)

        # Setup the root logger for the app
        logger = Logger(filename=app_cfg_obj.logfile_name,
                        default_level=Logger.STR_TO_VAL[log_level],
                        project=app_cfg_obj.app_cfg.get(
                            AppCfgFileSections.PROJECT,
                            AppCfgFileSectionKeys.NAME),
                        set_root=True)

        # Show defined loggers and log levels
        logger.debug(f"Log File: {app_cfg_obj.logfile_name}")
        for line in logger.list_loggers().split('\n'):
            logger.debug(line)

        return logger
Exemple #5
0
"""

    Definitions of expected input from configuration files

"""

from configparser import ConfigParser, NoSectionError, NoOptionError
import os
from typing import List

from PDL.logger.logger import Logger

LOG = Logger()


class AppCfgFileSections:
    """
    Sections available within the application configuration. Defined as
    constants to reduce typos, and if a value needs to change, it only needs to
    be changed here.

    Listed in alphabetical order.

    """
    CLASSIFICATION = 'classification'
    DATABASE = 'database'
    IMAGES = 'images'
    LOGGING = 'logging'
    PROJECT = 'project'
    STORAGE = 'storage'