PYTHON Logging Module

Source: Internet
Author: User

Python's log function, began to run on the python2.4, a variety of error, and later replaced by python2.7.9.

Attach the Linux python upgrade process:

1. Download the Python installation package---Python-2.7.9. Tar.xz 2, download to download directory, unzip tar -xzvf Python-3.3. 0.tgz 3, enter the uncompressed folder CD Python -3.3. 0 4, before compiling before the/usr/local Build a folder Python3 (as a Python installation path to avoid overwriting the old version) mkdir /usr/local/ Python3 5, start compiling the installation . /configure--prefix=/usr/local/ python3make doinstall6, this time does not overwrite the old version, and then the original    /usr/bin/python link changed to another name MV /usr/bin/python/usr/bin/ python_old27, re-establish a new version of the Python link ln -s/usr/local/python3/bin/python3/usr/bin/ python8, enter python at this time- v

# -*-CODING=GBK-*- # filename:pythonglog.py __author__ ' Vincent ' Import Logging Import logging.configlogging.config.fileConfig ("pythonlog.conf")

#filename:pythonlog.conf#Define logger module, root is the parent class, must exist, others are custom. #Logging.getlogger (NAME) is equivalent to registering a log print to the logging module#name. Represents the inheritance relationship of log[Loggers]keys=Root,main,console#Define Handler[Handlers]keys=Filehandler,consolehandler#Defining formatted output[Formatters]keys=FMT#--------------------------------------------------#to implement the logger module defined above, it must be a form of [logger_xxxx]#--------------------------------------------------#[logger_xxxx] logger_ module name#Level with Debug, INFO, WARNING, ERROR, CRITICAL#handlers processing class, can have multiple, separated by commas#Qualname Logger Name, the application is obtained through Logging.getlogger. For names that cannot be obtained, the root module is logged. #whether the propagate inherits the log information of the parent class, 0: No 1: Yes[Logger_root]level=infohandlers=Filehandler[logger_main]level=errorhandlers=filehandlerpropagate=0qualname=Main[logger_console]level=infohandlers=consolehandlerpropagate=0qualname=Console#--------------------------------------------------#Handler#--------------------------------------------------#[Handler_xxxx]#class Handler category name#level log Levels#formatter, the formatter defined above#args handler initialization function arguments[Handler_filehandler]class=handlers. Rotatingfilehandlerlevel=Infoformatter=Fmtargs=('Python.log','a') [Handler_consolehandler]class=Streamhandlerlevel=Infoformatter=Fmtargs=(Sys.stdout,)#--------------------------------------------------#Log Format#--------------------------------------------------#% (Asctime) s year-month-day time-minute-second, millisecond 2013-04-26 20:10:43,745#% (filename) s file name, excluding directories#% (pathname) s directory name, full path#% (funcName) s function name#% (levelname) S-Class aliases#% (Lineno) d line number#% (module) s module name#% (message) s message body#% (name) s log Module name#% (process) d process ID#% (processName) s process name#% (thread) d thread ID#% (threadname) s thread name[Formatter_fmt]format=[% (asctime) s f=% (filename) s l=% (Lineno) d] [%(message) s]datefmt=%y/%m/%d%h:%m:%Sclass=logging. Formatter

Module test:

__author__ ' Vincent ' Import OS Import SYS Import Logging Import pythonlogconsole=logging.getlogger ("console") Console.info (  "This isLOGGER info! ")

Two log handles defined, one main, output log information to file Python.log, another console, output log information to screen

PYTHON Logging Module

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.