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. 在 window7 window8下公布webService注意问题

    李石磊 学习日记 错误形如: 解决方式: 1.将服务公布,在IIS下创建虚拟文件夹 2.为上面创建的虚拟文件夹创建单独的应用程序,方法是右击虚拟文件夹.点击"加入应用程序...", ...

  2. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  3. xcode Workspaces

    A workspace is an Xcode document that groups projects and other documents so you can work on them to ...

  4. 利用Java针对MySql封装的jdbc框架类 JdbcUtils 完整实现(包括增删改查、JavaBean反射原理,附源代码)

    近期看老罗的视频,跟着完毕了利用Java操作MySql数据库的一个框架类JdbcUtils.java,完毕对数据库的增删改查.当中查询这块,包含普通的查询和利用反射完毕的查询,主要包含以下几个函数接口 ...

  5. VS2008--无法找到“XXX.exe”的调试信息,或者调试信息不匹配

    ------解决方案----- 1. 关闭掉Visual Studio 实例. 2. 找到解决方案下的.suo文件并删除之. 3. 重新启动Visual Studio,或者直接双击.sln文件打开 4 ...

  6. CentOS7 编译安装LNMP

    (文章来自:http://www.cnblogs.com/i-it/p/3841840.html,请各位到这个网址去看原文的) LNMP(Linux-Nginx-Mysql-PHP),本文在CentO ...

  7. unity3d教程动态创建简单平面地形

    unity3d创建地形是不须要usingUnityEditor的.这里使用了AssetDatabase.所以需using UnityEditor; 创建三步: 1.TerrainData terrai ...

  8. windows phone 独立存储空间的操作 (2)

    原文:windows phone 独立存储空间的操作 (2) IsolatedStorage独立存储空间是保存应用程序的一些数据已经配置文件,独立存储空间相对于其他的wp程序是独立的,也就是说每个wp ...

  9. Java EE (9) -- JDBC & JTA

    Connection接口中定义了5中隔离级别常量 Connection.TRANSACTION_NONE  --  不支持事务 Connection.TRANSACTION_READ_UNCOMMIT ...

  10. Android 关于资源适配

    一. 关于图片资源 图片宽高 不要固定大小,在小屏幕和大屏幕,不同分频率上 ,採用不同的图片,这个要美工切图的. 不同的分辨率,界面的长宽比不一致,须要不同规格的图片 在drawable-hdpi,d ...