Commit d9e5655a by Guba Sándor

improve logging

parent 942d2c17
......@@ -6,7 +6,7 @@ from os import getenv
from socket import gethostname
import logging
logger = logging.getLogger(__name__)
logger = logging.getLogger()
HOSTNAME = gethostname()
AMQP_URI = getenv('AMQP_URI')
......
......@@ -3,9 +3,14 @@ from twisted.internet import reactor, inotify
from twisted.python import filepath
from agentcelery import celery, HOSTNAME
from protocol import inotify_handler
from os import getenv, listdir, path
from os import getenv, listdir, path, environ
import logging
logging.basicConfig()
logger = logging.getLogger()
level = environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
SOCKET_DIR = getenv('SOCKET_DIR', '/var/lib/libvirt/serial')
......@@ -33,7 +38,7 @@ def main():
w = Worker(app=celery, concurrency=1,
pool_cls='threads',
hostname=HOSTNAME + '.agentdriver',
loglevel=logging.DEBUG)
loglevel=level)
reactor.callInThread(w.run)
notifier = inotify.INotify(reactor)
notifier.startReading()
......
......@@ -13,7 +13,7 @@ from utils import SerialLineReceiverBase
from agentcelery import agent_started, agent_stopped, renew
logger = logging.getLogger(__name__)
logger = logging.getLogger()
reactor.connections = {}
......@@ -47,6 +47,7 @@ def inotify_handler(self, file, mask):
if vm in reactor.connections:
return
serial = SerialLineReceiverFactory(vm)
logger.info("connecting to %s (%s)", vm, file.path)
reactor.connectUNIX(file.path, serial)
......
......@@ -2,8 +2,7 @@ from twisted.protocols.basic import LineReceiver
import json
import logging
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
logger = logging.getLogger()
class SerialLineReceiverBase(LineReceiver, object):
......@@ -31,14 +30,14 @@ class SerialLineReceiverBase(LineReceiver, object):
args = {}
command = data.get('command', None)
response = data.get('response', None)
logging.debug('[serial] valid json: %s' % (data, ))
logger.debug('[serial] valid json: %s' % (data, ))
except (ValueError, KeyError) as e:
logging.error('[serial] invalid json: %s (%s)' % (data, e))
logger.error('[serial] invalid json: %s (%s)' % (data, e))
return
if command is not None and isinstance(command, unicode):
logging.debug('received command: %s (%s)' % (command, args))
logger.debug('received command: %s (%s)' % (command, args))
self.handle_command(command, args)
elif response is not None and isinstance(response, unicode):
logging.debug('received reply: %s (%s)' % (response, args))
logger.debug('received reply: %s (%s)' % (response, args))
self.handle_response(response, args)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment