A simple example of Python (2.7.6) Log processing

Source: Internet
Author: User

The logging module in the Python Standard library provides a standard set of APIs to handle the printing of log information.

ImportLogginglogging.basicconfig ( level=logging. DEBUG, Format='% (asctime) s [% (ThreadName) s] (% (filename) s:% (lineno) d)% (levelname) s-% (message) s', Datefmt='%y-%m-%d%h:%m:%s', filename='Myapp.log',) Logging.debug ('This is a debug message') Logging.info ('This is an info message') logging.warning ('This is a warning message')

The logs printed in Myapp.log are as follows:

2015-03-11 15:54:34 [Mainthread] (logging_demo.py:10) debug-this is a DEBUG message2015-03-11 15:54:34 [MainThread] (log GING_DEMO.PY:11) Info-this is an INFO message2015-03-11 15:54:34 [Mainthread] (Logging_demo.py:12) Warning-this is a W Arning message

The parameter description of the Logging.basicconfig function:

Parameters Description
FileName Log file name
FileMode Open mode of log file, default to ' a '
Format Output format of the log
Datefmt The output format of the time
Level Log level, size relationship CRITICAL (0) > ERROR (+) > WARNING (+) > INFO > DEBUG (Ten) > NOTSET (+)
Stream The output stream of the log print, which is ignored when specified with filename

Formatting symbols in Logging:

Symbol Description
% (Asctime) s Time
% (filename) s Filename
% (FuncName) s Name of function
% (LevelName) s Log level values
% (Levelno) s Log level
% (Lineno) d Line number
% (module) s Module
% (message) s Log Messages
% (name) s Journal name
% (pathname) s Name of the Logger
% (process) d Process ID
% (ProcessName) s Process Name
% (thread) d Thread ID
% (ThreadName) s Thread Name

A simple example of Python (2.7.6) Log processing

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.