python日志 loguru模块

# while-true logrufu ,input提示 非 click提示  python模板

import subprocess
import time
from functools import wraps
from loguru import logger
import sys, os



def time_this_function(func):
    #作为装饰器使用,返回函数执行需要花费的时间
    @wraps(func)
    def wrapper(*args,**kwargs):
        pid = os.getpid()
        start=time.time()
        result=func(*args,**kwargs)
        end=time.time()
        print(pid)
        # print("%s,%f" % (func.__name__, end-start))
        
        logger.debug('[func %s running with (%s, %s) ] [time of duration is %fs] [pid is %s ]' % (func.__name__, args, kwargs, end-start, pid))  
        logger.info("this is info log")
        # logger.error("this is error log")
        return result
    return wrapper

@time_this_function
def my_cmd(mycmd, cwd):
    cwd = cwd
    mycmd = mycmd
    p = subprocess.Popen("{}".format(mycmd), shell=True, cwd=cwd)
    p.communicate()
    returncode = p.returncode
    if returncode != 0:
        print("returncode is" , returncode, "命令有误。")

@time_this_function
def start_check():
    print(" check is ok")

@time_this_function
def install_os():
    print(" install os is ok")

@time_this_function
def install_aliyun():
    pass

@time_this_function
def install_docker():
    pass

@time_this_function
def install_k8s():
    pass










if __name__ == "__main__":
    count = 1
    if count > 0:
        password = input('请输入您的密码:')
        if password == "passwd":
            while True:
                number = input('0 检查环境 1 配置系统环境 2 安装阿里云 7 安装docker 8安装kubelet 9 安装k8s-master 10 退出程序,请输入:')
                if number == "0":
                    print("start check")
                    start_check()
                    # my_cmd("lk", "/root")
                elif number == "1":
                    print("start install os hostname ,stop firewalld ...")
                    install_os()
                elif number == "2":
                    print(" aliyum.repo start")
                    install_aliyun()
                elif number == "7":
                    print(" start install docker ")
                elif number == "8":
                    print(" start install kubelet ")
                elif number == "9":
                    print("start init k8s-master")
                elif number == "10":
                    break
                else:
                    print('输入错误,请重新输入:')
        elif count > 0:
            count -= 1
            print('您输入的密码不正确,还有{}次输入机会'.format(count))

            

# loguru 文章 https://cuiqingcai.com/7776.html                 

# loguru代码官方文档    https://loguru.readthedocs.io/en/stable/api/logger.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值