473,800 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

logging to two files

Hi

Have the following code:
import logging

logging.basicCo nfig(level = logging.DEBUG,
format = '[%(levelname)-8s %(asctime)s]
%(message)s',
filename = 'rfs.log',
filemode = 'w')

When using logging.(debug, info etc) stuff is logged to rfs.log.
How may I specify another log with different charateristics, such as a
different file

regards
Jul 19 '05 #1
2 3117
Tor Erik Sønvisen wrote:
Hi

Have the following code:
import logging

logging.basicCo nfig(level = logging.DEBUG,
format = '[%(levelname)-8s %(asctime)s]
%(message)s' ,
filename = 'rfs.log',
filemode = 'w')

When using logging.(debug, info etc) stuff is logged to rfs.log.
How may I specify another log with different charateristics, such as a
different file

regards

I'm not sure if I understood your problem. However, just a tip for you:
is it possible to create your own handler object? (See section 6.29.5 in
the library reference).
You could setup a handler object that holds a list of other handler
objects and distribute all logging events to them. This way you should
be able to add/remove handlers at runtime.

Best,

Laci 2.0

--
_______________ _______________ _______________ _______________ _____
Laszlo Nagy web: http://designasign.biz
IT Consultant mail: ga*****@geochem source.com

Python forever!
Jul 19 '05 #2
Tor Erik Sønvisen wrote:
Hi

Have the following code:
import logging

logging.basicCo nfig(level = logging.DEBUG,
format = '[%(levelname)-8s %(asctime)s]
%(message)s',
filename = 'rfs.log',
filemode = 'w')

When using logging.(debug, info etc) stuff is logged to rfs.log.
How may I specify another log with different charateristics, such as a
different file

regards

You have to not use basicConfig if you want multiple handlers. Instead set
up the configuration explicitly.

Here is some code I used recently which you can use as a base. It isn't
logging to two files, instead it logs to a file and the console.

# Initialise logging
def setupLogging():
SCRIPT = os.path.splitex t(os.path.basen ame(sys.argv[0]))[0]
SECTNAME = 'logging-'+SCRIPT
if not configuration.h as_section(SECT NAME):
SECTNAME = 'logging'

options = configuration.o ptions(SECTNAME )
if 'level' in options:
loglevel = configuration.g et(SECTNAME, 'level')
else:
loglevel = 'NOTSET'

if 'console' in options:
consolelevel = configuration.g et(SECTNAME, 'console')
else:
consolelevel = ''

if isinstance(logl evel, basestring):
loglevel = logging._levelN ames[loglevel.upper( )]

if 'format' in options:
logformat = configuration.g et(SECTNAME, 'format')
else:
logformat = '%(asctime)s %(levelname)s %(message)s'

if 'filename' in options:
logfile = configuration.g et(SECTNAME, 'filename')
else:
logfile='errors .log'

if 'filemode' in options:
logmode = configuration.g et(SECTNAME, 'filemode')
else:
logmode = 'a'

if isinstance(cons olelevel, basestring):
clevel = logging._levelN ames[consolelevel.up per()]
else:
clevel = consolelevel

handler = logging.FileHan dler(logfile, "a")
fmt = logging.Formatt er(logformat, "%Y-%m-%d %H:%M:%S")
handler.setForm atter(fmt)
handler.setLeve l(loglevel)
logging.root.ad dHandler(handle r)

if consolelevel:
console = logging.StreamH andler()
formatter = logging.Formatt er('%(levelname )-8s %(message)s')
console.setForm atter(formatter )
console.setLeve l(clevel)
logging.root.ad dHandler(consol e)

logging.root.se tLevel(min(logl evel, clevel))
The configuration file contains a section such as:

[logging]
level=warning
filename=output \%(script)s.log
console=info

Jul 19 '05 #3

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

Similar topics

5
8000
by: Ravi Shankar | last post by:
Hi all, I have an enterprise application. I am using Apache Log4J for the logging purposes. WHen a request is received by the application, it goes throug servlets and many classes, and the necessary details are logged to files, which has autorate option. I mean when certain file exceeds the size, automatically another file is generated for a maximum of 10 files and then again starts from the first. So far is so good. Now assume that...
0
1680
by: Neil Benn | last post by:
Hello, I'm running a test and having issues with logging, if I call logging.shutdown() and then want to start the logging going again then I get a problem as if I call shutdown, I can't get the root logger again, such as : ..>>> import logging ..>>> objTestLogger = logging.getLogger() ..>>> objTestLogger.setLevel(logging.INFO)
6
10328
by: Burkhard Schultheis | last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is what is in db2diag.log during online backup: Starting a full database backup. 2004-04-01-02.33.54.760164 Instance:lzgneu Node:000 PID:1293(db2loggw (TELEMATX)) TID:1024 Appid:none data protection sqlpgwlp Probe:909 TailPage 0 does not match pagelsn 0023CEBF0FFB and firstlsn 0023CEBF8000
2
1745
by: johnm | last post by:
As a refresher, a description of my problem is in the message body below. I could not get answers to all of the questions that were asked below in a previous thread, but here is what I found out: 1. Number of LOB's inserted per hour and average size 2. Number of LOB's updated per hour and average size 3. Number of LOB's deleted per hour and average size 4. Rough estimate of the amount of non-LOB data inserted, updated, and deleted per...
3
2940
by: Karuppasamy | last post by:
Hi I am trying to use the Logging Module provided by Microsoft Application Blocks for .Net . I installed everything as per the Instructions given in the 'Development Using the Logging Block'. But when i am trying to run the sample, i am getting the following error in the Event Viwer. Kindly help me on this.
3
5411
by: nicholas.petrella | last post by:
I am currently trying to use the python logging system as a core enterprise level logging solution for our development and production environments. The rotating file handler seems to be what I am looking for as I want the ability to have control over the number and size of log files that are written out for each of our tools. I have noticed a few problems with this handler and wanted to post here to get your impressions and possibly...
3
11567
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 logging system will create a default logger that *also* emits logs, which I can't seem to get rid of. Is there a way I can suppress the creation of this default logger, or remove it when I 'm setting up my handlers? Thanks. Sample code:
3
7192
by: pundarikakshaiah | last post by:
Hi, I am using JDK1.4 logging framework and below are the properties that I have in my logging.properties file to configure logging.. handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler .level= INFO java.util.logging.ConsoleHandler.level=SEVERE java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter java.util.logging.FileHandler.level=INFO java.util.logging.FileHandler.pattern=%h/java%u.log...
3
2227
by: guybenron | last post by:
Hey, I have a sort of petty-neurotic question, I'm kinda pedantic and like to keep my log directories clean, and this thing is bothering me to the point of actually posting a question (couldn't find any post about this..). My application has two types of components: daemons and regular ones that are run every on crontab. Because the log structure is very similar, I want both to use the same logging configuration file.
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.