1 # Copyright 2013 IBM Corp
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # yardstick comment: this is a modified copy of
17 # ceilometer/ceilometer/dispatcher/file.py
22 from oslo_config import cfg
24 from yardstick.dispatcher.base import Base as DispatchBase
28 cfg.StrOpt('file_path',
29 default='/tmp/yardstick.out',
30 help='Name and the location of the file to record '
32 cfg.IntOpt('max_bytes',
34 help='The max size of the file.'),
35 cfg.IntOpt('backup_count',
37 help='The max number of the files to keep.'),
39 CONF.register_opts(OPTS, group="dispatcher_file")
42 class FileDispatcher(DispatchBase):
43 """Dispatcher class for recording data to a file.
46 __dispatcher_type__ = "File"
48 def __init__(self, conf):
49 super(FileDispatcher, self).__init__(conf)
52 # if the directory and path are configured, then log to the file
53 if CONF.dispatcher_file.file_path:
54 dispatcher_logger = logging.Logger('dispatcher.file')
55 dispatcher_logger.setLevel(logging.INFO)
56 # create rotating file handler which logs result
57 rfh = logging.handlers.RotatingFileHandler(
58 self.conf.get('file_path', CONF.dispatcher_file.file_path),
59 maxBytes=CONF.dispatcher_file.max_bytes,
60 backupCount=CONF.dispatcher_file.backup_count,
63 rfh.setLevel(logging.INFO)
64 # Only wanted the data to be saved in the file, not the
65 # project root logger.
66 dispatcher_logger.propagate = False
67 dispatcher_logger.addHandler(rfh)
68 self.log = dispatcher_logger
70 def record_result_data(self, data):
72 self.log.info(json.dumps(data))
74 def flush_result_data(self):