473,385 Members | 2,243 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,385 software developers and data experts.

Removing default logging handler (causes duplicate logging)

Hello All,

I want to add a logger to my application, then addHandler to it to log to a
special destination.

Unfortunately when I use logging.getLogger("my_logger") to create the new
logger, it apparently comes with a default handler that logs to STDOUT (or
STDERR?). When I add my special handler it works Ok, but still logs to terminal,
which I do not want.

The only way I found to remove the default handler is by using
'logger.removeHandler(logger.handlers[0])'.

Is there a more elegant solution that uses the logging API?

my setup: Python 2.5.1 on Linux Suse 9.

P.S.I am not using Basic config, just 'import logging' and then regular
logging.* calls.

Thanks in advance,
Gal Aviel.

Mar 4 '08 #1
1 4106
On Mar 4, 1:29 pm, Gal Aviel <galav...@yahoo.comwrote:
Hello All,

I want to add a logger to my application, then addHandler to it to log to a
special destination.

Unfortunately when I use logging.getLogger("my_logger") to create the new
logger, it apparently comes with a default handler that logs to STDOUT (or
STDERR?). When I add my special handler it works Ok, but still logs to terminal,
which I do not want.
from docs:
------------------
getLogger( [name])

Return a logger with the specified name or, if no name is specified,
return a logger which is the root logger of the hierarchy.
------------------

so you should do 'root = getlogger()', then append your own logger to
the root.

Gerard
Mar 4 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: j vickroy | last post by:
Hello, I'm trying to understand the behavior of the Python 2.3 logging module (MS Windows 2k) with regard to RotatingFileHandler. The following script illustrates a puzzling problem. What is...
8
by: Steve Erickson | last post by:
I have a logger class that uses the Python logging module. When I call it within a program using the unittest module, I get one line in the log file for the first test, two identical ones for the...
23
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field...
2
by: Martin Lapierre | last post by:
How can I remove the default exception handler handler? When adding a custom handler, I can't get rid of the VS.NET unhandled exception dialog. Ex: AppDomain currentDomain =...
0
by: - vhannak | last post by:
I have Visual Studio C# app where the main form keeps a log of the application's status. For several of the event handlers and methods in the main form, I have try/catch blocks. But adding...
3
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the...
5
by: Shiao | last post by:
Hi, I am getting duplicate log entries with the logging module. The following behaves as expected, leading to one log entry for each logged event: logging.basicConfig(level=logging.DEBUG,...
4
by: Michele Simionato | last post by:
I have just discovered a bug in my code using the logging module, due to handlers not being closed properly. The issue was that I called the function removeHandler and I assumed that it took care...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.