40 from logilab.common.configuration import merge_options |
40 from logilab.common.configuration import merge_options |
41 from logilab.common.decorators import clear_cache |
41 from logilab.common.decorators import clear_cache |
42 |
42 |
43 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
43 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
44 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS |
44 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS |
|
45 from cubicweb.server import set_debug |
45 from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
46 from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
46 from cubicweb.__pkginfo__ import version as cw_version |
47 from cubicweb.__pkginfo__ import version as cw_version |
47 |
48 |
48 LOG_LEVELS = ('debug', 'info', 'warning', 'error') |
49 LOG_LEVELS = ('debug', 'info', 'warning', 'error') |
|
50 DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE') |
49 |
51 |
50 # don't check duplicated commands, it occurs when reloading site_cubicweb |
52 # don't check duplicated commands, it occurs when reloading site_cubicweb |
51 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
53 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
52 version=cw_version, check_duplicated_command=False) |
54 version=cw_version, check_duplicated_command=False) |
53 |
55 |
134 'choices': LOG_LEVELS, 'short': 'l', |
136 'choices': LOG_LEVELS, 'short': 'l', |
135 'help': 'allow to specify log level for debugging (choices: %s)' |
137 'help': 'allow to specify log level for debugging (choices: %s)' |
136 % (', '.join(LOG_LEVELS)), |
138 % (', '.join(LOG_LEVELS)), |
137 } |
139 } |
138 ), |
140 ), |
|
141 ('dbglevel', |
|
142 {'type': 'multiple_choice', 'metavar': '<debug level>', |
|
143 'default': None, |
|
144 'choices': DBG_FLAGS, |
|
145 'help': ('Set the server debugging flags; you may choose several ' |
|
146 'values in %s; imply "debug" loglevel if loglevel is not set' % (DBG_FLAGS,)), |
|
147 }), |
139 ) |
148 ) |
140 actionverb = None |
149 actionverb = None |
141 |
150 |
142 def run(self, args): |
151 def run(self, args): |
143 """run the <command>_method on each argument (a list of instance |
152 """run the <command>_method on each argument (a list of instance |
155 # by default loglevel is 'error' but we keep the default value to None |
164 # by default loglevel is 'error' but we keep the default value to None |
156 # because some subcommands (e.g: pyramid) can override the loglevel in |
165 # because some subcommands (e.g: pyramid) can override the loglevel in |
157 # certain situations if it's not explicitly set by the user and we want |
166 # certain situations if it's not explicitly set by the user and we want |
158 # to detect that (the "None" case) |
167 # to detect that (the "None" case) |
159 if self['loglevel'] is None: |
168 if self['loglevel'] is None: |
160 init_cmdline_log_threshold(self.cwconfig, 'error') |
169 # if no loglevel is set but dbglevel is here we want to set level to debug |
|
170 if self['dbglevel']: |
|
171 init_cmdline_log_threshold(self.cwconfig, 'debug') |
|
172 else: |
|
173 init_cmdline_log_threshold(self.cwconfig, 'error') |
161 else: |
174 else: |
162 init_cmdline_log_threshold(self.cwconfig, self['loglevel']) |
175 init_cmdline_log_threshold(self.cwconfig, self['loglevel']) |
|
176 |
|
177 if self['dbglevel']: |
|
178 set_debug('|'.join('DBG_' + x.upper() for x in self['dbglevel'])) |
163 |
179 |
164 try: |
180 try: |
165 status = cmdmeth(appid) or 0 |
181 status = cmdmeth(appid) or 0 |
166 except (ExecutionError, ConfigurationError) as ex: |
182 except (ExecutionError, ConfigurationError) as ex: |
167 # we need to do extract this information here for pdb since it is |
183 # we need to do extract this information here for pdb since it is |