import logging
# 建立logging物件
logger = logging.getlogger(
)log_dir_path =
"***xx/***x/test.log"
# log檔案路徑
# 建立乙個檔案物件, 如果檔案超過500個bytes,僅保留5個檔案。
fh = logging.handlers.rotatingfilehandler(log_dir_path, maxbytes=
500, backupcount=
5, encoding=
"utf-8"
)# th = handlers.timedrotatingfilehandler(filename=filename, when='s', backupcount=3, encoding='utf-8') # 這個是按照時間進行切分的,這裡是秒,按周(w)、天(d)、時(h)、分(m)、秒(s)切割
# 建立乙個螢幕物件
sh = logging.streamhandler(
)# 配置顯示格式 可以設定兩個配置格式 分別繫結到檔案和螢幕上
formatter = logging.formatter(
'%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
)fh.setformatter(formatter)
# 將格式繫結到兩個物件上
sh.setformatter(formatter)
logger.addhandler(fh)
# 將兩個控制代碼物件繫結到logger
logger.addhandler(sh)
logger.setlevel(logging.info)
# 設定logger等級
fh.setlevel(logging.debug)
# 寫入檔案的顯示等級從debug開始
sh.setlevel(logging.warning)
# 在螢幕顯示等級的從warning開始
logger.debug(
'debug message'
)# 排錯
logger.info(
'info message'
)# 正常資訊
logger.warning(
'warning message'
)# 警告
logger.error(
'error message'
)# 錯誤
logger.critical(
'critical message'
)# 崩潰
format引數中可能用到的格式化串:
%(name)s logger的名字
%(levelno)s 數字形式的日誌級別
%(levelname)s 文字形式的日誌級別
%(pathname)s 呼叫日誌輸出函式的模組的完整路徑名,可能沒有
%(filename)s 呼叫日誌輸出函式的模組的檔名
%(module)s 呼叫日誌輸出函式的模組名
%(funcname)s 呼叫日誌輸出函式的函式名
%(lineno)d 呼叫日誌輸出函式的語句所在的**行
%(created)f 當前時間,用unix標準的表示時間的浮 點數表示
%(relativecreated)d 輸出日誌資訊時的,自logger建立以 來的毫秒數
%(asctime)s 字串形式的當前時間。預設格式是 「2003-07-08 16:49:45,896」。逗號後面的是毫秒
%(thread)d 執行緒id。可能沒有
%(threadname)s 執行緒名。可能沒有
%(process)d 程序id。可能沒有
%(message)s使用者輸出的訊息
django專案中的log使用
import logging.config # config 配置
# 定義三種日誌輸出格式 開始
standard_format =
'[%(asctime)s][%(threadname)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
'[%(levelname)s][%(message)s]'
#其中name為getlogger指定的名字
******_format =
'[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
id_******_format =
'[%(levelname)s][%(asctime)s] %(message)s'
# 定義日誌輸出格式 結束
logfile_name =
'log1.log'
# log檔名
logfile_path_staff = r'c:\users\administrator\pycharmprojects\23期\第五周\logging模組\日誌資料夾\log1.log'
# log配置字典
# logging_dic第一層的所有的鍵不能改變
logging_dic =
,'******':,
},'filters':,
'handlers':,
#列印到檔案的日誌,收集info及以上的日誌
'fh':,
},'loggers':,
},}def
md_logger()
: logging.config.dictconfig(logging_dic)
# 匯入上面定義的logging配置 通過字典方式去配置這個日誌
logger = logging.getlogger(
)# 生成乙個log例項 這裡可以有引數 傳給task_id
return logger
# logger.debug('it works!') # 記錄該檔案的執行狀態
dic =
deflogin()
:# print('登陸成功')
md_logger(
).info(f"登陸成功"
)def
aricle()
:print()
login(
)aricle(
)
建立IOS專案的配置
新建專案需要的配置 不是所有的icon都是需要配置的,spotilight是可以不用配置 icon對應的格仔放大多的圖 xxpt的格仔,xx xx 3 啟 launchscreen.xib 只能支援ios8系統 啟 對開發的影響 如果只配置4 s的啟 沒有配置5 s的啟 在5 s上面會出現黑條 如果...
java web專案的https配置
1 進入到jdk下的bin目錄 keytool v genkey alias tomcat keyalg rsa keystore d tomcat.keystore validity 36500附 d tomcat.keystore是將生成的tomcat.keystore放到d盤根目錄下。vali...
Unity專案的 gitignore配置
unity專案只需要關注assets projectsettings packages三個資料夾的版本控制。最新版的unity基本已經將設定預設為可版本管理狀態。我使用的版本是unity2019.4.13。如果不放心,大家可以自行檢視一下這兩個配置的地方是否正確。edit 專案設定 編輯器 確保如下...