[WIP][Feat] Add support for Oslo logging capabilities
- Add 'oslo.log' package to requirements.txt - Replace Python logging library with Oslo logging library in server.py and log.py - Update iso8601 silencincing to default option
This commit is contained in:
parent
05ea659191
commit
368c89664b
|
@ -14,7 +14,9 @@
|
|||
|
||||
import difflib
|
||||
import yaml
|
||||
import logging
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from supermutes.dot import dotify
|
||||
|
||||
|
@ -24,6 +26,13 @@ from ..utils.release import release_prefix
|
|||
from ..utils import git
|
||||
from ..utils import lint
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
DOMAIN = "armada"
|
||||
|
||||
logging.register_options(CONF)
|
||||
logging.setup(CONF, DOMAIN)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
class Armada(object):
|
||||
|
|
|
@ -12,73 +12,29 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import logging
|
||||
import string
|
||||
import sys
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
import functools
|
||||
|
||||
@functools.wraps(logging.Formatter.format)
|
||||
def new_format(self, record, string=string,
|
||||
old_format=logging.Formatter.format):
|
||||
if string.find is None:
|
||||
string.find = str.find
|
||||
return old_format(self, record)
|
||||
logging.Formatter.format = new_format
|
||||
|
||||
|
||||
class ColorFormatter(logging.Formatter):
|
||||
LEVEL_COLORS = {
|
||||
logging.DEBUG: '\033[00;32m', # GREEN
|
||||
logging.INFO: '\033[00;36m', # CYAN
|
||||
logging.WARN: '\033[01;33m', # BOLD YELLOW
|
||||
logging.ERROR: '\033[01;31m', # BOLD RED
|
||||
logging.CRITICAL: '\033[01;31m', # BOLD RED
|
||||
}
|
||||
|
||||
def format(self, record, Formatter=logging.Formatter):
|
||||
# Hack to get last log line instead of exception on 2.6
|
||||
res = Formatter.format(self, record) # old-style class on 2.6
|
||||
return self.LEVEL_COLORS[record.levelno] + res + '\033[m'
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
CONF = cfg.CONF
|
||||
DOMAIN = "armada"
|
||||
|
||||
def set_console_formatter(**formatter_kwargs):
|
||||
formatter_kwargs.setdefault(
|
||||
'fmt', '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
||||
formatter_kwargs.setdefault('datefmt', '%m-%d %H:%M')
|
||||
|
||||
root_logger = logging.getLogger('')
|
||||
cliff_log = logging.getLogger('cliff')
|
||||
stevedore_log = logging.getLogger('stevedore')
|
||||
iso8601_log = logging.getLogger("iso8601")
|
||||
# Specify default log levels
|
||||
custom_log_level_defaults = [
|
||||
'root=INFO',
|
||||
'cliff=INFO',
|
||||
'stevedore=INFO',
|
||||
'iso8601=INFO'
|
||||
]
|
||||
|
||||
log_dir = os.path.expanduser('~/.armada')
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir)
|
||||
logging.set_defaults(
|
||||
default_log_levels=logging.get_default_log_levels() +
|
||||
custom_log_level_defaults)
|
||||
|
||||
file_logger = logging.FileHandler(filename=str(log_dir + '/armada.log'))
|
||||
root_logger.addHandler(file_logger)
|
||||
|
||||
cliff_log.setLevel(logging.INFO)
|
||||
stevedore_log.setLevel(logging.INFO)
|
||||
iso8601_log.setLevel(logging.INFO)
|
||||
|
||||
for handler in root_logger.handlers:
|
||||
if handler.__class__ is logging.StreamHandler: # Skip subclasses
|
||||
console_handler = handler
|
||||
# Skip if not a tty (default ssh, redirect, ...)
|
||||
isatty = getattr(handler.stream, 'isatty', None)
|
||||
if isatty is None or not isatty():
|
||||
continue
|
||||
break
|
||||
else:
|
||||
return # Didn't find any suitable StreamHandlers there
|
||||
formatter = ColorFormatter(**formatter_kwargs)
|
||||
console_handler.setFormatter(formatter)
|
||||
|
||||
|
||||
def silence_iso8601():
|
||||
iso8601_logger = logging.getLogger('iso8601')
|
||||
iso8601_logger.setLevel(logging.INFO)
|
||||
# Setup logging configuration
|
||||
logging.register_options(CONF)
|
||||
logging.setup(CONF, DOMAIN)
|
||||
|
|
|
@ -36,8 +36,6 @@ class ArmadaApp(app.App):
|
|||
def configure_logging(self):
|
||||
super(ArmadaApp, self).configure_logging()
|
||||
log.set_console_formatter()
|
||||
log.silence_iso8601()
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
if argv is None:
|
||||
|
|
|
@ -2,6 +2,7 @@ grpc==0.3.post19
|
|||
grpcio==1.1.3
|
||||
grpcio-tools==1.1.3
|
||||
kubernetes==1.0.0
|
||||
oslo.log==3.28.0
|
||||
protobuf==3.2.0
|
||||
PyYAML==3.12
|
||||
requests==2.17.3
|
||||
|
|
|
@ -14,15 +14,22 @@
|
|||
#
|
||||
|
||||
|
||||
import logging
|
||||
import falcon
|
||||
import json
|
||||
from falcon import HTTP_200
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from armada.handlers.tiller import Tiller as tillerHandler
|
||||
from armada.handlers.armada import Armada as armadaHandler
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
DOMAIN = "armada"
|
||||
|
||||
logging.register_options(CONF)
|
||||
logging.setup(CONF, DOMAIN)
|
||||
|
||||
class Tiller(object):
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue