[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 difflib
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from supermutes.dot import dotify
|
from supermutes.dot import dotify
|
||||||
|
|
||||||
@ -24,6 +26,13 @@ from ..utils.release import release_prefix
|
|||||||
from ..utils import git
|
from ..utils import git
|
||||||
from ..utils import lint
|
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__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Armada(object):
|
class Armada(object):
|
||||||
|
@ -12,73 +12,29 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import os
|
from oslo_config import cfg
|
||||||
import logging
|
from oslo_log import log as 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'
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
DOMAIN = "armada"
|
||||||
|
|
||||||
def set_console_formatter(**formatter_kwargs):
|
def set_console_formatter(**formatter_kwargs):
|
||||||
formatter_kwargs.setdefault(
|
formatter_kwargs.setdefault(
|
||||||
'fmt', '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
'fmt', '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
||||||
formatter_kwargs.setdefault('datefmt', '%m-%d %H:%M')
|
formatter_kwargs.setdefault('datefmt', '%m-%d %H:%M')
|
||||||
|
|
||||||
root_logger = logging.getLogger('')
|
# Specify default log levels
|
||||||
cliff_log = logging.getLogger('cliff')
|
custom_log_level_defaults = [
|
||||||
stevedore_log = logging.getLogger('stevedore')
|
'root=INFO',
|
||||||
iso8601_log = logging.getLogger("iso8601")
|
'cliff=INFO',
|
||||||
|
'stevedore=INFO',
|
||||||
|
'iso8601=INFO'
|
||||||
|
]
|
||||||
|
|
||||||
log_dir = os.path.expanduser('~/.armada')
|
logging.set_defaults(
|
||||||
if not os.path.exists(log_dir):
|
default_log_levels=logging.get_default_log_levels() +
|
||||||
os.makedirs(log_dir)
|
custom_log_level_defaults)
|
||||||
|
|
||||||
file_logger = logging.FileHandler(filename=str(log_dir + '/armada.log'))
|
# Setup logging configuration
|
||||||
root_logger.addHandler(file_logger)
|
logging.register_options(CONF)
|
||||||
|
logging.setup(CONF, DOMAIN)
|
||||||
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)
|
|
||||||
|
@ -36,8 +36,6 @@ class ArmadaApp(app.App):
|
|||||||
def configure_logging(self):
|
def configure_logging(self):
|
||||||
super(ArmadaApp, self).configure_logging()
|
super(ArmadaApp, self).configure_logging()
|
||||||
log.set_console_formatter()
|
log.set_console_formatter()
|
||||||
log.silence_iso8601()
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
if argv is None:
|
if argv is None:
|
||||||
|
@ -2,6 +2,7 @@ grpc==0.3.post19
|
|||||||
grpcio==1.1.3
|
grpcio==1.1.3
|
||||||
grpcio-tools==1.1.3
|
grpcio-tools==1.1.3
|
||||||
kubernetes==1.0.0
|
kubernetes==1.0.0
|
||||||
|
oslo.log==3.28.0
|
||||||
protobuf==3.2.0
|
protobuf==3.2.0
|
||||||
PyYAML==3.12
|
PyYAML==3.12
|
||||||
requests==2.17.3
|
requests==2.17.3
|
||||||
|
@ -14,15 +14,22 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import falcon
|
import falcon
|
||||||
import json
|
import json
|
||||||
from falcon import HTTP_200
|
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.tiller import Tiller as tillerHandler
|
||||||
from armada.handlers.armada import Armada as armadaHandler
|
from armada.handlers.armada import Armada as armadaHandler
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
CONF = cfg.CONF
|
||||||
|
DOMAIN = "armada"
|
||||||
|
|
||||||
|
logging.register_options(CONF)
|
||||||
|
logging.setup(CONF, DOMAIN)
|
||||||
|
|
||||||
class Tiller(object):
|
class Tiller(object):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user