Django logging is configured in the settings. py file.

Source: Internet
Author: User

 

Support for django1.3 and later versions...

I did not get it out for a long time after I started with 1.2.5. It turned out to be a version problem. It was really depressing...

 

Configure logging in settings. py

  Logging = {<br/> 'version': 1, <br/> 'Disable _ existing_loggers ': True, <br/> 'formatters ': {<br/> 'normal': {</P> <p> 'format': '% (asctime) s [% (threadname) S: % (thread) d] [% (name) S: % (lineno) D] [% (levelname) S]-% (Message) s' <br/> }, <br/>}, <br/> 'filters ': {<br/>}, <br/> 'handlers': {<br/> 'mail _ admins ': {<br/> 'level': 'error', <br/> 'class': 'django. utils. log. adminemailhandler ', <br/> 'include _ html': True, <br/> # 'filters': ['special '], <br/> }, <br/> 'default': {<br/> 'level': 'debug', <br/> 'class': 'logging. handlers. rotatingfilehandler ', <br/> 'filename': OS. path. join ('logs/', 'all. log '), # or directly write the path: 'C: // logs/All. log', <br/> 'maxbytes ': 1024*1024*5, #5 MB <br/> 'backupcount': 5, <br/> 'formatter ': 'Standard', <br/>}, <br/> 'request _ handler': {<br/> 'level': 'debug ', <br/> 'class': 'logging. handlers. rotatingfilehandler ', <br/> 'filename': OS. path. join ('logs/', 'script. log '), # or directly write the path: 'filename': 'C:/logs/request. log'''Maxbytes ': 1024*1024*5, #5 MB <br/> 'backupcount': 5, <br/> 'formatter': 'standard ', <br/>}, <br/> 'scprits _ handler': {<br/> 'level': 'debug', <br/> 'class': 'logging. handlers. rotatingfilehandler ', <br/> 'filename': OS. path. join ('logs/', 'script. log '), # or directly write the path: 'filename': 'C:/logs/script. log' <br/> 'maxbytes ': 1024*1024*5, #5 MB <br/> 'backupcount': 5, <br/> 'formatter ': 'Standard', <br/>}, <br/>}, <br/> 'loggers': {<br/> 'django ': {<br/> 'handlers': ['default'], <br/> 'level': 'info', <br/> 'pagate ': false <br/>}, <br/> 'django. request ': {<br/> 'handlers': ['request _ handler'], <br/> 'level': 'debug', <br/> 'pagate ': false <br/>}, <br/> 'scripts': {# script-specific logs <br/> 'handlers': ['scprits _ handler'], <br/> 'level': 'info', <br/> 'pagate': false <br/>}, <br/>}< br/>}[Python] View plaincopyprint?

    1. Log = logging. getlogger ('Django')

Log = logging. getlogger ('django ')[Python]View plaincopyprint?

    1. Log.info ('Django logging ..............')

Log.info ('django logging ..............')[Python]View plaincopyprint?

Available

Logging = {'version': 1, 'Disable _ existing_loggers ': True, 'formatters': {'simple': {'format': '[% (asctime) s] % (levelname) S: % (Message) s '}, 'verbose': {'format': '[% (asctime) S] % (levelname) S % (module) S % (process) d % (thread) D: % (Message) s '}, 'standard': {'format':' % (asctime) s [% (threadname) S: % (thread) D] [% (name) S: % (lineno) D] [% (levelname) S]-% (Message) s '},}, 'handlers': {'mail _ admins': {'level': 'error', 'class': 'django. utils. log. adminemailhandler ', 'include _ HTML': True,}, 'default': {'level': 'debug', 'class': 'logging. handlers. rotatingfilehandler ', 'filename': OS. path. join ('logs/', 'debug _ default. log '), 'maxbytes': 1024*1024*5, 'backupcount': 5, 'formatter ': 'simple',}, 'request _ handler ': {'level': 'debug', 'class': 'logging. handlers. rotatingfilehandler ', 'filename': OS. path. join ('logs/', 'debug _ request. log '), 'maxbytes': 1024*1024*5, 'backupcount': 5, 'formatter ': 'standard',}, 'scprits _ handler ': {'level': 'debug', 'class': 'logging. handlers. rotatingfilehandler ', 'filename': OS. path. join ('logs/', 'debug _ scprits. log '), 'maxbytes': 1024*1024*5, 'backupcount': 5, 'formatter ': 'standard',}, 'console': {'level ': 'info', 'class': 'logging. handlers. rotatingfilehandler ', 'filename': OS. path. join ('logs/', 'info _ console. log '), 'formatter': 'simple',}, 'file': {'level': 'info', 'class': 'logging. handlers. rotatingfilehandler ', 'formatter': 'simple', 'filename': OS. path. join ('logs/', 'info _ file. log '), 'maxbytes': 1024*1024*5, #5 MB 'backupcount': 5, 'Mode': 'A',},}, 'loggers ': {'django ': {'handlers': ['file', 'console', 'request _ handler', 'scprits _ handler'], 'level': 'info ', 'pagate': True ,},},}

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.