1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from yardstick.dispatcher.base import Base as DispatchBase
16 class FileDispatcher(DispatchBase):
17 """Dispatcher class for recording data to a file.
20 __dispatcher_type__ = "File"
22 # TODO: make parameters below configurable, currently just hard coded
23 # Path of the file to record the data
24 file_path = "/tmp/yardstick.out"
25 # The max size of the file
27 # The max number of the files to keep
30 def __init__(self, conf):
31 super(FileDispatcher, self).__init__(conf)
34 # if the directory and path are configured, then log to the file
36 dispatcher_logger = logging.Logger('dispatcher.file')
37 dispatcher_logger.setLevel(logging.INFO)
38 # create rotating file handler which logs result
39 rfh = logging.handlers.RotatingFileHandler(
40 self.conf.get('file_path', self.file_path),
41 maxBytes=self.max_bytes,
42 backupCount=self.backup_count,
45 rfh.setLevel(logging.INFO)
46 # Only wanted the data to be saved in the file, not the
47 # project root logger.
48 dispatcher_logger.propagate = False
49 dispatcher_logger.addHandler(rfh)
50 self.log = dispatcher_logger
52 def record_result_data(self, data):
54 self.log.info(json.dumps(data))