Esempio n. 1
0
def test_copy_logger_config(tmpdir):
    '''Test if logger configuration is copied'''

    # Make a local directory
    locd = tmpdir.mkdir("config")

    configdir = Directory(str(locd))
    logger = Logger(configdir)

    with pytest.raises(ValueError):

        # Copy the logging file
        logger.copy_config()
Esempio n. 2
0
def test_configure_logger(tmpdir, directory):
    '''Test if logger configuration can be loaded'''

    # Make a local directory
    locd = tmpdir.mkdir("config")
    locp = locd.join("logging.yaml")

    configdir = Directory(str(locd))

    logger = Logger(configdir)

    # Copy the logging file
    src_file_path = directory.get_path("logging.yaml")
    shutil.copy(src_file_path, str(locp))

    # Attempt to configure the logger
    log_config_dict = logger.read()
    logger.configure_logger(log_config_dict)
Esempio n. 3
0
def test_copy_logger_config(tmpdir, directory):
    '''Test if logger configuration is copied'''

    # Make a local directory
    locd = tmpdir.mkdir("config")
    locp = locd.join("logging.yaml")

    configdir = Directory(str(locd))
    dirmap = DirectoryMap(configdir, directory)

    logger = Logger(dirmap)

    # Copy the logging file
    logger.copy_config()

    assert dirmap.last_copy_path == str(locp)
    assert len(locd.listdir()) == 1
    assert os.path.basename(str(locd.listdir()[0])) == "logging.yaml"
Esempio n. 4
0
def test_user_config_exists(tmpdir):
    '''Test if the user_config_exists function returns false'''

    # Make a local directory
    locd = tmpdir.mkdir("config")

    configdir = Directory(str(locd))

    logger = Logger(configdir)

    assert not configdir.isfile(logger.config_file_name)
Esempio n. 5
0
def start_logging(level=None):
    """Start python logger"""

    objdir = ObjDirectory(__name__, "config")
    datadir = UserDataDirectory("dtocean_hydro", "DTOcean", "config")
    dirmap = DirectoryMap(datadir, objdir)

    log = Logger(dirmap)
    log("dtocean_hydro",
        level=level,
        info_message="Begin logging for dtocean_hydro.")
Esempio n. 6
0
def test_call_logger_options(tmpdir, directory):
    '''Test if logger can be called'''

    # Make a local directory
    locd = tmpdir.mkdir("config")

    configdir = Directory(str(locd))
    dirmap = DirectoryMap(configdir, directory)

    logger = Logger(dirmap)
    logger('my_logger', level="CRITICAL", info_message="test")

    assert True
Esempio n. 7
0
def test_call_logger(tmpdir, directory):
    '''Test if logger can be called'''

    # Make a local directory
    locd = tmpdir.mkdir("config")

    configdir = Directory(str(locd))
    dirmap = DirectoryMap(configdir, directory)

    logger = Logger(dirmap)
    logger('my_logger')

    assert True
Esempio n. 8
0
def test_call_logger_options(tmpdir, directory):
    '''Test if logger can be called with options'''

    # Make a local directory
    locd = tmpdir.mkdir("config")
    locp = locd.join("logging.yaml")

    configdir = Directory(str(locd))

    logger = Logger(configdir)

    # Copy the logging file
    src_file_path = directory.get_path("logging.yaml")
    shutil.copy(src_file_path, str(locp))

    logger('my_logger', level="CRITICAL", info_message="test")

    assert True
Esempio n. 9
0
def test_call_logger(tmpdir, directory):
    '''Test if logger can be called'''

    # Make a local directory
    locd = tmpdir.mkdir("config")
    locp = locd.join("logging.yaml")

    configdir = Directory(str(locd))

    logger = Logger(configdir)

    # Copy the logging file
    src_file_path = directory.get_path("logging.yaml")
    shutil.copy(src_file_path, str(locp))

    logger('my_logger')

    assert True
Esempio n. 10
0
def test_configure_logger(tmpdir, directory):
    '''Test if logger configuration can be loaded'''

    # Make a local directory
    locd = tmpdir.mkdir("config")

    configdir = Directory(str(locd))
    dirmap = DirectoryMap(configdir, directory)

    logger = Logger(dirmap)

    # Copy the logging file
    logger.copy_config()

    # Attempt to configure the logger
    log_config_dict = logger.read()
    logger.configure_logger(log_config_dict)
Esempio n. 11
0
def start_logging():
    """Start python logger"""

    # Pick up the configuration from the user directory if it exists
    userdir = UserDataDirectory("dtocean_core", "DTOcean", "config")

    # Look for files.ini
    if userdir.isfile("files.ini"):
        configdir = userdir
    else:
        configdir = ObjDirectory("dtocean_core", "config")

    files_ini = ReadINI(configdir, "files.ini")
    files_config = files_ini.get_config()

    appdir_path = userdir.get_path("..")
    log_folder = files_config["logs"]["path"]
    log_path = os.path.join(appdir_path, log_folder)
    logdir = Directory(log_path)

    # Look for logging.yaml
    if userdir.isfile("logging.yaml"):
        configdir = userdir
    else:
        configdir = ObjDirectory("dtocean_core", "config")

    log = Logger(configdir)
    log_config_dict = log.read()

    # Update the file logger if present
    if "file" in log_config_dict["handlers"]:
        log_filename = log_config_dict["handlers"]["file"]["filename"]
        log_path = logdir.get_path(log_filename)
        log_config_dict["handlers"]["file"]["filename"] = log_path
        logdir.makedir()

    log.configure_logger(log_config_dict)
    logger = log.add_named_logger("dtocean_core")

    # Rotate any rotating file handlers
    for handler in logger.handlers:
        if handler.__class__.__name__ == 'RotatingFileHandler':
            handler.doRollover()

    logger.info("Begin logging for dtocean_core")

    return
Esempio n. 12
0
def start_logging(debug=False):
    
    # Pick up the configuration from the user directory if it exists
    userdir = UserDataDirectory("dtocean_app", "DTOcean", "config")
            
    if userdir.isfile("files.ini") and userdir.isfile("logging.yaml"):
        configdir = userdir
    else:
        configdir = ObjDirectory("dtocean_app", "config")
    
    files_ini = ReadINI(configdir, "files.ini")
    files_config = files_ini.get_config()
    
    appdir_path = userdir.get_path("..")
    log_folder = files_config["logs"]["path"]
    log_path = os.path.join(appdir_path, log_folder)
    logdir = Directory(log_path)
    
    # Disable the logging QtHandler if the debug flag is set
    QtHandler.debug = debug
    
    log = Logger(configdir)
    log_config_dict = log.read()
    
    # Update the file logger if present
    if "file" in log_config_dict["handlers"]:
        log_filename = log_config_dict["handlers"]["file"]["filename"]
        log_path = logdir.get_path(log_filename)
        log_config_dict["handlers"]["file"]["filename"] = log_path
        logdir.makedir()
    
    log.configure_logger(log_config_dict)
    logger = log.add_named_logger("dtocean_app")
    
    # Rotate any rotating file handlers
    for handler in logger.handlers:
        if handler.__class__.__name__ == 'RotatingFileHandler':
            try:
                handler.doRollover()
            except WindowsError:
                pass
            
    logger.info("Welcome to DTOcean")
    
    return
Esempio n. 13
0
def start_logging(debug=False):

    # Disable the logging QtHandler if the debug flag is set
    QtHandler.debug = debug

    # Pick up the configuration from the user directory if it exists
    userdir = UserDataDirectory("dtocean_app", "DTOcean", "config")

    # Look for logging.yaml
    if userdir.isfile("logging.yaml"):
        configdir = userdir
    else:
        configdir = ObjDirectory("dtocean_app", "config")

    # Get the logger configuration
    log = Logger(configdir)
    log_config_dict = log.read()

    # Get Directory to place logs
    log_dir = get_log_dir()

    # Update the file logger if present
    if "file" in log_config_dict["handlers"]:
        log_filename = log_config_dict["handlers"]["file"]["filename"]
        log_path = log_dir.get_path(log_filename)
        log_config_dict["handlers"]["file"]["filename"] = log_path
        log_dir.makedir()

    log.configure_logger(log_config_dict)
    logger = log.add_named_logger("dtocean_app")

    # Rotate any rotating file handlers
    for handler in logger.handlers:
        if handler.__class__.__name__ == 'RotatingFileHandler':
            try:
                handler.doRollover()
            except WindowsError:
                pass

    logger.info("Welcome to DTOcean")

    return