formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s","%Y%b%d-%H:%M:%S")
上面的%Y等是时间格式,所以要想理解上面要表示个什么,先来看一下Python的时间格式。
我们的例子是以 年月日-时:分:秒 的形式显示日期的。除此之外,还要理解%(asctime)s等格式符所代表的意义,%(asctime)s表示这个位置上是字符串形式的当前时间;%(levelname)s,如果是logger.debug则它是DEBUG,如果是logger.error则它是ERROR;%(message)s,假如有logger.warning("HAHA"),则在%(message)s位置上是字符串HAHA。更详细的格式符如下: