formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s","%Y%b%d-%H:%M:%S")

上面的%Y等是时间格式,所以要想理解上面要表示个什么,先来看一下Python的时间格式。

  • %a - abbreviated weekday name
  • %A - full weekday name
  • %b - abbreviated month name
  • %B - full month name
  • %c - preferred date and time representation
  • %C - century number (the year divided by 100, range 00 to 99)
  • %d - day of the month (01 to 31)
  • %D - same as %m/%d/%y
  • %e - day of the month (1 to 31)
  • %g - like %G, but without the century
  • %G - 4-digit year corresponding to the ISO week number (see %V).
  • %h - same as %b
  • %H - hour, using a 24-hour clock (00 to 23)
  • %I - hour, using a 12-hour clock (01 to 12)
  • %j - day of the year (001 to 366)
  • %m - month (01 to 12)
  • %M - minute
  • %n - newline character
  • %p - either am or pm according to the given time value
  • %r - time in a.m. and p.m. notation
  • %R - time in 24 hour notation
  • %S - second
  • %t - tab character
  • %T - current time, equal to %H:%M:%S
  • %u - weekday as a number (1 to 7), Monday=1. Warning: In Sun Solaris Sunday=1
  • %U - week number of the current year, starting with the first Sunday as the first day of the first week
  • %V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday
    as the first day of the week
  • %W - week number of the current year, starting with the first Monday as the first day of the first week
  • %w - day of the week as a decimal, Sunday=0
  • %x - preferred date representation without the time
  • %X - preferred time representation without the date
  • %y - year without a century (range 00 to 99)
  • %Y - year including the century
  • %Z or %z - time zone or name or abbreviation
  • %% - a literal % character

我们的样例是以  年月日-时:分:秒  的形式显示日期的。

除此之外,还要理解%(asctime)s等格式符所代表的意义,%(asctime)s表示这个位置上是字符串形式的当前时间。%(levelname)s,假设是logger.debug则它是DEBUG。假设是logger.error则它是ERROR;%(message)s,假如有logger.warning("HAHA"),则在%(message)s位置上是字符串HAHA。更具体的格式符例如以下:

%(name)s

Logger的名字

%(levelno)s

数字形式的日志级别

%(levelname)s

文本形式的日志级别

%(pathname)s

调用日志输出函数的模块的完整路径名,可能没有

%(filename)s

调用日志输出函数的模块的文件名称

%(module)s

调用日志输出函数的模块名

%(funcName)s

调用日志输出函数的函数名

%(lineno)d

调用日志输出函数的语句所在的代码行

%(created)f

当前时间,用UNIX标准的表示时间的浮 点数表示

%(relativeCreated)d

输出日志信息时的,自Logger创建以 来的毫秒数

%(asctime)s

字符串形式的当前时间。

默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒

%(thread)d

线程ID。可能没有

%(threadName)s

线程名。

可能没有

%(process)d

进程ID。可能没有

%(message)s

用户输出的消息




版权声明:本文博客原创文章,博客,未经同意,不得转载。

Python日志输出格式和时间格式的更多相关文章

  1. python 基础 7.2 时间格式的相互转换

    #/usr/bin/python #coding=utf-8 #@Time   :2017/11/9 8:55 #@Auther :liuzhenchuan #@File   :时间格式的相互转换.p ...

  2. nginx访问日志中的时间格式修改

    1.说明 默认的时间格式是:[08/Mar/2013:09:30:58 +0800],由$time_local变量表示. 我想要改成如下格式:2013-03-08 12:21:03. 2.需要修改的文 ...

  3. tomcat的catalina.out日志按自定义时间格式进行分割

    默认情况下,tomcat的catalina.out日志文件是没有像其它日志一样,按日期进行分割,而是全部输出全部写入到一个catalina.out,这样日积月累就会造成.out日志越来越大,给管理造成 ...

  4. python解决json序列化时间格式

    简单实例 import json from datetime import datetime from datetime import date info = { "name": ...

  5. python获取hive表时间格式最大分区

    #获取表的最大分区 import boto3 from datetime import datetime,timedelta def get_max_partition(db_name,table_n ...

  6. python 日志类

    简介 在所有项目中必不可少的一定是日志记录系统,python为我们提供了一个比较方便的日志模块logging,通常,我们都会基于此模块编写一个日志记录类,方便将项目中的日志记录到文件中. loggin ...

  7. python实现根据当前时间创建目录并输出日志

    举个例子:比如我们要实现根据当前时间的年月日来新建目录来存放每天的日志,当前时间作为日志文件名称:代码如下: #!/usr/bin/env python3 # _*_ coding: utf-8 _* ...

  8. python 爬虫时间数据-时间格式转换

    1 import time,datetime 2 3 time_original = '17/Sep/2012:11:40:00' 4 time_format = datetime.datetime. ...

  9. python中将HTTP头部中的GMT时间转换成datetime时间格式

    原文: https://blog.csdn.net/zoulonglong/article/details/80585716 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...

随机推荐

  1. Nagios的客户端的安装

    一.Linux服务器的nagios客户端的安装 步骤: 1.  创建目录,上传文件到该目录 mkdir /data nagios-plugins-2.1.1.tar.gz nrpe-2.12.tar. ...

  2. cocos2dx的模板容器简单使用(Vector,Map,Value)

    在cocos2dxv3.0beta之前存在顺序性容器cocos2d::CCArray,和cocos2d::CCDictionary.可是在新版本号之后这两个容器都将被cocos2d::Vector&l ...

  3. JSP简单介绍

    前言 知识点 1.JSP是什么   java  server   page,javaserver端页面技术.其主要作用在server端动态生成页面, 其组成java代码和html, 2.JSP的组成 ...

  4. [jQuery]地图浏览:如何实现图片的放大缩小和点击之后的位置居中

    HTML代码: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis. ...

  5. 认为C/C++很难理解、找工作面试笔试,快看看这本书!

    假设你是C/C++谁刚开始学习,看这本书.因为也许你读其他的书还不如不看.一定要选择一本好书. 假设你正在准备工作,请认真看这本书,由于这本书会教会你工作中必备的知识,相信你即将面临的语法类题目不会超 ...

  6. SVM-SVM概述

    (一)SVM背景资料简介 支持向量机(Support Vector Machine)这是Cortes和Vapnik至1995首次提出,样本.非线性及高维模式识别中表现出很多特有的优势,并可以推广应用到 ...

  7. TP-LINK telnet远程 重启路由器(转)

    突然断网,以前房东的路由器管理页面可以打开,今天突然间就打不开了.ping了下,可以ping通,于是就想起了房东的路由器是TP-LINK的 可以 telnet登陆的.每次,断网,我都会重启房东的路由器 ...

  8. JNDI 什么

    JNDI是 Java 命名与文件夹接口(Java Naming and Directory Interface).在J2EE规范中是重要的规范之中的一个,不少专家觉得,没有透彻理解JNDI的意义和作用 ...

  9. JAVA 数据权限设计

    数据权限设计 前言 在各种系统中.要保证数据对象的安全性以及易操作性,使企业的各业务部门.职能部门可以方便并且高效的协同工作,那么一个好的数据权限管理设计就成为一个关键的问题.尽管企业中各个单元的工作 ...

  10. 排序算法c语言描述---冒泡排序

    排序算法系列学习,主要描述冒泡排序,选择排序,直接插入排序,希尔排序,堆排序,归并排序,快速排序等排序进行分析. 文章规划: 一.通过自己对排序算法本身的理解,对每个方法写个小测试程序. 具体思路分析 ...