Python log format output and time format

Source: Internet
Author: User
Tags iso 8601 month name

Formatter = logging. Formatter ("% (asctime) s% (levelname) s% (message) S", "%y%b%d-%h:%m:%s")


The above%y is a time format, so to understand what to indicate above, first look at the Python time format.


  • %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, Range xx to 99)
  • %d-day of the Month (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 (xx to 23)
  • %i-hour, using a 12-hour clock (12)
  • %j-day of the year (001 to 366)
  • %m-month (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 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, where Week 1 are the first week that have at least 4 days in t He 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 xx to 99)
  • %y-year including the century
  • %Z or%z-time zone or name or abbreviation
  • Percent-a literal% character

Our example is to display the date in the form of a month day-time: minute: seconds .
In addition to this, it is necessary to understand the meaning of the format characters such as% (Asctime) s, and% (asctime) s means the current time as a string in this position;% (LevelName) s, If it is logger.debug then it is debug, if it is logger.error then it is error;% (message) s, if there is logger.warning ("HAHA"), then in % (message) The s position is the string haha. More detailed format characters are as follows:

When the log information is output, the number of milliseconds since the logger was created

TD valign= "Top" width= "358" style= "margin:0px; padding:3px; border:1px solid silver; Border-collapse:collapse ">

% (name) s

Logger's name.

% (levelno) s

log level in digital form

% (levelname) s

The log level in text form

% (pathname) s

The full pathname of the module that called the log output function, may not have

% (filename) s

filename of the module that called the log output function

% (module) s

call the module name of the log output function

% (funcName) s

call the function name of the log output function

% (lineno) d

The code line where the statement that called the log output function is located

% (created) F

current time, a floating-point number representing time with UNIX standard

% (relativecreated) d

% (asctime) s

The current time in string form. The default format is "2003-07-08 16:49:45,896". After the comma is milliseconds

% (thread) d

thread ID. May not have

% (threadname) s

thread name. May not have

% (process) d

process ID. May not have

% (message) s

User-Output messages






Python log format output and time format

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.