X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fdispatcher%2Ffile.py;h=24fc22dd48b7370f7a24a6d2291d1d5f8ad3805d;hb=8291c3d11227de42599be920605f3f884dfa755b;hp=c2cc265ba8a774b0c012a97533efe060dafa26ce;hpb=74479a22c461cc2c08f9525879481c0a86d3af84;p=yardstick.git diff --git a/yardstick/dispatcher/file.py b/yardstick/dispatcher/file.py index c2cc265ba..24fc22dd4 100644 --- a/yardstick/dispatcher/file.py +++ b/yardstick/dispatcher/file.py @@ -16,28 +16,11 @@ # yardstick comment: this is a modified copy of # ceilometer/ceilometer/dispatcher/file.py -import logging -import logging.handlers -import json - -from oslo_config import cfg +from __future__ import absolute_import from yardstick.dispatcher.base import Base as DispatchBase - -CONF = cfg.CONF -OPTS = [ - cfg.StrOpt('file_path', - default='/tmp/yardstick.out', - help='Name and the location of the file to record ' - 'data.'), - cfg.IntOpt('max_bytes', - default=0, - help='The max size of the file.'), - cfg.IntOpt('backup_count', - default=0, - help='The max number of the files to keep.'), -] -CONF.register_opts(OPTS, group="dispatcher_file") +from yardstick.common import constants as consts +from yardstick.common import utils class FileDispatcher(DispatchBase): @@ -48,29 +31,8 @@ class FileDispatcher(DispatchBase): def __init__(self, conf): super(FileDispatcher, self).__init__(conf) - self.log = None - - # if the directory and path are configured, then log to the file - if CONF.dispatcher_file.file_path: - dispatcher_logger = logging.Logger('dispatcher.file') - dispatcher_logger.setLevel(logging.INFO) - # create rotating file handler which logs result - rfh = logging.handlers.RotatingFileHandler( - self.conf.get('file_path', CONF.dispatcher_file.file_path), - maxBytes=CONF.dispatcher_file.max_bytes, - backupCount=CONF.dispatcher_file.backup_count, - encoding='utf8') - - rfh.setLevel(logging.INFO) - # Only wanted the data to be saved in the file, not the - # project root logger. - dispatcher_logger.propagate = False - dispatcher_logger.addHandler(rfh) - self.log = dispatcher_logger - - def record_result_data(self, data): - if self.log: - self.log.info(json.dumps(data)) + self.target = conf['dispatcher_file'].get('file_path', + consts.DEFAULT_OUTPUT_FILE) - def flush_result_data(self): - pass + def flush_result_data(self, data): + utils.write_json_to_file(self.target, data)