[serverctl] allow changing the log level for source-sync command
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 19 Jun 2015 16:38:53 +0200
changeset 10400 383a5e629145
parent 10399 5234525560ac
child 10401 4f41eb2f06bc
[serverctl] allow changing the log level for source-sync command When calling this from cron we only want to see output if something fails.
server/serverctl.py
--- a/server/serverctl.py	Thu Apr 30 13:06:45 2015 +0200
+++ b/server/serverctl.py	Fri Jun 19 16:38:53 2015 +0200
@@ -1076,13 +1076,19 @@
     name = 'source-sync'
     arguments = '<instance> <source>'
     min_args = max_args = 2
+    options = (
+            ('loglevel',
+             {'short': 'l', 'type' : 'choice', 'metavar': '<log level>',
+              'default': 'info', 'choices': ('debug', 'info', 'warning', 'error'),
+             }),
+    )
 
     def run(self, args):
+        from cubicweb.cwctl import init_cmdline_log_threshold
         config = ServerConfiguration.config_for(args[0])
         config.global_set_option('log-file', None)
         config.log_format = '%(levelname)s %(name)s: %(message)s'
-        logger = logging.getLogger('cubicweb.sources')
-        logger.setLevel(logging.INFO)
+        init_cmdline_log_threshold(config, self['loglevel'])
         # only retrieve cnx to trigger authentication, close it right away
         repo, cnx = repo_cnx(config)
         cnx.close()