[PATCH 4 of 4 V2] [debug] add DBG_TRANSACTIONS flag and hide transactions debug by default

Laurent Peuch cortex at worlddomination.be
Wed Jul 24 16:47:07 CEST 2019


On Wed, Jul 24, 2019 at 04:29:32PM +0200, Laurent Peuch wrote:
> # HG changeset patch
> # User Laurent Peuch <cortex at worlddomination.be>
> # Date 1563975648 -7200
> #      Wed Jul 24 15:40:48 2019 +0200
> # Node ID fbb8731f84b73899f4c84564b7b845f30cbe8ab8
> # Parent  e771d38b4a511798ba21dd17c23c3b32b88e2259
> # EXP-Topic improve-cli
> [debug] add DBG_TRANSACTIONS flag and hide transactions debug by default
> 
> CW debug output log is very verbose and most information is not always useful
> in all situation. This new flag is an attempt to make logs more useful by
> default while not preventing from adding this additional information when
> needed.

I took this opportunity to do this modification I wanted to do since a
long time in the continuation of work of making CW easier to use and
debug and thus clean a bit the output to highlight more relevant
information.

> diff --git a/cubicweb/cwctl.py b/cubicweb/cwctl.py
> --- a/cubicweb/cwctl.py
> +++ b/cubicweb/cwctl.py
> @@ -46,7 +46,7 @@ from cubicweb.toolsutils import Command,
>  from cubicweb.__pkginfo__ import version as cw_version
>  
>  LOG_LEVELS = ('debug', 'info', 'warning', 'error')
> -DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE')
> +DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'TRANSACTIONS', 'HOOKS', 'OPS', 'SEC', 'MORE')
>  
>  # don't check duplicated commands, it occurs when reloading site_cubicweb
>  CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
> diff --git a/cubicweb/server/__init__.py b/cubicweb/server/__init__.py
> --- a/cubicweb/server/__init__.py
> +++ b/cubicweb/server/__init__.py
> @@ -63,6 +63,8 @@ DBG_RQL = 1
>  DBG_SQL = 2
>  #: repository events
>  DBG_REPO = 4
> +#: db transactions
> +DBG_TRANSACTIONS = 8
>  #: hooks
>  DBG_HOOKS = 16
>  #: operations
> @@ -72,7 +74,7 @@ DBG_SEC = 64
>  #: more verbosity
>  DBG_MORE = 128
>  #: all level enabled
> -DBG_ALL = DBG_RQL + DBG_SQL + DBG_REPO + DBG_HOOKS + DBG_OPS + DBG_SEC + DBG_MORE
> +DBG_ALL = DBG_RQL + DBG_SQL + DBG_REPO + DBG_TRANSACTIONS + DBG_HOOKS + DBG_OPS + DBG_SEC + DBG_MORE
>  
>  _SECURITY_ITEMS = []
>  _SECURITY_CAPS = ['read', 'add', 'update', 'delete', 'transition']
> diff --git a/cubicweb/server/session.py b/cubicweb/server/session.py
> --- a/cubicweb/server/session.py
> +++ b/cubicweb/server/session.py
> @@ -686,7 +686,8 @@ class Connection(RequestSessionBase):
>                          self.critical('rollback error', exc_info=sys.exc_info())
>                          continue
>                  cnxset.rollback()
> -                self.debug('rollback for transaction %s done', self)
> +                if server.DEBUG & server.DBG_TRANSACTIONS:
> +                    self.debug('rollback for transaction %s done', self)
>          finally:
>              self.clear()
>  
> @@ -726,7 +727,8 @@ class Connection(RequestSessionBase):
>                                  print(operation)
>                              operation.handle_event('precommit_event')
>                      self.pending_operations[:] = processed
> -                    self.debug('precommit transaction %s done', self)
> +                    if server.DEBUG & server.DBG_TRANSACTIONS:
> +                        self.debug('precommit transaction %s done', self)
>                  except BaseException:
>                      # if error on [pre]commit:
>                      #
> @@ -772,7 +774,8 @@ class Connection(RequestSessionBase):
>                                  raise
>                              self.critical('error while postcommit',
>                                            exc_info=sys.exc_info())
> -                self.debug('postcommit transaction %s done', self)
> +                if server.DEBUG & server.DBG_TRANSACTIONS:
> +                    self.debug('postcommit transaction %s done', self)
>                  return self.transaction_uuid(set=False)
>          finally:
>              self.clear()
> diff --git a/cubicweb/test/unittest_cwctl.py b/cubicweb/test/unittest_cwctl.py
> --- a/cubicweb/test/unittest_cwctl.py
> +++ b/cubicweb/test/unittest_cwctl.py
> @@ -180,7 +180,7 @@ class InstanceCommandTest(unittest.TestC
>  
>      @patch.object(server, "DEBUG", 0)
>      def test_set_dblevel(self):
> -        DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE')
> +        DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'TRANSACTIONS', 'HOOKS', 'OPS', 'SEC', 'MORE')
>  
>          total_value = 0
>  
> diff --git a/doc/book/annexes/rql/debugging.rst b/doc/book/annexes/rql/debugging.rst
> --- a/doc/book/annexes/rql/debugging.rst
> +++ b/doc/book/annexes/rql/debugging.rst
> @@ -14,6 +14,7 @@ Server debugging flags. They may be comb
>  .. autodata:: cubicweb.server.DBG_RQL
>  .. autodata:: cubicweb.server.DBG_SQL
>  .. autodata:: cubicweb.server.DBG_REPO
> +.. autodata:: cubicweb.server.DBG_TRANSACTIONS
>  .. autodata:: cubicweb.server.DBG_HOOKS
>  .. autodata:: cubicweb.server.DBG_OPS
>  .. autodata:: cubicweb.server.DBG_MORE
> 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
> @@ -51,6 +51,11 @@ Backwards incompatible changes
>  
>  * DBG_MS flag has been removed since it is not used anymore
>  
> +* hide "precommit/postcommit/rollback for transaction" logs by default, to
> +  re-enable them use the "TRANSACTIONS" flag either with --dbglevel CLI
> +  argument or following this documentation
> +  https://cubicweb.readthedocs.io/en/default/book/annexes/rql/debugging/
> +
>  Deprecated code drops
>  ---------------------
>  

-- 

Laurent Peuch -- Bram



More information about the cubicweb-devel mailing list