コード例 #1
0
ファイル: __init__.py プロジェクト: H0R5E/dtocean-core
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
コード例 #2
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)
コード例 #3
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
コード例 #4
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)
コード例 #5
0
ファイル: __init__.py プロジェクト: H0R5E/dtocean-app
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