日志模块logging

内置,直接导入

import logging

设置日志文件路径

format = '[%(asctime)s %(name)-12s][%(levelname)-8s %(threadName)s]%(message)s'

    logging.basicConfig(level=logging.DEBUG,

                        format = format,

                        datefmt='%m-%d %H:%M:%S', filename=path)

    console = logging.StreamHandler()

    console.setLevel(logging.INFO)

    formatter = logging.Formatter('%(message)s')

    console.setFormatter(formatter)

    logging.getLogger('123').addHandler(console)

设置日志标识

_logger = logging.getLogger('123')

打印日志

_logger.debug(msg)

_logger.info(msg)

_logger.warning(msg)

_logger.error(msg)

_logger.critical(msg)

如果想对日志进行分天,可以将日志文件设为日期

你可能感兴趣的:(日志模块logging)