??python????????????????????(4)
???????????? ???????[ 2014/1/7 16:06:18 ] ??????????????? python
????????????У?????????????????????????????????????????????????????????????
?????????????????
???????????????????????????????????????????????????ò??????CPU ??????
??????????????????????????дl(shuí)og?????????????????дl(shuí)og??????????
?????????????дl(shuí)og ???????? ?????2???
?????????????Queue????log????????и?log queue???棬????????????дl(shuí)og
???????????????socket server???? ???server??????log????????дl(shuí)og
???????????2????????????????дl(shuí)og????????????????????????????????????????дl(shuí)og??????????????????????????д???log????????????????е?С?????? ????????????и?????????(https://launchpad.net/python-concurrent-log-handler)??????????????дl(shuí)og????????????????????СRotatingFileHandler?? ?????rotate ????????????????????????????
try:
from cloghandler import ConcurrentRotatingFileHandler as RFHandler
except ImportError:
from warnings import warn
warn("ConcurrentLogHandler package not installed. Using builtin log handler")
from logging.handlers import RotatingFileHandler as RFHandler
rotateHandler = RFHandler("sim.log"?? "a"?? 10*1024*1024?? 5)
formatter = logging.Formatter('%(asctime)s [%(processName)s %(threadName)s %(levelname)s %(module)s:%(lineno)d] %(message)s')
rotateHandler.setFormatter(formatter)
log = logging.getLogger()
log.addHandler(rotateHandler)
log.setLevel(20)
rotateHandler = RFHandler("sim.log"?? "a"?? 10*1024*1024?? 5)
????log??????sim.log?? ?????10M??rotate?? ????5?????
????formatter = logging.Formatter('%(asctime)s [%(processName)s %(threadName)s %(levelname)s %(module)s:%(lineno)d] %(message)s') ????log????????? ??????????????????????????????????????
????log.setLevel(20) ???????????log????? CRITICAL 50; ERROR 40; WARNING 30; INFO 20; DEBUG 10?? NOSET 0;
import logging
import time
import multiprocessing
class Customer(multiprocessing.Process):
def __init__(self??mp_name):
multiprocessing.Process.__init__(self??name=mp_name)
def run(self):
while 1:
logging.debug(" I am here")
time.sleep(1)
for i in xrange(2):
mp=Customer("customer"+str(i))
mp.start()
?????????log?????????
2013-12-05 21:42:10??961 [customer0 MainThread DEBUG testqueue_old:115] I am here
2013-12-05 21:42:15??361 [customer1 MainThread DEBUG testqueue_old:115] I am here
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11