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?
- Log = logging. getlogger ('Django')
Log = logging. getlogger ('django ')[Python]View plaincopyprint?
- 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 ,},},}