Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18019 > unrolled thread
| Started by | Lie Ryan <lie.1296@gmail.com> |
|---|---|
| First post | 2011-12-27 21:48 +1100 |
| Last post | 2011-12-27 21:48 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: python logging module:a quick question Lie Ryan <lie.1296@gmail.com> - 2011-12-27 21:48 +1100
| From | Lie Ryan <lie.1296@gmail.com> |
|---|---|
| Date | 2011-12-27 21:48 +1100 |
| Subject | Re: python logging module:a quick question |
| Message-ID | <mailman.4130.1324982957.27778.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web