Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18019
| From | Lie Ryan <lie.1296@gmail.com> |
|---|---|
| Subject | Re: python logging module:a quick question |
| Date | 2011-12-27 21:48 +1100 |
| References | <4EF9651F.7070806@tysdomain.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4130.1324982957.27778.python-list@python.org> (permalink) |
On 12/27/2011 05:26 PM, Littlefield, Tyler wrote: > Hello all: > I have a basic server I am working on, and wanted some input with an > error I'm getting. > I am initializing the logger like so: > if __name__ == "__main__": > observer = log.PythonLoggingObserver() > observer.start() > logging.basicConfig(filename='logs/server.log', level=logging.DEBUG, > format='%(asctime)s [%(levelname)s] %(module)s:%(funcname)s:%(lineno)d > %(message)s') > logger = logging.getLogger() > logger.addHandler(logging.handlers.TimedRotatingFileHandler) You should pass an **instance** of the handler, not the class; so it should look like this: logger.addHandler(logging.handlers.TimedRotatingFileHandler(...)) if you want to configure the handler, e.g. configure how often the log file is rotated, you can do it by passing parameters to the handler's constructure, e.g.: logger.addHandler(logging.handlers.TimedRotatingFileHandler(filename='/foo/mylog.log', when='d', interval=3, backupCount=5)) will create a handler that will log to the file /foo/mylog.log and rotate the log every 3 days and keeps the last 5 logs for backup. the logging handlers are documented over here: http://docs.python.org/library/logging.handlers.html#logging.handlers.TimedRotatingFileHandler Note that if you're using a recent enough version of python, it's also possible to configure the logging module using a dictionary-based configuration. Dictionary-based configuration is generally simpler than code-based configuration.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: python logging module:a quick question Lie Ryan <lie.1296@gmail.com> - 2011-12-27 21:48 +1100
csiph-web