473,382 Members | 1,646 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,382 software developers and data experts.

multiple logger

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( 'project1.log',
maxBytes=1024)
project1Handler.setLevel(logging.INFO)
formatter1 = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')
project1Handler.setFormatter(formatter1)
logging.getLogger('project1').addHandler(project1H andler)
logger1 = logging.getLogger('project1')

logger1.debug('Quick zephyrs blow, vexing daft Jim.')
logger1.info('How quickly daft jumping zebras vex.')
logger1.warning('Jail zesty vixen who grabbed pay from quack.')
logger1.error('The five boxing wizards jump quickly.')
project2Handler = logging.handlers.RotatingFileHandler( 'project2.log',
maxBytes=1024)
project2Handler.setLevel(logging.DEBUG)
formatter2 = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')
project2Handler.setFormatter(formatter2)
logging.getLogger('project2').addHandler(project2H andler)
logger2 = logging.getLogger('project2')

logger2.debug('Quick zephyrs blow, vexing daft Jim.')
logger2.info('How quickly daft jumping zebras vex.')
logger2.warning('Jail zesty vixen who grabbed pay from quack.')
logger2.error('The five boxing wizards jump quickly.')
However, I got this for project1.log:

project1 : WARNING Jail zesty vixen who grabbed pay from quack.
project1 : ERROR The five boxing wizards jump quickly.

and this for project2.log:

project2 : WARNING Jail zesty vixen who grabbed pay from quack.
project2 : ERROR The five boxing wizards jump quickly.

Where are the DEBUG and INFO messages go?

I then add this at the begining of my code:

logging.basicConfig(level=logging.DEBUG)

Now it seems that both project1.log and project2.log has the correct
output. But I also see all the log message going to the console, which
I really don't want.

What did I miss here? Do I have to set a handler for the root logger
before I can set something for the child loggers? If yes, how do I make
the root logger logs to nowhere?

Thanks in advance!

Albert

Oct 7 '05 #1
1 1994
Just replace

logging.basicConfig(level=logging.DEBUG)

with

logging.getLogger().setLevel(logging.DEBUG)

and you will no longer get messages written to the console. The
basicConfig() method is meant for really basic use of logging - it
allows one call to set level, and to add either a console handler a
simple (non-rotating) file handler to the root logger. See the
documentation for more information.

Vinay Sajip

Oct 7 '05 #2

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

Similar topics

3
by: Jeff Shannon | last post by:
I'm having some difficulty getting my logging configuration set correctly. I'm using a config file (copied at end of post), with the intent of setting several loggers which write to a combination...
0
by: Laszlo | last post by:
Hi I need a GL::Logger wich implements Class::Singleton to be a singleton and Log::Log4perl to can log amy message into a file. Here is the module source:...
4
by: Rob Conner | last post by:
No you don't need to know Zope to help me. The whole reason I'd even want to do this is because of Zope though. I made a Zope product, and now want to perfect it. some simple example code... ...
2
by: raffelm | last post by:
Bear with my while I try to explain... I've created these two interfaces: public interface ILoggingEvents { event LoggingWindowClosing OnClosing;} public interface ILogging { ... } I then...
1
by: bneron | last post by:
hello, I use the logging module include in Python 2.4 distribution, and I 'd like to have a logger witth several Handlers . I know how to do this by coding in python, but could I specify this...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
1
by: Chris Curvey | last post by:
Hi all, I've apparently tied myself up a bit using the logging package. In my project, I have a core set of model and controller classes that set up their logging using logging.fileConfig()....
6
by: Mr Flibble | last post by:
Hi all, I've decided to use log4net for my logging/tracing. In the example on the site it shows using main() to setup the root logger and then using the LogManager within your classes to...
1
by: Almad | last post by:
Hi, our applications can have plugins as subpackages and I'd like to allow them to use their own logger as well as it's configuration. I thought that best way will be their own configuration...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...
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...

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.