Python log format output and time format, python log time format

Source: Internet
Author: User
Tags iso 8601 month name

Python log format output and time format, python log time format

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


The above % Y and so on are time formats, so to understand the above, Let's 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 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

In our example Year, month, day, hour, minute, secondTo display the date.
In addition, we need to understand the meaning of format characters such as % (asctime) s. % (asctime) s indicates the current time in the string format; % (levelname) s, for logger. debug, It is DEBUG, if it is logger. error, it is ERROR; % (message) s, if there is a logger. warning ("HAHA") is the string HAHA at the % (message) s position. The more detailed format is as follows:

% (Name) s

Logger name

% (Levelno) s

Log Level in digital form

% (Levelname) s

Log Level in text format

% (Pathname) s

The complete path name of the module that calls the log output function.

% (Filename) s

File Name of the module that calls the log output function

% (Module) s

The name of the module that calls the log output function.

% (FuncName) s

Name of the function that calls the log output function

% (Lineno) d

The code line of the statement that calls the log output function

% (Created) f

Current Time, represented by floating points of time in UNIX standard

% (RelativeCreated) d

Number of milliseconds since Logger was created when log information is output

% (Asctime) s

The current time in string format. The default format is "16:49:45, 896 ". The comma is followed by a millisecond

% (Thread) d

Thread ID. Not possible

% (ThreadName) s

Thread name. Not possible

% (Process) d

Process ID. Not possible

% (Message) s

User Output Message






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.