logging.fileConfig limitations?

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Jun 18 18:15:12 CEST 2009


On Jun 17, 9:05 pm, Mani Ghasemlou <m... at tungle.com> wrote:
> Hi all,
>
> C:\Documents and Settings\ßéäöÜ2\Local Settings\Application Data\MyApp\MyApp.log
>
> Now it turns out that the logging module can't find "C:/Documents and
> Settings/ßéäöÜ2/Local Settings/Application Data/MyApp/MyApp.log"
> specified in the "args" section, and rightfully so because this is an
> encoded string. *There does not seem to be a way for me to specify the
> encoding of the string so that the logging module resolves the proper
> unicode path.* This is my key problem!
>
> Is there some way to accomplish what I want?
>

No need to poke about in the source. Here's my script:

#-- log_ufn.py --
import logging.config

logging.config.fileConfig("log_ufn.ini")
logging.error("Holy Cow, Batman!")

and here's my configuration file, adapted from yours:

#-- log_ufn.ini --
[formatters]
keys: normal

[handlers]
keys: rotatingfile

[loggers]
keys: root

[formatter_normal]
format: %(asctime)s %(levelname)s %(module)s: %(message)s

[logger_root]
level: DEBUG
handlers: rotatingfile

[handler_rotatingfile]
class: handlers.RotatingFileHandler
formatter: normal
args: (u"C:/Temp/\u00DF\u00E9\u00E4\u00F6\u00DC2/MyApp.log", "a",
2*1024*1024, 5, None)

Note that I specified a Unicode filename, with Unicode escapes for
ßéäöÜ2.

After I run the script (using ActivePython 2.5.2.2), I get the
following output:

# -- Contents of C:\temp\ßéäöÜ2\MyApp.log --
2009-06-18 17:07:30,493 ERROR log_ufn: Holy Cow, Batman!

Which seems to be what one would expect.



More information about the Python-list mailing list