1 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
17 _product_name = 'nfvbench'
19 def setup(mute_stdout=False):
20 # logging.basicConfig()
22 handler = logging.NullHandler()
24 formatter_str = '%(asctime)s %(levelname)s %(message)s'
25 handler = logging.StreamHandler()
26 handler.setFormatter(logging.Formatter(formatter_str))
28 # Add handler to logger
29 logger = logging.getLogger(_product_name)
30 logger.addHandler(handler)
31 # disable unnecessary information capture
32 logging.logThreads = 0
33 logging.logProcesses = 0
34 logging._srcfile = None
36 def add_file_logger(logfile):
38 file_formatter_str = '%(asctime)s %(levelname)s %(message)s'
39 file_handler = logging.FileHandler(logfile, mode='w')
40 file_handler.setFormatter(logging.Formatter(file_formatter_str))
41 logger = logging.getLogger(_product_name)
42 logger.addHandler(file_handler)
44 def set_level(debug=False):
45 log_level = logging.DEBUG if debug else logging.INFO
46 logger = logging.getLogger(_product_name)
47 logger.setLevel(log_level)
50 logger = logging.getLogger(_product_name)