473,404 Members | 2,137 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,404 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 1349
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.