Yichen Wang 315f94bdc9 Rest API Enhancements
Rest API Enhancements:
1. Add the public folder for holding static files (HTML+JS);
2. Add support for dumping logs with offset;
3. Add support for dumping the final report;

Others:
1. Fix the issue for not dumping complete console logs;
2. Remove .html from the gitignore list

Change-Id: I8a4c0b35c35a818b67d445bcb913d1abfc683301
2015-09-03 14:53:58 -07:00

82 lines
2.5 KiB
Python

# Copyright 2015 Cisco Systems, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
from oslo_config import cfg
from oslo_log import handlers
from oslo_log import log as oslogging
DEBUG_OPTS = [
cfg.BoolOpt("kb-debug",
default=False,
help="Print debug output for KloudBuster only")
]
CONF = cfg.CONF
CONF.register_cli_opts(DEBUG_OPTS)
oslogging.register_options(CONF)
logging.KBDEBUG = logging.DEBUG + 5
logging.addLevelName(logging.KBDEBUG, "KBDEBUG")
CRITICAL = logging.CRITICAL
DEBUG = logging.DEBUG
ERROR = logging.ERROR
FATAL = logging.FATAL
INFO = logging.INFO
NOTSET = logging.NOTSET
KBDEBUG = logging.KBDEBUG
WARN = logging.WARN
WARNING = logging.WARNING
def setup(product_name, logfile=None):
dbg_color = handlers.ColorHandler.LEVEL_COLORS[logging.DEBUG]
handlers.ColorHandler.LEVEL_COLORS[logging.KBDEBUG] = dbg_color
oslogging.setup(CONF, product_name)
# Adding the FileHandler to all known loggers inside KloudBuster
if logfile:
if os.path.exists(logfile):
os.remove(logfile)
CONF.log_file = logfile
hdlr = logging.FileHandler(logfile)
for name in oslogging._loggers:
if name:
oslogging.getLogger(name).logger.addHandler(hdlr)
if CONF.kb_debug:
oslogging.getLogger(
project=product_name).logger.setLevel(logging.KBDEBUG)
def getLogger(name="unknown", version="unknown"):
if name not in oslogging._loggers:
oslogging._loggers[name] = KloudBusterContextAdapter(
logging.getLogger(name), {"project": "kloudbuster",
"version": version})
return oslogging._loggers[name]
def delete_logfile(product_name):
if CONF.log_file and os.path.exists(CONF.log_file):
os.remove(CONF.log_file)
CONF.log_file = None
class KloudBusterContextAdapter(oslogging.KeywordArgumentAdapter):
def kbdebug(self, msg, *args, **kwargs):
self.log(logging.KBDEBUG, msg, *args, **kwargs)