Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36276 > unrolled thread
| Started by | Peter Steele <pwsteele@gmail.com> |
|---|---|
| First post | 2013-01-06 11:10 -0800 |
| Last post | 2013-01-09 00:57 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Specifying two log files with one configuration file Peter Steele <pwsteele@gmail.com> - 2013-01-06 11:10 -0800
Re: Specifying two log files with one configuration file Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2013-01-09 00:57 +0000
| From | Peter Steele <pwsteele@gmail.com> |
|---|---|
| Date | 2013-01-06 11:10 -0800 |
| Subject | Specifying two log files with one configuration file |
| Message-ID | <4e6a4b79-5a4a-4e0b-818a-74cb7f0caf94@googlegroups.com> |
I want to configure the Python logging module to manage two separate log files, allowing me to do something like this:
import logging
import logging.config
logging.config.fileConfig("mylogging.conf")
root = logging.getLogger()
test = logging.getLogger("test")
root.debug("This is a message targeted to the root log file")
test.debug("This is a message targeted to the test log file")
I have been unable to get this to work. My current conf file looks like this:
[formatters]
keys: simple
[handlers]
keys: root,test
[loggers]
keys: root,test
[formatter_simple]
format=%(asctime)s - %(levelname)s - %(message)s
[handler_root]
class: handlers.RotatingFileHandler
args: ('/var/log/root.log', 'a', 1024000, 14)
formatter: simple
[handler_test]
class: handlers.RotatingFileHandler
args: ('/var/log/test.log', 'a', 1024000, 14)
formatter: simple
[logger_root]
level: DEBUG
handlers: root
qualname:
[logger_test]
level: DEBUG
handlers: test
qualname:
With this setup, all of my log messages go to test.log. root.log is created, but nothing gets logged to it. What do I need in my logging conf file to have two separate log file destinations?
[toc] | [next] | [standalone]
| From | Vinay Sajip <vinay_sajip@yahoo.co.uk> |
|---|---|
| Date | 2013-01-09 00:57 +0000 |
| Message-ID | <mailman.299.1357693038.2939.python-list@python.org> |
| In reply to | #36276 |
Peter Steele <pwsteele <at> gmail.com> writes: > I have been unable to get this to work. My current conf file looks like this: Try with the following changes: [logger_test] level: DEBUG handlers: test propagate: 0 qualname: test The qualname: test is what identifies the logger as the logger named 'test', and propagate: 0 prevents the test message from being passed up to the root logger. Regards, Vinay Sajip
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web