Commit d9e5655a by Guba Sándor

improve logging

parent 942d2c17
...@@ -6,7 +6,7 @@ from os import getenv ...@@ -6,7 +6,7 @@ from os import getenv
from socket import gethostname from socket import gethostname
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger()
HOSTNAME = gethostname() HOSTNAME = gethostname()
AMQP_URI = getenv('AMQP_URI') AMQP_URI = getenv('AMQP_URI')
......
...@@ -3,9 +3,14 @@ from twisted.internet import reactor, inotify ...@@ -3,9 +3,14 @@ from twisted.internet import reactor, inotify
from twisted.python import filepath from twisted.python import filepath
from agentcelery import celery, HOSTNAME from agentcelery import celery, HOSTNAME
from protocol import inotify_handler from protocol import inotify_handler
from os import getenv, listdir, path from os import getenv, listdir, path, environ
import logging import logging
logging.basicConfig()
logger = logging.getLogger()
level = environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
SOCKET_DIR = getenv('SOCKET_DIR', '/var/lib/libvirt/serial') SOCKET_DIR = getenv('SOCKET_DIR', '/var/lib/libvirt/serial')
...@@ -33,7 +38,7 @@ def main(): ...@@ -33,7 +38,7 @@ def main():
w = Worker(app=celery, concurrency=1, w = Worker(app=celery, concurrency=1,
pool_cls='threads', pool_cls='threads',
hostname=HOSTNAME + '.agentdriver', hostname=HOSTNAME + '.agentdriver',
loglevel=logging.DEBUG) loglevel=level)
reactor.callInThread(w.run) reactor.callInThread(w.run)
notifier = inotify.INotify(reactor) notifier = inotify.INotify(reactor)
notifier.startReading() notifier.startReading()
......
...@@ -13,7 +13,7 @@ from utils import SerialLineReceiverBase ...@@ -13,7 +13,7 @@ from utils import SerialLineReceiverBase
from agentcelery import agent_started, agent_stopped, renew from agentcelery import agent_started, agent_stopped, renew
logger = logging.getLogger(__name__) logger = logging.getLogger()
reactor.connections = {} reactor.connections = {}
...@@ -47,6 +47,7 @@ def inotify_handler(self, file, mask): ...@@ -47,6 +47,7 @@ def inotify_handler(self, file, mask):
if vm in reactor.connections: if vm in reactor.connections:
return return
serial = SerialLineReceiverFactory(vm) serial = SerialLineReceiverFactory(vm)
logger.info("connecting to %s (%s)", vm, file.path)
reactor.connectUNIX(file.path, serial) reactor.connectUNIX(file.path, serial)
......
...@@ -2,8 +2,7 @@ from twisted.protocols.basic import LineReceiver ...@@ -2,8 +2,7 @@ from twisted.protocols.basic import LineReceiver
import json import json
import logging import logging
root_logger = logging.getLogger() logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
class SerialLineReceiverBase(LineReceiver, object): class SerialLineReceiverBase(LineReceiver, object):
...@@ -31,14 +30,14 @@ class SerialLineReceiverBase(LineReceiver, object): ...@@ -31,14 +30,14 @@ class SerialLineReceiverBase(LineReceiver, object):
args = {} args = {}
command = data.get('command', None) command = data.get('command', None)
response = data.get('response', 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: except (ValueError, KeyError) as e:
logging.error('[serial] invalid json: %s (%s)' % (data, e)) logger.error('[serial] invalid json: %s (%s)' % (data, e))
return return
if command is not None and isinstance(command, unicode): 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) self.handle_command(command, args)
elif response is not None and isinstance(response, unicode): 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) 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