Mercurial > kallithea
changeset 8086:488b52cad890 stable
logging: always invoke fileConfig with '__file__' and 'here'
WSGI servers tend to provide '__file__' and 'here' as 'defaults' when invoking
fileConfig, so '%(here)s' string interpolation also can be used in logging
configuration.
Make sure we do the same when we initialize logging without using a WSGI server.
It is annoying to have to do this, and it will only in rare cases make any
difference ... but it seems like the best option.
Patch also modified by Mads Kiilerich.
author | Wolfgang Scherer <Wolfgang.Scherer@gmx.de> |
---|---|
date | Sun, 29 Dec 2019 17:35:13 +0100 |
parents | f9c55f700ad9 |
children | ba6418fde72f |
files | docs/setup.rst kallithea/alembic/env.py kallithea/bin/kallithea_cli_base.py kallithea/bin/kallithea_cli_iis.py |
diffstat | 4 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/setup.rst Mon Dec 30 00:03:19 2019 +0100 +++ b/docs/setup.rst Sun Dec 29 17:35:13 2019 +0100 @@ -562,7 +562,7 @@ ini = '/srv/kallithea/my.ini' from logging.config import fileConfig - fileConfig(ini) + fileConfig(ini, {'__file__': ini, 'here': '/srv/kallithea'}) from paste.deploy import loadapp application = loadapp('config:' + ini) @@ -578,7 +578,7 @@ ini = '/srv/kallithea/kallithea.ini' from logging.config import fileConfig - fileConfig(ini) + fileConfig(ini, {'__file__': ini, 'here': '/srv/kallithea'}) from paste.deploy import loadapp application = loadapp('config:' + ini)
--- a/kallithea/alembic/env.py Mon Dec 30 00:03:19 2019 +0100 +++ b/kallithea/alembic/env.py Sun Dec 29 17:35:13 2019 +0100 @@ -43,7 +43,9 @@ # stamping during "kallithea-cli db-create"), config_file_name is not available, # and loggers are assumed to already have been configured. if config.config_file_name: - fileConfig(config.config_file_name, disable_existing_loggers=False) + fileConfig(config.config_file_name, + {'__file__': config.config_file_name, 'here': os.path.dirname(config.config_file_name)}, + disable_existing_loggers=False) def include_in_autogeneration(object, name, type, reflected, compare_to):
--- a/kallithea/bin/kallithea_cli_base.py Mon Dec 30 00:03:19 2019 +0100 +++ b/kallithea/bin/kallithea_cli_base.py Sun Dec 29 17:35:13 2019 +0100 @@ -72,7 +72,8 @@ path_to_ini_file = os.path.realpath(config_file) kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file) config_bytes = read_config(path_to_ini_file, strip_section_prefix=annotated.__name__) - logging.config.fileConfig(cStringIO.StringIO(config_bytes)) + logging.config.fileConfig(cStringIO.StringIO(config_bytes), + {'__file__': path_to_ini_file, 'here': os.path.dirname(path_to_ini_file)}) if config_file_initialize_app: kallithea.config.middleware.make_app_without_logging(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf) kallithea.lib.utils.setup_cache_regions(kallithea.CONFIG)
--- a/kallithea/bin/kallithea_cli_iis.py Mon Dec 30 00:03:19 2019 +0100 +++ b/kallithea/bin/kallithea_cli_iis.py Sun Dec 29 17:35:13 2019 +0100 @@ -33,7 +33,8 @@ def __ExtensionFactory__(): from paste.deploy import loadapp from logging.config import fileConfig - fileConfig('%(inifile)s') + fileConfig('%(inifile)s', {'__file__': '%(inifile)s', 'here': '%(inifiledir)s'}) + application = loadapp('config:%(inifile)s') def app(environ, start_response): @@ -75,6 +76,7 @@ with open(dispatchfile, 'w') as f: f.write(dispath_py_template % { 'inifile': config_file_abs.replace('\\', '\\\\'), + 'inifiledir': os.path.dirname(config_file_abs).replace('\\', '\\\\'), 'virtualdir': virtualdir, })