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
20 import logging.handlers
23 from oslo_config import cfg
25 from yardstick.dispatcher.base import Base as DispatchBase
29 cfg.StrOpt('file_path',
30 default='/tmp/yardstick.out',
31 help='Name and the location of the file to record '
33 cfg.IntOpt('max_bytes',
35 help='The max size of the file.'),
36 cfg.IntOpt('backup_count',
38 help='The max number of the files to keep.'),
40 CONF.register_opts(OPTS, group="dispatcher_file")
43 class FileDispatcher(DispatchBase):
44 """Dispatcher class for recording data to a file.
47 __dispatcher_type__ = "File"
49 def __init__(self, conf):
50 super(FileDispatcher, self).__init__(conf)
53 # if the directory and path are configured, then log to the file
54 if CONF.dispatcher_file.file_path:
55 dispatcher_logger = logging.Logger('dispatcher.file')
56 dispatcher_logger.setLevel(logging.INFO)
57 # create rotating file handler which logs result
58 rfh = logging.handlers.RotatingFileHandler(
59 self.conf.get('file_path', CONF.dispatcher_file.file_path),
60 maxBytes=CONF.dispatcher_file.max_bytes,
61 backupCount=CONF.dispatcher_file.backup_count,
64 rfh.setLevel(logging.INFO)
65 # Only wanted the data to be saved in the file, not the
66 # project root logger.
67 dispatcher_logger.propagate = False
68 dispatcher_logger.addHandler(rfh)
69 self.log = dispatcher_logger
71 def record_result_data(self, data):
73 self.log.info(json.dumps(data))
75 def flush_result_data(self):