473,769 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RotatingFileHan dler and logging config file

Hello,

I've successfully coded Python to do what I want with a
RotatingFileHan dler, but am having trouble getting the same behavior via
a config file.

I wanted to create one log file each time I run my app, with up to 10
files kept from the last invocations. This was accomplished with

self._logger = logging.getLogg er('PDGUI')
# We will rotate the files 'manually', so use zero rotate size.
handler = logging.handler s.RotatingFileH andler( \
"..\\PDGUI.log" , "a", 0, 10)
handler.doRollo ver() # force the next file to be used

formatter = logging.Formatt er("%(asctime) s " + \
"%(levelname)s\ t%(message)s")
handler.setForm atter(formatter )
self._logger.ad dHandler(handle r)
self._logger.se tLevel(logging. INFO)

I'd like to do the same thing with a config file (so that, if this
*isn't* the behavior I want, I can change the config file, of course).
I started with a rather plain config file, with the only interesting bit
being:

[handler_hand01]
class=handlers. RotatingFileHan dler
level=NOTSET
formatter=form0 1
args=("..\\PDGU I.log", "a", 0, 10,)
But I still have one problem - how do I force the "handler.doRoll over()"
to happen with the config file? There doesn't seem to be any way to do
this in the config file itself, which is OK and perhaps appropriate
[BTW, has anyone else noticed that RotatingFileHan dler isn't documented
in the docs? All the other file handlers have at least a paragraph on
their options, but nothing for RFH!]

I can't find any way to do the handler.doRollo ver() in code, either, if
I've started off with a config file. Something like
logging.config. fileConfig(opti ons.logconfig)

# BUGBUG If the config file specifies a RotatingFileHan dler,
# we need to force a doRollover now, but there's no way!
#
handler = logging.getLogg er().getHandler () # THIS DOESN'T EXIST!
handler.doRollo ver() # force the next file to be used
Ideas, suggestions, etc? It's too bad - with the code method, I can do
exactly what I want, but not with the config file.

- rob

Jul 18 '05 #1
12 12730
Rob Cranfill wrote:
[BTW, has anyone else noticed that RotatingFileHan dler isn't documented
in the docs? All the other file handlers have at least a paragraph on
their options, but nothing for RFH!]


It is in the latest docs.

Kent
Jul 18 '05 #2
Kent Johnson wrote:

It is in the latest docs.

Kent


No, it isn't. (But thanks for replying anyway!)

http://docs.python.org/lib/logging-c...ileformat.html

has all the others (OK, maybe not all, I haven't thoroughly checked, but
it's got nine of 'em) but nothing for RFH.

Or is that not "the latest docs"?

- rob
Jul 18 '05 #3
Rob Cranfill wrote:
Kent Johnson wrote:
It is in the latest docs.
No, it isn't. (But thanks for replying anyway!)


Can you prove it isn't? ;-)
http://docs.python.org/lib/logging-c...ileformat.html

has all the others (OK, maybe not all, I haven't thoroughly checked, but
it's got nine of 'em) but nothing for RFH.

Or is that not "the latest docs"?


Sure, but it's not the only place to look in the current docs.
Try here instead: http://docs.python.org/lib/node332.html

The missing piece of the puzzle might be the connection
between the 'args' in the config file and the arguments
passed to the __init__ method of the class....

-Peter
Jul 18 '05 #4
Rob Cranfill wrote:
Kent Johnson wrote:

It is in the latest docs.

Kent

No, it isn't. (But thanks for replying anyway!)

http://docs.python.org/lib/logging-c...ileformat.html


You're looking in the wrong place. Try

http://docs.python.org/lib/node333.html

Huy
Jul 18 '05 #5
news.sydney.pip enetworks.com wrote:

You're looking in the wrong place. Try

http://docs.python.org/lib/node333.html


which isn't quite the page in question, but leads to the closest
pertinent page,
http://docs.python.org/lib/logging-c...ileformat.html
which *still* has nothing on RotatingFileHan dler.

That's OK, I've given up on the idea of being able to configure a
RotatingFileHan dler from a config file; I'll do it in my code as a
default, and if users want any *other* behavior, they can config *that*.

- rob

Jul 18 '05 #6
Peter Hansen wrote:
The missing piece of the puzzle might be the connection
between the 'args' in the config file and the arguments
passed to the __init__ method of the class....


Yes, I can puzzle out the constructor args ("constructo r", heh heh, must
be a Java Man) but it's how to get it to do a doRollover() that's in
question. No sign of support for it in the docs (which your link to
doesn't elucidate RotatingFileHan dler any better than my original) but
that's OK, see my following message to <ny*****@swiftd sl.com.au> (what a
funny name!)

- rob
Jul 18 '05 #7
On Wed, 16 Mar 2005 20:48:40 -0800, Rob Cranfill <ro*********@co mcast.dot.net> wrote:
news.sydney.pi penetworks.com wrote:

You're looking in the wrong place. Try

http://docs.python.org/lib/node333.html


which isn't quite the page in question, but leads to the closest
pertinent page,
http://docs.python.org/lib/logging-c...ileformat.html
which *still* has nothing on RotatingFileHan dler.

That's OK, I've given up on the idea of being able to configure a
RotatingFileHa ndler from a config file; I'll do it in my code as a
default, and if users want any *other* behavior, they can config *that*.

To fish for yourself, go to google and put

RotatingFileHan dler site:docs.pytho n.org

in the search slot and click search.

The first hit is
http://docs.python.org/lib/node332.html

HTH

Regards,
Bengt Richter
Jul 18 '05 #8
Rob Cranfill wrote:
news.sydney.pip enetworks.com wrote:

You're looking in the wrong place. Try

http://docs.python.org/lib/node333.html


which isn't quite the page in question, but leads to the closest
pertinent page,
http://docs.python.org/lib/logging-c...ileformat.html
which *still* has nothing on RotatingFileHan dler.


Yeah...sorry about that. I misunderstood what node333.html was used for.
Looks like your best bet may be to extend the RotatingFileHan dler
directly in the handlers module and call doRollover() in __init__.

Huy
Jul 18 '05 #9
Bengt Richter wrote:
The first hit is
http://docs.python.org/lib/node332.html
HTH


NID (No, It Doesn't) ;-) but thanks anyway. To reiterate, the question
is how to make RotatingFileHan dler do a doRotate() on startup from a
*config file*. No mention of that in what you point to.

- rob
Jul 18 '05 #10

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

Similar topics

5
2936
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know the name of this is set in machine.config. I was hoping it would be possible to change this in web.config. I got it to work, kind of. Good news is I can change the name in my web.config file. Bad news is that trace.axd still works meaning I can...
1
2016
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 file passed to fileConfig. However, I run into problems... 1) It seems that I cannot refer to something from previously loaded
1
3647
by: Kenneth Love | last post by:
I have a Python logging config file that contains a RotatingFileHandler handler. In the args key, I have hard-coded the log filename. Everything works great. However, I find that I now need to override this filename at application runtime. Is there a good way to do this? Here is a bit of sample code that (hopefully) clarifies my question. --------------- log.ini -----------------
4
3332
by: Frank Aune | last post by:
Hello, I've been playing with the python logging module lately, and I manage to log to both stderr and MySQL database. What I'm wondering, is if its possible to specify the database handler in a config file like: class=DBHandler
1
2105
by: Matthew Wilson | last post by:
The python logging module is a beautiful masterpiece. I'm studying filters and the config-file approach. Is it possible to define a filter somehow and then refer to it in my config file? TIA Matt
3
2225
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.
3
6423
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the logging.config.fileConfig() function. Let say my logging class is called "MyLogHandler" and it's in a module called "mylogmodule", I want to be able to make an entry something like this in my logging config file:
4
2364
by: Matthew Wilson | last post by:
I'm working on a package that uses the standard library logging module along with a .cfg file. In my code, I use logging.config.fileConfig('/home/matt/mypackage/matt.cfg') to load in the logging config file. However, it seems really obvious to me that this won't work when I share this package with others.
1
2883
by: GR M | last post by:
Hi.. I want to write the connection string of my application in app.config file. I dont know how to write it or how to dynamically change it from my application source code either. My App.config file shows like.. <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <sources> <!-- This section defines the logging configuration for My.Application.Log --> <source...
0
9586
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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
10210
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
9861
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
6672
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
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.