20170621 python日誌檔案記錄

2021-08-02 20:50:06 字數 1102 閱讀 1431

python 日誌檔案記錄

# -*- coding:utf-8 -*- #

import logging

log_format = '%(filename)s [%(asctime)s] [%(levelname)s] %(message)s'

logging.basicconfig(format=log_format, datefmt='%y-%m-%d %h:%m:%s %p', level=logging.debug)

logging.debug('this message should be logged')

# %(levelname):日誌級別的名字格式

# %(levelno)s:日誌級別的數字表示

# %(name)s:日誌名字

# %(funcname)s:函式名字

# %(asctime):日誌時間,可以使用datefmt去定義時間格式,如上圖。

# %(pathname):指令碼的絕對路徑

# %(filename):指令碼的名字

# %(module):模組的名字

# %(thread):thread id

# %(threadname):執行緒的名字

# logging.basicconfig(format=log_format,datefmt='%y-%m-%d %h:%m:%s %p',level=logging.debug) #設定日誌輸出格式和級別。

log_filename = "logging_test.log"

logging.basicconfig(filename=log_filename, filemode='w', level=logging.debug)

logging.debug('this message should be logged')

logging.info('so should this')

logging.warning('and this, too')

# 看了吧,日誌的設定都是使用basicconfig()方法,需要注意的是,日誌寫入檔案的預設方式是『a』,也就是追加,如果想覆蓋檔案,則使用如上圖那樣,使用filemode='w'。

python標記日子 學習python的日子(一)

最開始接觸python,是用了乙個大神開發的工具條,對python十分感興趣就找了本書開始學習,沒學幾天就開始忙著找工作了,簡歷中寫著正在學習python,但是有次面試360的,受了打擊,發現自己之前懂得都太淺顯了。剛好找工作告一段落,現在開始好好學習python了。話說 head first 系列...

python日期和時間設定 Python日期和時間

日期和時間主要有兩個庫,datetime和time.datetime 日期 datetime.date.today 1000天之後 datetime.datetimedelta days 1000 列印格式的問題 isoformat strftime 字串轉換 strptime time datet...

python一日總結

今天學習一下python基本操作中的if和while迴圈今天說一下if語句和while迴圈 age int input 請輸入年齡 定義字串 int是轉化為整數 if age 0and age 120 判斷條件 if age 18 再次判斷 print 你是乙個成年人!列印 elif age 18 ...