aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahothan <ahothan@cisco.com>2017-08-15 15:52:12 -0700
committerahothan <ahothan@cisco.com>2017-08-15 15:52:12 -0700
commit4c5e4ba753face81fd73aa3bae1fe3c012e48859 (patch)
tree7c13bb498a7eb89e1b9a5debaba877e483358aab
parentee54ef3cc13c0633f664264dfb450f3d2fab13bc (diff)
NFVBENCH-4 Add support for log file
Change-Id: Id630944944d472322a763fe41ccb0e1ed9fb3066 Signed-off-by: ahothan <ahothan@cisco.com>
-rw-r--r--nfvbench/cfg.default.yaml4
-rw-r--r--nfvbench/log.py24
-rw-r--r--nfvbench/nfvbench.py19
3 files changed, 34 insertions, 13 deletions
diff --git a/nfvbench/cfg.default.yaml b/nfvbench/cfg.default.yaml
index ed6ead8..dba7670 100644
--- a/nfvbench/cfg.default.yaml
+++ b/nfvbench/cfg.default.yaml
@@ -365,6 +365,10 @@ std_json:
# Can be overriden by --debug
debug: false
+# Set to a valid path name if logging to file is to be enabled
+# Defaults to disabled
+log_file:
+
# Module and class name of factory which will be used to provide classes dynamically for other components.
factory_module: 'nfvbench.factory'
factory_class: 'BasicFactory'
diff --git a/nfvbench/log.py b/nfvbench/log.py
index 22afefe..f308171 100644
--- a/nfvbench/log.py
+++ b/nfvbench/log.py
@@ -14,27 +14,33 @@
import logging
+_product_name = 'nfvbench'
-def setup(product_name):
+def setup():
# logging.basicConfig()
formatter_str = '%(asctime)s %(levelname)s %(message)s'
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(formatter_str))
# Add handler to logger
- logger = logging.getLogger(product_name)
+ logger = logging.getLogger(_product_name)
logger.addHandler(handler)
+def add_file_logger(logfile):
+ if logfile:
+ file_formatter_str = '%(asctime)s %(levelname)s %(message)s'
+ file_handler = logging.FileHandler(logfile, mode='w')
+ file_handler.setFormatter(logging.Formatter(file_formatter_str))
+ logger = logging.getLogger(_product_name)
+ logger.addHandler(file_handler)
-def set_level(product, debug=False):
+def set_level(debug=False):
log_level = logging.DEBUG if debug else logging.INFO
- logger = logging.getLogger(product)
+ logger = logging.getLogger(_product_name)
logger.setLevel(log_level)
-
-def getLogger(product):
- logger = logging.getLogger(product)
-
+def getLogger():
+ logger = logging.getLogger(_product_name)
return logger
-LOG = getLogger('nfvbench')
+LOG = getLogger()
diff --git a/nfvbench/nfvbench.py b/nfvbench/nfvbench.py
index 5b7eb91..a4f9ead 100644
--- a/nfvbench/nfvbench.py
+++ b/nfvbench/nfvbench.py
@@ -121,8 +121,8 @@ class NFVBench(object):
def print_summary(self, result):
"""Print summary of the result"""
- print NFVBenchSummarizer(result)
- sys.stdout.flush()
+ summary = NFVBenchSummarizer(result)
+ LOG.info(str(summary))
def save(self, result):
"""Save results in json format file."""
@@ -365,6 +365,11 @@ def parse_opts_from_cli():
default=None,
help='Override traffic profile direction (requires -fs)')
+ parser.add_argument('--log-file', '--logfile', dest='log_file',
+ action='store',
+ help='Filename for saving logs',
+ metavar='<log_file>')
+
opts, unknown_opts = parser.parse_known_args()
return opts, unknown_opts
@@ -406,7 +411,7 @@ def check_physnet(name, netattrs):
def main():
try:
- log.setup('nfvbench')
+ log.setup()
# load default config file
config, default_cfg = load_default_config()
# create factory for platform specific classes
@@ -422,7 +427,7 @@ def main():
openstack_spec = config_plugin.get_openstack_spec()
opts, unknown_opts = parse_opts_from_cli()
- log.set_level('nfvbench', debug=opts.debug)
+ log.set_level(debug=opts.debug)
if opts.version:
print pbr.version.VersionInfo('nfvbench').version_string_with_vcs()
@@ -457,6 +462,8 @@ def main():
config.generator_profile = opts.generator_profile
if opts.sriov:
config.sriov = True
+ if opts.log_file:
+ config.log_file = opts.log_file
# show running config in json format
if opts.show_config:
@@ -475,6 +482,10 @@ def main():
# in a copy of the dict (config plugin still holds the original dict)
config_plugin.set_config(config)
+ # add file log if requested
+ if config.log_file:
+ log.add_file_logger(config.log_file)
+
nfvbench = NFVBench(config, openstack_spec, config_plugin, factory)
if opts.server: