ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

logging.Formatter日志格式

2021-08-02 09:00:18  阅读:221  来源: 互联网

标签:week logging time year 日志 Formatter day first


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 pided 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

    用户输出的消息

标签:week,logging,time,year,日志,Formatter,day,first
来源: https://www.cnblogs.com/luckywh/p/15088482.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有