473,379 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 1346
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: peiyin.li | last post by:
Hi, I want to have two loggers that logs to two different files. Here is what I have: import logging import logging.handlers project1Handler = logging.handlers.RotatingFileHandler(...
1
by: robert | last post by:
some packages like paramiko use the logging. I get this messages: "No handlers could be found for logger xxx" on stderr I don't want to deal with this logging at all so far - its useless in this...
10
by: Gary Jefferson | last post by:
Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B', and each module has its own logger, created with: module1logger = logging.getLogger('project.A') and module2logger =...
5
by: CedricCicada | last post by:
Greetings! I want to write messages into the Windows event log. I found sevicemanager, but the source is always "Python Service", and I'd like to be a bit more descriptive. Poking around on...
2
by: Steve Greenland | last post by:
Apparently I don't understand logging levels. The code: import logging, logging.handlers logging.basicConfig(level=logging.WARNING) newlog = logging.handlers.TimedRotatingFileHandler(...
4
by: garyjefferson123 | last post by:
Suppose I have some sort of context variable that I want to appear in log messages. E.g.: logger = logging.getLogger("somelogger") class SomeOp: def __init__(self, ctx): self.ctx = ctx def...
4
by: skunkwerk | last post by:
i'm redirecting the stdout & stderr of my python program to a log. Tests i've done on a simple program with print statements, etc. work fine. however, in my actual program i get weird output like...
1
by: nagk9 | last post by:
Hi , I am using log4j in my application. I have the problem with log4j.properties file . It will automatically appends another logger file from the current logger which i am using for the...
0
by: archwn | last post by:
Dear all, I would like to create a custom logger which allows logging commands in stream-style, but at the same time the output goes to some file or to the screen (cout) or to both. The code below...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.