Browse Source

[MP2P] Still log to stdout when logfile is specified

A previous commit made logging to stdout alternative to logging
to a file. This patch restores stdout logging.
It also ensures the formatter is applied to the root logger for
consistent output.

Change-Id: Ie479006c865e823484aa7b71fea29356e22cf7cd
changes/03/789003/1
Salvatore 2 weeks ago
committed by Salvatore Orlando
parent
commit
b8093c882f
1 changed files with 8 additions and 9 deletions
  1. +8
    -9
      vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py

+ 8
- 9
vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py View File

@ -1669,27 +1669,26 @@ def MP2Policy_migration(resource, event, trigger, **kwargs):
LOG.setLevel(logging.DEBUG)
else:
LOG.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
root_logger = logging.getLogger(None)
start_migration_service = False
handler = logging.StreamHandler()
if kwargs.get('property'):
properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])
logfile = properties.get('logfile', None)
if logfile:
handler = logging.FileHandler(logfile)
root_logger.addHandler(handler)
start_service_flag = properties.get('start-migration-service', 'False')
if start_service_flag.lower() == 'true':
start_migration_service = True
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
LOG.addHandler(handler)
# Remove handler from root logger to avoid duplication
root_logger = logging.getLogger(None)
for root_handler in root_logger.handlers[:]:
root_logger.removeHandler(root_handler)
# Apply formatter to every handler
handlers = root_logger.handlers
for handler in handlers:
handler.setFormatter(formatter)
nsxlib = _get_nsxlib_from_config(verbose)
nsxpolicy = p_utils.get_connected_nsxpolicy(
conf_path=cfg.CONF.nsx_v3, verbose=verbose)


Loading…
Cancel
Save