472,139 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

Logger / I get all messages 2 times

ASh
Hi,

I have this source:

import logging
import logging.config

logging.config.fileConfig("logging.properties")
log = logging.getLogger("qname")
log.debug("message")

------------------- OUTPUT
DEBUG logger_test:8: message
DEBUG logger_test:8: message

------- FILE CONFIG
[formatters]
keys: detailed

[handlers]
keys: console

[loggers]
keys: root, engine

[formatter_detailed]
format: %(levelname)s %(module)s:%(lineno)d: %(message)s

[handler_console]
class: StreamHandler
args: []
formatter: detailed

[logger_root]
level: ERROR
handlers: console

[logger_engine]
level: DEBUG
qualname: qname
handlers: console

---------------

Why do I get the log 2 times?

Oct 23 '08 #1
3 1294
ASh wrote:
Hi,

I have this source:

import logging
import logging.config

logging.config.fileConfig("logging.properties")
log = logging.getLogger("qname")
log.debug("message")

------------------- OUTPUT
DEBUG logger_test:8: message
DEBUG logger_test:8: message

------- FILE CONFIG
[formatters]
keys: detailed

[handlers]
keys: console

[loggers]
keys: root, engine

[formatter_detailed]
format: %(levelname)s %(module)s:%(lineno)d: %(message)s

[handler_console]
class: StreamHandler
args: []
formatter: detailed

[logger_root]
level: ERROR
handlers: console

[logger_engine]
level: DEBUG
qualname: qname
handlers: console

---------------

Why do I get the log 2 times?
Because you add the handler "console" two times, to logger_engine and
logger_root. You should only add it to root, or set propagate to false.

Diez
Oct 23 '08 #2
ASh
On Oct 23, 5:10*pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
ASh wrote:
Hi,
I have this source:
import logging
import logging.config
logging.config.fileConfig("logging.properties")
log = logging.getLogger("qname")
log.debug("message")
------------------- OUTPUT
DEBUG logger_test:8: *message
DEBUG logger_test:8: *message
------- FILE CONFIG
[formatters]
keys: detailed
[handlers]
keys: console
[loggers]
keys: root, engine
[formatter_detailed]
format: %(levelname)s %(module)s:%(lineno)d: *%(message)s
[handler_console]
class: StreamHandler
args: []
formatter: detailed
[logger_root]
level: ERROR
handlers: console
[logger_engine]
level: DEBUG
qualname: qname
handlers: console
---------------
Why do I get the log 2 times?

Because you add the handler "console" two times, to logger_engine and
logger_root. You should only add it to root, or set propagate to false.

Diez
What if I want to output only the specific logger to console and
ignore every other?
Oct 24 '08 #3
On Oct 24, 8:28 am, ASh <anton.shish...@gmail.comwrote:
On Oct 23, 5:10 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
ASh wrote:
Hi,
I have this source:
importlogging
importlogging.config
>logging.config.fileConfig("logging.properties")
log =logging.getLogger("qname")
log.debug("message")
------------------- OUTPUT
DEBUG logger_test:8: message
DEBUG logger_test:8: message
------- FILE CONFIG
[formatters]
keys: detailed
[handlers]
keys: console
[loggers]
keys: root, engine
[formatter_detailed]
format: %(levelname)s %(module)s:%(lineno)d: %(message)s
[handler_console]
class: StreamHandler
args: []
formatter: detailed
[logger_root]
level: ERROR
handlers: console
[logger_engine]
level: DEBUG
qualname: qname
handlers: console
---------------
Why do I get the log 2 times?
Because you add the handler "console" two times, to logger_engine and
logger_root. You should only add it to root, or set propagate to false.
Diez

What if I want to output only the specific logger to console and
ignore every other?
Just add the handler to the logger you want and to no other logger.
Then, events logged with the logger you want (and its child loggers)
will be sent to the console. If you don't want the child loggers to
log to console, set their propagate value to 0.

Regards,

Vinay Sajip
Oct 24 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by peiyin.li | last post: by
1 post views Thread by robert | last post: by
10 posts views Thread by Gary Jefferson | last post: by
5 posts views Thread by CedricCicada | last post: by
2 posts views Thread by Steve Greenland | last post: by
4 posts views Thread by garyjefferson123 | last post: by
4 posts views Thread by skunkwerk | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.