Adds serial port logging support

Adds serial port logging to improve troubleshooting.
Serial port settings are confugurable with the option:
"logging_serial_port_settings"
This commit is contained in:
Alessandro Pilotti 2014-02-09 20:41:39 +02:00
parent 23ca4b577a
commit dfbf133aee
2 changed files with 59 additions and 2 deletions

View File

@ -18,10 +18,9 @@ import sys
from cloudbaseinit import init from cloudbaseinit import init
from cloudbaseinit.openstack.common import cfg from cloudbaseinit.openstack.common import cfg
from cloudbaseinit.openstack.common import log as logging from cloudbaseinit.utils import log as logging
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def main(): def main():

View File

@ -0,0 +1,58 @@
# Copyright 2014 Cloudbase Solutions Srl
#
# 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 serial
from cloudbaseinit.openstack.common import cfg
from cloudbaseinit.openstack.common import log as openstack_logging
opts = [
cfg.StrOpt('logging_serial_port_settings', default=None,
help='Serial port logging settings. Format: '
'"port,baudrate,parity,bytesize", e.g.: "COM1,115200,N,8". '
'Set to None (default) to disable.'),
]
CONF = cfg.CONF
CONF.register_opts(opts)
class SerialPortHandler(logging.StreamHandler):
def __init__(self):
if CONF.logging_serial_port_settings:
settings = CONF.logging_serial_port_settings.split(',')
self._port = serial.Serial(port=settings[0],
baudrate=int(settings[1]),
parity=settings[2],
bytesize=int(settings[3]))
if not self._port.isOpen():
self._port.open()
super(SerialPortHandler, self).__init__(self._port)
def close(self):
if self._port and self._port.isOpen():
self._port.close()
def setup(product_name):
openstack_logging.setup(product_name)
if CONF.logging_serial_port_settings:
log_root = openstack_logging.getLogger(product_name).logger
serialportlog = SerialPortHandler()
log_root.addHandler(serialportlog)