python logging

https://blog.csdn.net/qq_17513503/article/details/80734393

LevelNumeric value
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0

 

 

 

 

 

 

 

 

 

Attribute nameFormatDescription
args You shouldn’t need to format this yourself. The tuple of arguments merged into msg to produce message, or a dict whose values are used for the merge (when there is only one argument, and it is a dictionary).
asctime %(asctime)s Human-readable time when the LogRecord was created. By default this is of the form ‘2003-07-08 16:49:45,896’ (the numbers after the comma are millisecond portion of the time).
created %(created)f Time when the LogRecord was created (as returned by time.time()).
exc_info You shouldn’t need to format this yourself. Exception tuple (à la sys.exc_info) or, if no exception has occurred, None.
filename %(filename)s Filename portion of pathname.
funcName %(funcName)s Name of function containing the logging call.
levelname %(levelname)s Text logging level for the message ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL').
levelno %(levelno)s Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL).
lineno %(lineno)d Source line number where the logging call was issued (if available).
message %(message)s The logged message, computed as msg % args. This is set when Formatter.format() is invoked.
module %(module)s Module (name portion of filename).
msecs %(msecs)d Millisecond portion of the time when the LogRecord was created.
msg You shouldn’t need to format this yourself. The format string passed in the original logging call. Merged with args to produce message, or an arbitrary object (see Using arbitrary objects as messages).
name %(name)s Name of the logger used to log the call.
pathname %(pathname)s Full pathname of the source file where the logging call was issued (if available).
process %(process)d Process ID (if available).
processName %(processName)s Process name (if available).
relativeCreated %(relativeCreated)d Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded.
stack_info You shouldn’t need to format this yourself. Stack frame information (where available) from the bottom of the stack in the current thread, up to and including the stack frame of the logging call which resulted in the creation of this record.
thread %(thread)d Thread ID (if available).
threadName %(threadName)s Thread name (if available).

import logging.handlers
import threading
import time
import datetime
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor

logger = logging.getLogger('zbw')
logger.propagate = False
logger.setLevel('INFO')
h1 = logging.handlers.TimedRotatingFileHandler(filename='C:\\Users\\tiny\\Documents\\logger.log', interval=1, encoding='utf-8')
logger.addHandler(h1)
formatter = logging.Formatter(fmt="%(asctime)s|%(filename)s|%(processName)s|%(threadName)s|%(funcName)s|%(message)s")
h1.setFormatter(formatter)


def cacl():
sum = 0
for i in range(100000000):
sum += 1
logger.info('__name__:{}sum:{}'.format(__name__, sum))
return sum


if __name__ == '__main__':
start = datetime.datetime.now()
with ThreadPoolExecutor(4) as te:
lst = [te.submit(cacl) for i in range(4)]
delta = (datetime.datetime.now()-start).total_seconds()
print(delta)
for fu in lst:
print(fu.done(), fu.result())

start = datetime.datetime.now()
with ProcessPoolExecutor(4) as pe:
lst = [pe.submit(cacl) for i in range(4)]
delta = (datetime.datetime.now()-start).total_seconds()
print(delta)
for fu in lst:
print(fu.done(), fu.result())

posted @ 2020-12-30 14:15  bwzbk  阅读(91)  评论(0)    收藏  举报