예제 #1
0
    logfile = os.path.join(log_dir, 'pav.log')
    if not os.path.exists(logfile):
        try:
            # 'Touch' the file, in case it doesn't exist. Makes it easier to verify writability
            # in a sec.
            open(logfile, 'a').close()
        except OSError:
            # It's ok if we can't do this.
            pass

    if os.access(logfile, os.W_OK):
        # Set up a rotating logfile than rotates when it gets larger than 1 MB.
        file_handler = RotatingFileHandler(filename=logfile,
                                           maxBytes=1024**2,
                                           backupCount=3)
        file_handler.format(pav_cfg.log_format)
        file_handler.setLevel(pav_cfg.log_level)
        root_logger.addHandler(file_handler)
        break

# The root logger should pass all messages, even if the handlers filter them.
root_logger.setLevel(logging.DEBUG)

# Initialize all the plugins
try:
    plugins.initialize_plugins(pav_cfg)
except plugins.PluginError as err:
    print("Error initializing plugins: {}".format(err), file=sys.stderr)
    sys.exit(-1)

# Get and parse the arguments