__init__.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:aws-ork 作者: TriNimbus 项目源码 文件源码
def main():
    parser = argparse.ArgumentParser(description='Listens to an SQS queue and accepts and removes Salt minion keys')
    parser.add_argument('-v', '--verbose', action='store_true', help='Enable debug logging')
    parser.add_argument('-d', '--daemon', action='store_true', help='Daemonize and enable logging to file')
    parser.add_argument('--syslog', action='store_true', help='Log to syslog rather than file, only in daemon mode')
    parser.add_argument('--purge', action='store_true', help='Purge all message from queue at startup')
    args = parser.parse_args()

    logger.setLevel(logging.INFO)
    if args.verbose:
        logger.setLevel(logging.DEBUG)

    # Log to file if daemonized
    if args.daemon:
        if args.syslog:
            lh = logging.handlers.SysLogHandler(address='/dev/log', facility='daemon')
            lh.setFormatter(logging.Formatter('%(filename)s[%(process)d]: %(levelname)s - %(message)s'))
            log_fh = lh.socket.fileno()
        else:
            lh = logging.FileHandler('/var/log/aws_ork.log')
            lh.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
            log_fh = lh.stream.fileno()
    else:
        lh = logging.StreamHandler()
        lh.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
        log_fh = lh.stream.fileno()

    logger.addHandler(lh)

    if args.daemon:
        context = daemon.DaemonContext()
        context.files_preserve = [log_fh]
        with context:
            run(args.purge)
    else:
        run(args.purge)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号