Changeset - efd088f7903b
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-07-31 21:53:59
mads@kiilerich.com
kallithea-cli: introduce generic custom logging configuration for each cli command

Command line commands have different needs for logging than the server process.

To enable that use case, allow config sections to be enabled (and thus augment
existing sections), depending on which kallithea-cli command is running.
1 file changed with 17 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_base.py
Show inline comments
 
@@ -13,8 +13,10 @@
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import click
 
import cStringIO
 
import functools
 
import os
 
import re
 
import sys
 

	
 
import kallithea
 
@@ -31,6 +33,19 @@ import paste.deploy
 
kallithea_cli_path = sys.argv[0]
 

	
 

	
 
def read_config(ini_file_name, strip_section_prefix):
 
    """Read ini_file_name content, and for all sections like '[X:Y]' where X is
 
    strip_section_prefix, replace the section name with '[Y]'."""
 

	
 
    def repl(m):
 
        if m.group(1) == strip_section_prefix:
 
            return '[%s]' % m.group(2)
 
        return m.group(0)
 

	
 
    with open(ini_file_name) as f:
 
        return re.sub(r'^\[([^:]+):(.*)]', repl, f.read(), flags=re.MULTILINE)
 

	
 

	
 
# This placeholder is the main entry point for the kallithea-cli command
 
@click.group(context_settings=dict(help_option_names=['-h', '--help']))
 
def cli():
 
@@ -55,7 +70,8 @@ def register_command(config_file=False, 
 
            def runtime_wrapper(config_file, *args, **kwargs):
 
                path_to_ini_file = os.path.realpath(config_file)
 
                kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
 
                logging.config.fileConfig(path_to_ini_file)
 
                config_bytes = read_config(path_to_ini_file, strip_section_prefix=annotated.__name__)
 
                logging.config.fileConfig(cStringIO.StringIO(config_bytes))
 
                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)
0 comments (0 inline, 0 general)