Create logger before help message
[kamaki] / kamaki / cli / __init__.py
index 1842da4..cf5653f 100644 (file)
@@ -241,6 +241,9 @@ def _init_session(arguments, is_non_API=False):
     _verbose = arguments['verbose'].value
     _cnf = arguments['config']
 
+    _silent = arguments['silent'].value
+    _setup_logging(_silent, _debug, _verbose, _include)
+
     if _help or is_non_API:
         return None, None
 
@@ -251,8 +254,6 @@ def _init_session(arguments, is_non_API=False):
     if not (stdout.isatty() and _colors == 'on'):
         from kamaki.cli.utils import remove_colors
         remove_colors()
-    _silent = arguments['silent'].value
-    _setup_logging(_silent, _debug, _verbose, _include)
 
     cloud = arguments['cloud'].value or _cnf.value.get(
         'global', 'default_cloud')
@@ -327,24 +328,25 @@ def _init_session(arguments, is_non_API=False):
 
 
 def _load_spec_module(spec, arguments, module):
+    global kloger
     if not spec:
         return None
     pkg = None
     for location in cmd_spec_locations:
         location += spec if location == '' else '.%s' % spec
         try:
+            kloger.debug('Import %s from %s' % ([module], location))
             pkg = __import__(location, fromlist=[module])
+            kloger.debug('\t...OK')
             return pkg
         except ImportError as ie:
+            kloger.debug('\t...Failed')
             continue
     if not pkg:
         msg = 'Loading command group %s failed: %s' % (spec, ie)
-        try:
-            kloger.debug(msg)
-        except AttributeError:
-            print msg
-            print 'HINT: use a text editor to remove all global.*_cli'
-            print '      settings from the configuration file'
+        msg += '\nHINT: use a text editor to remove all global.*_cli'
+        msg += '\n\tsettings from the configuration file'
+        kloger.debug(msg)
     return pkg