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
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
Comment