# HG changeset patch # User Laurent Peuch # Date 1558454897 -7200 # Node ID 5add82b08a6df4361cd453ebabd04f69dda86a3e # Parent 17d1b1f4eddd19f4a1f6bf9fafae7d3581528459 [cubicweb-ctl] backport --loglevel option of pyramid to all instance commands diff -r 17d1b1f4eddd -r 5add82b08a6d cubicweb/cwctl.py --- a/cubicweb/cwctl.py Thu Jul 25 03:33:01 2019 +0200 +++ b/cubicweb/cwctl.py Tue May 21 18:08:17 2019 +0200 @@ -45,6 +45,8 @@ from cubicweb.toolsutils import Command, rm, create_dir, underline_title from cubicweb.__pkginfo__ import version as cw_version +LOG_LEVELS = ('debug', 'info', 'warning', 'error') + # don't check duplicated commands, it occurs when reloading site_cubicweb CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', version=cw_version, check_duplicated_command=False) @@ -127,6 +129,13 @@ 'help': 'launch pdb on exception', } ), + ("loglevel", + {'type': 'choice', 'default': None, 'metavar': '', + 'choices': LOG_LEVELS, 'short': 'l', + 'help': 'allow to specify log level for debugging (choices: %s)' + % (', '.join(LOG_LEVELS)), + } + ), ) actionverb = None @@ -139,6 +148,19 @@ traceback_ = None + # debugmode=True is to force to have a StreamHandler used instead of + # writting the logs into a file in /tmp + self.cwconfig = cwcfg.config_for(appid, debugmode=True) + + # by default loglevel is 'error' but we keep the default value to None + # because some subcommands (e.g: pyramid) can override the loglevel in + # certain situations if it's not explicitly set by the user and we want + # to detect that (the "None" case) + if self['loglevel'] is None: + init_cmdline_log_threshold(self.cwconfig, 'error') + else: + init_cmdline_log_threshold(self.cwconfig, self['loglevel']) + try: status = cmdmeth(appid) or 0 except (ExecutionError, ConfigurationError) as ex: @@ -433,7 +455,6 @@ name = 'delete' arguments = '' min_args = max_args = 1 - options = () def run(self, args): """run the command with its specific arguments""" @@ -608,7 +629,7 @@ name = 'versions' def versions_instance(self, appid): - config = cwcfg.config_for(appid) + config = self.cwconfig # should not raise error if db versions don't match fs versions config.repairing = True # no need to load all appobjects and schema @@ -640,7 +661,7 @@ arguments = ' [batch command file(s)] [--