diff options
author | Sridhar Rao <sridhar.rao@spirent.com> | 2018-08-22 14:48:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-08-22 14:48:47 +0000 |
commit | 01724ca5eb6198cd0d9bf804e1c7972b2b1edf09 (patch) | |
tree | 3ed06297cc44b55bf54964975db8aacdf90da420 /vsperf | |
parent | 65f40a88070baaa58d999cfb358a81befe6b8cc9 (diff) | |
parent | b9f0a63e2a1d9b94f401f9fc31ff47dc739fa967 (diff) |
Merge "Logging: Enhance logging with separate files and timestamps"
Diffstat (limited to 'vsperf')
-rwxr-xr-x | vsperf | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -235,13 +235,22 @@ def parse_arguments(): def configure_logging(level): """Configure logging. """ + date = datetime.datetime.fromtimestamp(time.time()) + timestamp = date.strftime('%Y-%m-%d_%H-%M-%S') + settings.setValue('LOG_TIMEMSTAMP', timestamp) + name, ext = os.path.splitext(settings.getValue('LOG_FILE_DEFAULT')) + rename_default = "{name}_{uid}{ex}".format(name=name, uid=timestamp, ex=ext) log_file_default = os.path.join( - settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_DEFAULT')) + settings.getValue('LOG_DIR'), rename_default) log_file_host_cmds = os.path.join( settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_HOST_CMDS')) log_file_traffic_gen = os.path.join( settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_TRAFFIC_GEN')) + metrics_file = (settings.getValue('LOG_FILE_INFRA_METRICS_PFX') + + timestamp + '.log') + log_file_infra_metrics = os.path.join(settings.getValue('LOG_DIR'), + metrics_file) _LOGGER.setLevel(logging.DEBUG) @@ -253,6 +262,8 @@ def configure_logging(level): file_logger = logging.FileHandler(filename=log_file_default) file_logger.setLevel(logging.DEBUG) + file_logger.setFormatter(logging.Formatter( + '%(asctime)s : %(message)s')) _LOGGER.addHandler(file_logger) class CommandFilter(logging.Filter): @@ -265,6 +276,11 @@ def configure_logging(level): def filter(self, record): return record.getMessage().startswith(trafficgen.CMD_PREFIX) + class CollectdMetricsFilter(logging.Filter): + """Filter out strings beginning with 'COLLECTD' :'""" + def filter(self, record): + return record.getMessage().startswith('COLLECTD') + cmd_logger = logging.FileHandler(filename=log_file_host_cmds) cmd_logger.setLevel(logging.DEBUG) cmd_logger.addFilter(CommandFilter()) @@ -275,6 +291,12 @@ def configure_logging(level): gen_logger.addFilter(TrafficGenCommandFilter()) _LOGGER.addHandler(gen_logger) + if settings.getValue('COLLECTOR') == 'Collectd': + met_logger = logging.FileHandler(filename=log_file_infra_metrics) + met_logger.setLevel(logging.DEBUG) + met_logger.addFilter(CollectdMetricsFilter()) + _LOGGER.addHandler(met_logger) + def apply_filter(tests, tc_filter): """Allow a subset of tests to be conveniently selected |