add logging
This commit is contained in:
parent
bd9dbb12b7
commit
8888f5d9f7
3 changed files with 57 additions and 28 deletions
|
|
@ -11,17 +11,7 @@ from uncloud.common import settings
|
|||
from uncloud import UncloudException
|
||||
from uncloud.common.cli import resolve_otp_credentials
|
||||
|
||||
|
||||
def exception_hook(exc_type, exc_value, exc_traceback):
|
||||
logging.getLogger(__name__).error(
|
||||
'Uncaught exception',
|
||||
exc_info=(exc_type, exc_value, exc_traceback)
|
||||
)
|
||||
|
||||
|
||||
sys.excepthook = exception_hook
|
||||
|
||||
# the components that use etcd
|
||||
# Components that use etcd
|
||||
ETCD_COMPONENTS = ['api', 'scheduler', 'host', 'filescanner',
|
||||
'imagescanner', 'metadata', 'configure', 'hack']
|
||||
|
||||
|
|
@ -30,10 +20,6 @@ ALL_COMPONENTS = ETCD_COMPONENTS.copy()
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Setting up root logger
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
subparsers = arg_parser.add_subparsers(dest='command')
|
||||
|
||||
|
|
@ -84,11 +70,18 @@ if __name__ == '__main__':
|
|||
mod = importlib.import_module('uncloud.{}.main'.format(name))
|
||||
main = getattr(mod, 'main')
|
||||
|
||||
if arguments['debug']:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
try:
|
||||
main(arguments)
|
||||
except UncloudException as err:
|
||||
logger.error(err)
|
||||
log.error(err)
|
||||
# except ConnectionFailedError as err:
|
||||
# logger.error('Cannot connect to etcd: {}'.format(err))
|
||||
# log.error('Cannot connect to etcd: {}'.format(err))
|
||||
except Exception as err:
|
||||
logger.exception(err)
|
||||
log.exception(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue