Pavel Paulau
Pavel Paulau

Reputation: 816

How to distribute logging config with Python package

Adding config file to package is not a big deal. But when I upload package to pypi and install it, it's not possible to read logging config:

logging.config.fileConfig('logging.conf')

basically my modules don't find it because file is not in current working directory anymore. How can I address that?

Upvotes: 3

Views: 304

Answers (1)

unutbu
unutbu

Reputation: 879621

If logging.conf exists in the same directory as the file calling logging.config.fileConfig, then you could use:

import os
logconf_file = os.path.join(os.path.dirname(__file__), 'logging.conf')
logging.config.fileConfig(logconf_file)

Upvotes: 3

Related Questions