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. BZOJ 3112 Zjoi2013 防守战线 单纯形

    题目大意: 单纯形*2.. . #include <cmath> #include <cstdio> #include <cstring> #include < ...

  2. Visual Prolog 的 Web 专家系统 (8)

    GENI核心 -- 推理引擎(2)流量控制 1.阐述fail."!"而回溯 与其他语言相比,,Prolog最大的特点.这是回溯机制. 回溯机制,还有的主要手段2个月,首先,通过使用 ...

  3. java nio-理解同步、异步,阻塞和非阻塞

    理解同步.异步,阻塞和非阻塞 结论:阻塞.非阻塞与是否同步异步无关.     转自知乎 “阻塞”与"非阻塞"与"同步"与“异步"不能简单的从字面理解, ...

  4. 为什么使用 React? Edit on GitHub

    为什么使用 React? React 是一个 Facebook 和 Instagram 用来创建用户界面的 JavaScript 库.很人多认为 React 是 MVC 中的 V(视图). 我们创造 ...

  5. HDU 4916 树分治

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. tar.bz2解压

    bzip2 -d gcc-4.1.0.tar.bz2 tar -xvf gcc-4.1.0.tar 或 tar -xvf *.tar

  7. 为什么推荐std::string而不是char*

    例如如下: map<const char*, const char*> map_test; map_test["a"] = "a"; map_tes ...

  8. android中用get和post方式向服务器提交请求

    通过get和post方式向服务器发送请求首先说一下get和post的区别get请求方式是将提交的参数拼接在url地址后面,例如http://www.baidu.com/index.jsp?num=23 ...

  9. STL源代码剖析 容器 stl_hashtable.h

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie hashtable ------------------------------------ ...

  10. Git双机同步

    如果使用git init 初始化,当客户端仓库push内容时,服务器端仓库可以看到log,但是更新的文件不能显示,必须使用git reset --hard才能更新内容