Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the python(2.5.2)'s logging mechanism? is there log4j look a like library or standard class of python/geodjango will do?

I am planning to add logging mechanism in my python&geodjango web service. Is there log4j look a like logging mechanism in python/geodjango?

I am looking for log4j's dailyrollingfileappender equivalent. Then automatically delete all 1month old log files.

Any guidance is appreciated.

UPDATES1 I am thinking of the below format.

datetime(ms)|log level|current thread name|client ip address|logged username|source file|source file line number|log message
like image 467
eros Avatar asked Oct 23 '22 20:10

eros


1 Answers

Yes - Python 2.5 includes the 'logging' module. One of the handlers it supports is handlers.TimedRotatingFileHandler, this is what you're looking for. 'logging' is very easy to use:

example:

import logging
import logging.config

logging.fileConfig('mylog.conf')
logger = logging.getLogger('root')

The following is your config file for logging

#======================

# mylog.conf
[loggers]
keys=root

[handlers]
keys=default

[formatters]
keys=default

[logger_root]
level=INFO
handlers=default
qualname=(root) # note - this is used in non-root loggers
propagate=1 # note - this is used in non-root loggers
channel=
parent=

[handler_default]
class=handlers.TimedRotatingFileHandler
level=INFO
formatter=default
args=('try.log', 'd', 1)

[formatter_default]
format=%(asctime)s %(pathname)s(%(lineno)d): %(levelname)s %(message)s
like image 154
mnain Avatar answered Oct 27 '22 09:10

mnain