python日誌 loguru模組

2021-10-21 12:05:38 字數 2364 閱讀 8555

# 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)

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

@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 文章 

# loguru**官方文件    

Python記錄日誌模組推薦 loguru!

在做專案的時候一直在用python自帶的模組logging,進行日誌的記錄,雖然他們滿足我大部分的要求,但是還是有很多缺點,例如需要額外的配置 不能自動刪除時間久的日誌檔案等等。難道真的沒有比較好的第三方模組嗎。於是我在網上langlanglang 咦?還真到了乙個比較好的模組來記錄日誌。他就是今天...

Python日誌記錄器詳解 Loguru

loguru乙個能徹底解放你的日誌記錄器。它即插即用,具備多種方式滾動日誌 自動壓縮日誌檔案 定時刪除等功能。除此之外,多執行緒安全 高亮日誌 日誌告警等功能也不在話下。下面就給大家介紹一下這個強大工具的基本使用方法。loguru 安裝方式很簡單,開啟終端輸入 pip install loguru即...

python怎麼取模 Python中的取模運算方法

所謂取模運算,就是計算兩個數相除之後的餘數,符號是 如a b就是計算a除以b的餘數。用數學語言來描述,就是如果存在整數n和m,其中0 m b,使得a n b m,那麼a b a n b m.取模運算的兩個運算元都必須是整數,可以是負整數,但是b不可以是0,因為被除數不能為0嘛。當a和b中存在負整數時...