[PATCH V2] [cubicweb-ctl] backport --debuglevel option of pyramid to all instance commands

Laurent Peuch cortex at worlddomination.be
Tue May 21 18:24:50 CEST 2019


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1558455411 -7200
#      Tue May 21 18:16:51 2019 +0200
# Node ID 90327a2c2bdb39a563c12664a53ce3029542fadc
# Parent  596d10a3ad9ae6fd5c456c3740cfd10274d942a1
[cubicweb-ctl] backport --debuglevel option of pyramid to all instance commands

diff --git a/cubicweb/cwctl.py b/cubicweb/cwctl.py
--- a/cubicweb/cwctl.py
+++ b/cubicweb/cwctl.py
@@ -41,10 +41,12 @@ from logilab.common.decorators import cl
 
 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS
+from cubicweb.server import set_debug
 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
 from cubicweb.__pkginfo__ import version as cw_version
 
 LOG_LEVELS = ('debug', 'info', 'warning', 'error')
+DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE')
 
 # don't check duplicated commands, it occurs when reloading site_cubicweb
 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
@@ -135,6 +137,13 @@ class InstanceCommand(Command):
                   % (', '.join(LOG_LEVELS)),
           }
          ),
+        ('debuglevel',
+         {'type': 'multiple_choice', 'metavar': '<debug level>',
+          'default': None,
+          'choices': DBG_FLAGS,
+          'help': ('Set the server debugging flags; you may choose several '
+                   'values in %s; imply "debug" loglevel' % (DBG_FLAGS,)),
+          }),
     )
     actionverb = None
 
@@ -145,6 +154,10 @@ class InstanceCommand(Command):
         appid = args[0]
         cmdmeth = getattr(self, '%s_instance' % self.name)
 
+        if self.config.debuglevel:
+            self.config.loglevel = "debug"
+            set_debug('|'.join('DBG_' + x.upper() for x in self.config.debuglevel))
+
         cwconfig = cwcfg.config_for(appid)
         if self.config.loglevel:
             init_cmdline_log_threshold(cwconfig, self.config.loglevel)
diff --git a/cubicweb/pyramid/pyramidctl.py b/cubicweb/pyramid/pyramidctl.py
--- a/cubicweb/pyramid/pyramidctl.py
+++ b/cubicweb/pyramid/pyramidctl.py
@@ -37,10 +37,10 @@ import warnings
 
 from cubicweb import ExecutionError
 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
-from cubicweb.cwctl import CWCTL, InstanceCommand, init_cmdline_log_threshold
+from cubicweb.cwctl import CWCTL, InstanceCommand
 from cubicweb.pyramid import wsgi_application_from_cwconfig
 from cubicweb.pyramid.config import get_random_secret_key
-from cubicweb.server import serverctl, set_debug
+from cubicweb.server import serverctl
 from cubicweb.web.webctl import WebCreateHandler
 from cubicweb.toolsutils import fill_templated_file
 
@@ -48,8 +48,6 @@ import waitress
 
 MAXFD = 1024
 
-DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE')
-
 
 def _generate_pyramid_ini_file(pyramid_ini_path):
     """Write a 'pyramid.ini' file into apphome."""
@@ -114,13 +112,6 @@ class PyramidStartHandler(InstanceComman
         ('reload-interval',
          {'type': 'int', 'default': 1,
           'help': 'Interval, in seconds, between file modifications checks'}),
-        ('dbglevel',
-         {'type': 'multiple_choice', 'metavar': '<dbg level>',
-          'default': None,
-          'choices': DBG_FLAGS,
-          'help': ('Set the server debugging flags; you may choose several '
-                   'values in %s; imply "debug" loglevel' % (DBG_FLAGS,)),
-          }),
         ('profile',
          {'action': 'store_true',
           'default': False,
@@ -359,11 +350,6 @@ class PyramidStartHandler(InstanceComman
             self.daemonize(cwconfig['pid-file'])
             self.record_pid(cwconfig['pid-file'])
 
-        if self['dbglevel']:
-            self['loglevel'] = 'debug'
-            set_debug('|'.join('DBG_' + x.upper() for x in self['dbglevel']))
-        init_cmdline_log_threshold(cwconfig, self['loglevel'])
-
         app = wsgi_application_from_cwconfig(
             cwconfig, profile=self['profile'],
             profile_output=self['profile-output'],
diff --git a/doc/changes/3.27.rst b/doc/changes/3.27.rst
--- a/doc/changes/3.27.rst
+++ b/doc/changes/3.27.rst
@@ -20,8 +20,8 @@ New features
 * add a --pdb flag to all cubicweb-ctl command to launch (i)pdb if an exception
   occurs during a command execution.
 
-* the --loglevel flag is available for all cubicweb-ctl instance commands (and
-  not only the "pyramid" one)
+* the --loglevel and --debuglevel flags are available for all cubicweb-ctl
+  instance commands (and not only the "pyramid" one)
 
 Backwards incompatible changes
 ------------------------------



More information about the cubicweb-devel mailing list